Skip to content

Commit

Permalink
lib/parseopt: require explicit parameters list (#1008)
Browse files Browse the repository at this point in the history
Now that  `getopt`  no longer automatically pulls in command line
arguments, it makes no sense to keep the default "empty" parameter.

Included is an update to documentation about the current behavior and a
fix to nimgrep to be able to read command line parameters.

Fixes 1a72373
  • Loading branch information
alaviss authored Nov 4, 2023
1 parent 75ffca0 commit a44b614
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 8 deletions.
8 changes: 3 additions & 5 deletions lib/pure/parseopt.nim
Original file line number Diff line number Diff line change
Expand Up @@ -405,14 +405,12 @@ iterator getopt*(p: var OptParser): tuple[kind: CmdLineKind, key,
if p.kind == cmdEnd: break
yield (p.kind, p.key, p.val)

iterator getopt*(cmdline: seq[string] = @[],
shortNoVal: set[char] = {}, longNoVal: seq[string] = @[]):
iterator getopt*(cmdline: seq[string],
shortNoVal: set[char] = {}, longNoVal: seq[string] = @[]):
tuple[kind: CmdLineKind, key, val: string] =
## Convenience iterator for iterating over command line arguments.
##
## This creates a new `OptParser<#OptParser>`_. If no command line
## arguments are provided, the real command line as provided by the
## `os` module is retrieved instead.
## This creates a new `OptParser<#OptParser>`_.
##
## `shortNoVal` and `longNoVal` are used to specify which options
## do not take values. See the `documentation about these
Expand Down
2 changes: 1 addition & 1 deletion tests/ccgbugs/tmangle_field.nim
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ import parseopt
type foo* {.importc: "foo", nodecl.} = object
key* {.importc: "key".}: cint

for kind, key, value in parseopt.getopt():
for kind, key, value in parseopt.getopt(@[]):
discard
2 changes: 1 addition & 1 deletion tests/misc/tparseopt.nim
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ else:

block: # general test
echo "t 0-0"
for kind, key, val in parseopt.getopt():
for kind, key, val in parseopt.getopt(@[]):
echo "kind: ", kind, "\tkey:val -- ", key, ":", val

# pass custom cmdline arguments
Expand Down
2 changes: 1 addition & 1 deletion tools/nimgrep.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1158,7 +1158,7 @@ when defined(posix):
useWriteStyled = terminal.isatty(stdout)
# that should be before option processing to allow override of useWriteStyled

for kind, key, val in getopt():
for kind, key, val in commandLineParams().getopt():
case kind
of cmdArgument:
if options.contains(optStdin):
Expand Down

0 comments on commit a44b614

Please sign in to comment.