-
Notifications
You must be signed in to change notification settings - Fork 310
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
Global options? #141
Comments
You could possibly do this, but it does seem very cumbersome and weird. I'd rather just fix things and allow parent command level options to be specified after subcommands (i.e. lift the restriction). |
Huh, I wasn't aware that this is possible. Can you give me a hint? Or are you talking about something you will implement? |
I was thinking of something like this: package main
import "github.com/jessevdk/go-flags"
type Opts struct {
Value bool `short:"v"`
}
func main() {
var opts struct {
*Opts
Command struct {
*Opts
} `command:"cmd"`
}
opts.Opts = &Opts{}
opts.Command.Opts = opts.Opts
flags.Parse(&opts)
println(opts.Value)
} But that's definitely hacky :) I went ahead and just removed the limitation, so command parent options can be specified after the command. |
Awesome, thanks! |
First, thanks for the excellent library!
I'm curious if it is possible to have top-level options that are valid as options after a command, i.e. exactly the use-case that (according to the documentation) is not supported. This behavior, unfortunately, confuses users (see restic/restic#198).
Is it maybe possible to define a struct with such global options, embed it in the top-level option struct and again in the command-level option struct? What's the easiest way to merge these two?
I'm looking forward to your comments!
The text was updated successfully, but these errors were encountered: