Open wheresalice opened 6 years ago
Global flags can already be set, by virtue of a cali.Cli also being a cali.Command.
var (
// Define this here, then all other files in cmd can add subcommands to it
cli = cali.NewCli("lucli")
)
func init() {
cli.SetShort("Example CLI tool")
cli.SetLong("A nice long description of what your tool actually does")
cli.Flags().StringP("bob", "r", "default", "Which bob should we use?")
cli.BindFlags()
}
I should definitely start a Wiki for this https://github.com/skybet/cali/wiki <-- currently empty.
As for setting the same flag for different commands... Yeah, that would be useful.
Wondering how it would work.
e.g. perhaps
command.FlagValues().GetString("port")
(this might already work, and be unambiguous, at least for Cobra flags, as you're only ever running one Cobra command. For Viper configs, there's still ambiguity)
Given I am using the flag name 'port' in one command When I define the flag name 'port' in a second command Then the default value will be set to the one in the command highest in the alphabet.
These values are written with a function belonging to
command
and therefore look like they should be command-specific:However the function to read them does not seem to be command-specific:
There should be a way of setting the same flag for different commands without them overriding each other. There should also be a way of setting a global flag for all commands to reuse.