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

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

Open
lwx599995 opened this issue Aug 7, 2023 · 2 comments

Comments

@lwx599995
Copy link

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?

@alecthomas
Copy link
Owner

No, that is not supported by Kong.

@lwx599995
Copy link
Author

No, that is not supported by Kong.

Okay, thank you very much for the prompt reply.

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

2 participants