tparsopt.nim 857 B

123456789101112131415161718192021222324252627282930313233343536
  1. discard """
  2. disabled: true
  3. """
  4. # this file has a type in the name, and it does not really test
  5. # parseopt module, because tester has no support to set arguments. Test the
  6. # new parseopt module. Therefore it is disabled.
  7. import
  8. parseopt
  9. import std/[assertions, syncio]
  10. proc writeHelp() =
  11. writeLine(stdout, "Usage: tparsopt [options] filename [options]")
  12. proc writeVersion() =
  13. writeLine(stdout, "Version: 1.0.0")
  14. var
  15. filename = ""
  16. for kind, key, val in getopt():
  17. case kind
  18. of cmdArgument:
  19. filename = key
  20. of cmdLongOption, cmdShortOption:
  21. case key
  22. of "help", "h": writeHelp()
  23. of "version", "v": writeVersion()
  24. else:
  25. writeLine(stdout, "Unknown command line option: ", key, ": ", val)
  26. of cmdEnd: doAssert(false) # cannot happen
  27. if filename == "":
  28. # no filename has been given, so we show the help:
  29. writeHelp()