tparams.nim 764 B

1234567891011121314151617181920212223
  1. discard """
  2. joinable: false
  3. """
  4. # not joinable because it executes itself with parameters
  5. import os
  6. import osproc
  7. import parseopt
  8. import sequtils
  9. let argv = commandLineParams()
  10. if argv == @[]:
  11. # this won't work with spaces
  12. doAssert execShellCmd(getAppFilename() & " \"foo bar\" --aa:bar=a --a=c:d --ab -c --a[baz]:doo") == 0
  13. else:
  14. let f = toSeq(getopt())
  15. doAssert f[0].kind == cmdArgument and f[0].key == "foo bar" and f[0].val == ""
  16. doAssert f[1].kind == cmdLongOption and f[1].key == "aa" and f[1].val == "bar=a"
  17. doAssert f[2].kind == cmdLongOption and f[2].key == "a" and f[2].val == "c:d"
  18. doAssert f[3].kind == cmdLongOption and f[3].key == "ab" and f[3].val == ""
  19. doAssert f[4].kind == cmdShortOption and f[4].key == "c" and f[4].val == ""