(Go: >> BACK << -|- >> HOME <<)

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

help and version show in Positional arguments on subcommands if there's no other options #200

Open
daenney opened this issue Oct 12, 2022 · 0 comments

Comments

@daenney
Copy link
Contributor
daenney commented Oct 12, 2022

When you define a struct which only has positional arguments, the built in --help and --version are printed as part of the positional arguments, instead of the options on subcommands.

On the "root", it works as expected:

type root struct {
	Test string `arg:"positional"`
}

func main() {
	arg.MustParse(&root{})
}
$ go run main.go --help
Usage: main [TEST]

Positional arguments:
  TEST

Options:
  --help, -h             display this help and exit
  --version              display version and exit

But with a subcommand (with 1 or multiple positionals):

type root struct {
	PosOnly *PosOnly `arg:"subcommand:posonly"`
}

type PosOnly struct {
	INPUT  string `arg:"positional"`
	OUTPUT string `arg:"positional"`
}

func main() {
	arg.MustParse(&root{})
}
$ go run main.go --help
Usage: main <command> [<args>]

Options:
  --help, -h             display this help and exit
  --version              display version and exit

Commands:
  posonly

$ go run main.go posonly --help
Usage: main posonly [INPUT [OUTPUT]]

Positional arguments:
  INPUT
  OUTPUT
  --help, -h             display this help and exit
  --version              display version and exit

But add an option:

type root struct {
	PosOnly *PosOnly `arg:"subcommand:posonly"`
}

type PosOnly struct {
	INPUT  string `arg:"positional"`
	OUTPUT string `arg:"positional"`
	Test   string `arg:"-t" default:"test"`
}

func main() {
	arg.MustParse(&root{})
}
$ go run main.go posonly --help
Usage: main posonly [--test TEST] [INPUT [OUTPUT]]

Positional arguments:
  INPUT
  OUTPUT

Options:
  --test TEST, -t TEST [default: test]
  --help, -h             display this help and exit
  --version              display version and exit
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

No branches or pull requests

1 participant