tparsopt.nim 824 B

12345678910111213141516171819202122232425262728293031323334
  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. proc writeHelp() =
  10. writeLine(stdout, "Usage: tparsopt [options] filename [options]")
  11. proc writeVersion() =
  12. writeLine(stdout, "Version: 1.0.0")
  13. var
  14. filename = ""
  15. for kind, key, val in getopt():
  16. case kind
  17. of cmdArgument:
  18. filename = key
  19. of cmdLongOption, cmdShortOption:
  20. case key
  21. of "help", "h": writeHelp()
  22. of "version", "v": writeVersion()
  23. else:
  24. writeLine(stdout, "Unknown command line option: ", key, ": ", val)
  25. of cmdEnd: doAssert(false) # cannot happen
  26. if filename == "":
  27. # no filename has been given, so we show the help:
  28. writeHelp()