kong: Unable to fully capture the rest of arguments and pass it through to another command

So I am trying to implement exec pattern, where I have a subtool I want to execute and pass all other arguments to it. Trying passthrough:"" does not fully work with --help flag. I have something like:

type Commands struct {
	Exec ExecCommand `cmd:"" help:"Run the sub-tool.`
}

type ExecCommand struct {
        Arg []string `arg:"" optional:"" passthrough:"" help:"Arguments passed on to the sub-tool."`
}

Inside ExecCommand’s Run I do: subtool.Main(append([]string{"subtool"}, c.Arg...)) to pass all args to the subtool’s CLI parsing.

And this does not work. So if I do:

tool exec foobar

it works well, and sub-tool gets foobar as an argument.

But:

tool exec --help

returns help of tool and not of the sub-tool.

A workaround is:

tool exec -- --help

which does work. But how can I make it work without --? I think this might be related to https://github.com/alecthomas/kong/discussions/216 and in general that I would prefer that global flags do not get inherited by the subcommands. So in general tool --help subcommand should work and tool subcommand --help should not, unless subcommand explicitly defines --help flag.

I tried to move passthrough:"" to Exec itself, but I got panic passthrough only makes sense for positional arguments.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 17 (17 by maintainers)

Commits related to this issue

Most upvoted comments

Sounds good. I will see if I can get to this any time soon and make a PR.

I do not get why we would need allow-flags so I will leave that out for now (you can always just move passthrough to an argument if you want additional flags).