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

Allow for reuse of flag names in different tasks #13

Open
wheresalice opened this issue Jan 31, 2018 · 2 comments
Open

Allow for reuse of flag names in different tasks #13

wheresalice opened this issue Jan 31, 2018 · 2 comments

Comments

@wheresalice
Copy link

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:

command.Flags().StringP("port", "p", "8000", "Port to expose on host")

However the function to read them does not seem to be command-specific:

cli.FlagValues().GetString("port")

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.

@lucymhdavies
Copy link

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.

@lucymhdavies
Copy link

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants