akamensky / argparse

Argparse for golang. Just because `flag` sucks
MIT License
611 stars 62 forks source link

Repeated text in sub-command usage text #59

Closed skaymakca closed 4 years ago

skaymakca commented 4 years ago

Thank you for the great library! As a former python argparse user this has helped getting a CLI together for some go work.

Working on a program with two levels of sub-commands I noticed the help info repeats with incorrect/incomplete argument usage. This is the not the case with doing -h on the sub-command.

This does not seem to be the same issue as #5 but might be related?

The command-advanced in examples shows this same behavior:

Repeated:

user@vubuntu:~/code/argparse/examples/commands-advanced$ ./commands-advanced dog
[sub]Command required
usage: zooprog dog <Command> [--wiggle] [-h|--help] --name "<value>"

               We are going to see dog

Commands:

  speak   Make the dog speak
  feed    Make the dog eat
  summon  Make the dog come over
  play    Make the dog play

Arguments:

      --wiggle  Makes the dog to wiggle its tail
  -h  --help    Print help information
      --name    Provide an optional name for the animal

usage: zooprog dog <Command> [--wiggle] [-h|--help] --name "<value>"

               We are going to see dog

Commands:

  speak   Make the dog speak
  feed    Make the dog eat
  summon  Make the dog come over
  play    Make the dog play

Arguments:

      --wiggle  Makes the dog to wiggle its tail
  -h  --help    Print help information
      --name    Provide an optional name for the animal

OK:

user@vubuntu:~/code/argparse/examples/commands-advanced$ ./commands-advanced dog -h
usage: zooprog dog <Command> [--wiggle] [-h|--help] --name "<value>"

               We are going to see dog

Commands:

  speak   Make the dog speak
  feed    Make the dog eat
  summon  Make the dog come over
  play    Make the dog play

Arguments:

      --wiggle  Makes the dog to wiggle its tail
  -h  --help    Print help information
      --name    Provide an optional name for the animal
akamensky commented 4 years ago

Looks like a bug introduced by recent changes

akamensky commented 4 years ago

@densestvoid you did some changes recently related to Usage output, do you think this is related? I verified this using examples/commands-advanced example code.

naughtyGitCat commented 4 years ago

same bug happened to me

naughtyGitCat commented 4 years ago

when no args were given, the root and the sub both print help info twice

thegreyd commented 4 years ago

@akamensky Hello, I was looking at the library earlier and had some time to sit and take a look at the issue. The fix looked easy enough so I submitted a PR here https://github.com/akamensky/argparse/pull/60

akamensky commented 4 years ago

@skaymakca or @naughtyGitCat can either of you please verify the issue is resolved in latest tip 936811b? (not released to go mod yet)

naughtyGitCat commented 4 years ago

@skaymakca or @naughtyGitCat can either of you please verify the issue is resolved in latest tip 936811b? (not released to go mod yet)

the commands-advanced test seems correct, but I don't know how to test in my go.mod managed project

skaymakca commented 4 years ago

I wasn't able to test commands-advanced but I was able to test the commit in my internal project and the output looks correct now.

@naughtyGitCat I was able to test by running (in my go.mod project): go get github.com/akamensky/argparse@936811b12db25dad4b7b86cbfd1dcc61571145cc

naughtyGitCat commented 4 years ago

I wasn't able to test commands-advanced but I was able to test the commit in my internal project and the output looks correct now.

@naughtyGitCat I was able to test by running (in my go.mod project): go get github.com/akamensky/argparse@936811b12db25dad4b7b86cbfd1dcc61571145cc

It fixed the problem, thanks

naughtyGitCat commented 4 years ago

go get github.com/akamensky/argparse@936811b12db25dad4b7b86cbfd1dcc61571145cc

It fixed the problem, thanks

skaymakca commented 4 years ago

I see the fix was merged into master. Thanks everyone!

akamensky commented 4 years ago

It has been released in v1.2.1 for go.mod projects