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

Argument pragma seems to drop information in help message of following options #15

Open
kdeme opened this issue Jun 3, 2020 · 1 comment

Comments

@kdeme
Copy link
Contributor

kdeme commented Jun 3, 2020

Noticed here that if the argument is put before the distance option. The help message is incomplete. Switching order seems to work as workaround.

In both cases, the cli works the same though, seems to be just the help message, e.g.:

Available sub-commands:

dcli ping <node>
<node>                 ENR URI of the node to a send ping message
dcli findnode

Instead of:

Available sub-commands:

dcli ping <node>
<node>                 ENR URI of the node to a send ping message
dcli findnode [OPTIONS]... <node>
<node>                 ENR URI of the node to send a findNode message
The following options are available:

 --distance       Distance parameter for the findNode message
@jangko
Copy link
Contributor

jangko commented Feb 20, 2022

The code responsible for this behavior is these 3 procs below.
So it was designed with assumption argument fields
will located after non argument fields.

But the weird things is, this expectation is not documented
and these procs also only used in showHelp and friends.

On the other hand, field setters doesn't use these procs thus
they have no problem with fields ordering.

func hasArgs(cmd: CmdInfo): bool =
  cmd.opts.len > 0 and cmd.opts[^1].kind == Arg

func firstArgIdx(cmd: CmdInfo): int =
  # This will work correctly only if the command has arguments.
  result = cmd.opts.len - 1
  while result > 0:
    if cmd.opts[result - 1].kind != Arg:
      return
    dec result

iterator args(cmd: CmdInfo): OptInfo =
  if cmd.hasArgs:
    for i in cmd.firstArgIdx ..< cmd.opts.len:
      yield cmd.opts[i]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants