diff options
author | Andreas Rumpf <rumpf_a@web.de> | 2017-07-13 04:48:22 +0200 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2017-07-13 04:48:22 +0200 |
commit | 2b862b74e0b0b7b4a18f4262356289fb921eaf0c (patch) | |
tree | 8f41b7355f6d791d6485e8225d6a5cb2f80ca7d6 /lib/pure/parseopt2.nim | |
parent | a5695c13afabac6e67ff677d564b6d1a6aeb1af4 (diff) | |
parent | 0c271f54208c7ba0bac6ad2da87f60e7c6d8e37c (diff) | |
download | Nim-2b862b74e0b0b7b4a18f4262356289fb921eaf0c.tar.gz |
Merge branch 'devel' into araq
Diffstat (limited to 'lib/pure/parseopt2.nim')
-rw-r--r-- | lib/pure/parseopt2.nim | 45 |
1 files changed, 30 insertions, 15 deletions
diff --git a/lib/pure/parseopt2.nim b/lib/pure/parseopt2.nim index 7fd9c60fe..2e8dbe140 100644 --- a/lib/pure/parseopt2.nim +++ b/lib/pure/parseopt2.nim @@ -123,26 +123,41 @@ type {.deprecated: [TGetoptResult: GetoptResult].} +iterator getopt*(p: var OptParser): GetoptResult = + ## This is an convenience iterator for iterating over the given OptParser object. + ## Example: + ## + ## .. code-block:: nim + ## var p = initOptParser("--left --debug:3 -l=4 -r:2") + ## for kind, key, val in p.getopt(): + ## case kind + ## of cmdArgument: + ## filename = key + ## of cmdLongOption, cmdShortOption: + ## case key + ## of "help", "h": writeHelp() + ## of "version", "v": writeVersion() + ## of cmdEnd: assert(false) # cannot happen + ## if filename == "": + ## # no filename has been given, so we show the help: + ## writeHelp() + p.pos = 0 + while true: + next(p) + if p.kind == cmdEnd: break + yield (p.kind, p.key, p.val) + when declared(paramCount): iterator getopt*(): GetoptResult = - ## This is an convenience iterator for iterating over the command line. - ## This uses the OptParser object. Example: + ## This is an convenience iterator for iterating over the command line arguments. + ## This create a new OptParser object. + ## See above for a more detailed example ## ## .. code-block:: nim - ## var - ## filename = "" ## for kind, key, val in getopt(): - ## case kind - ## of cmdArgument: - ## filename = key - ## of cmdLongOption, cmdShortOption: - ## case key - ## of "help", "h": writeHelp() - ## of "version", "v": writeVersion() - ## of cmdEnd: assert(false) # cannot happen - ## if filename == "": - ## # no filename has been given, so we show the help: - ## writeHelp() + ## # this will iterate over all arguments passed to the cmdline. + ## continue + ## var p = initOptParser() while true: next(p) |