alecthomas / kong

Kong is a command-line parser for Go

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Is there any way to achieve this: --version is not inherited to subcommands?

lwx599995 opened this issue · comments

My demo code is like this:

type SubCommand struct {
}

func (c *SubCommand) Run() error {
	return nil
}

var cli struct {
	Version kong.VersionFlag `help:"Show version."`
	Sub     SubCommand       `cmd:""`
}

func main() {
	ctx := kong.Parse(&cli, kong.Vars{"version": "v0.1.0"})
	err := ctx.Run()
	ctx.FatalIfErrorf(err)
}

I want to do something like this:

./cli --version
print: "v0.1.0"

./cli sub --version
print: "unknown flag --version" and exit

./cli sub --help
hide --version flag

Is there any way to achieve this: --version is not inherited to subcommands?
Or is it possible to have a tag like "parent-only" to make that flags are not inherited by subcommands?

No, that is not supported by Kong.

No, that is not supported by Kong.

Okay, thank you very much for the prompt reply.