Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow repeating an option to override its value #22

Merged
merged 1 commit into from
Sep 30, 2020
Merged

Conversation

stefantalpalaru
Copy link
Contributor

./tests/cli_example --foo:1 --bar:a --withBaz --foo:2 --bar:boo --bar:hoo --withBaz:false
foo = 2
bar = hoo
baz = false

./tests/cli_example --foo:1 --bar:a --withBaz --foo:2 --bar:boo --bar:hoo --withBaz:false
foo = 2
bar = hoo
baz = false
@cheatfate
Copy link

Because this PR do not have any tests, it could break handling sequence arguments, for example when one of the arguments are declared like this https://github.com/status-im/nim-beacon-chain/blob/master/beacon_chain/conf.nim#L92-L95 you can supply multiple items only via:

./beacon_node --bootstrap-node=<node1> --botstrap-node=<node2> --botstrap-node=<node3>

And this behavior should be preserved, or new one should be introduced.

@cheatfate cheatfate requested a review from zah August 31, 2020 12:11
@stefantalpalaru
Copy link
Contributor Author

it could break handling sequence arguments

As I already explained in Discord, there is no such breakage:

diff --git a/tests/cli_example.nim b/tests/cli_example.nim
index 2271320..e5773e1 100644
--- a/tests/cli_example.nim
+++ b/tests/cli_example.nim
@@ -1,9 +1,10 @@
 import
   ../confutils
 
-cli do (foo: int, bar: string, withBaz: bool, args {.argument.}: seq[string]):
+cli do (foo: int, bar: string, withBaz: bool, bootstrapNodes: seq[string], args {.argument.}: seq[string]):
   echo "foo = ", foo
   echo "bar = ", bar
   echo "baz = ", withBaz
+  echo "bootstrapNodes = ", bootstrapNodes
   for arg in args: echo "arg ", arg
./tests/cli_example --foo:1 --bar:a --withBaz --foo:2 --bar:boo --bar:hoo --withBaz:false --bootstrapNodes:node1 --bootstrapNodes:node2 test1 test2
foo = 2
bar = hoo
baz = false
bootstrapNodes = @["node1", "node2"]
arg test1
arg test2

Copy link

@mratsim mratsim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM but IIRC @zah had reserves on the behavior until you cited an actual spec on CLI parsing, can you link to the spec so that we can put that in the documentation at an opportune time.

@stefantalpalaru
Copy link
Contributor Author

"If an option that has option-arguments is repeated, the option and option-argument combinations should be interpreted in the order specified on the command line." - https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap12.html

getopt() examples showing how it's common practice to just override old values when processing the same option multiple times in a while loop: https://linux.die.net/man/3/getopt

@mratsim mratsim merged commit 2e8040e into master Sep 30, 2020
mratsim added a commit to status-im/nimbus-eth2 that referenced this pull request Sep 30, 2020
mratsim added a commit to status-im/nimbus-eth2 that referenced this pull request Sep 30, 2020
@jangko jangko deleted the option-override branch November 3, 2020 03:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants