cli [OPTION] -flagA arg0 -flagB arg1 -flagC arg2
How to achieve such a program just like “cli [OPTION] -flagA arg0 -flagB arg1 -flagC arg2”
If [OPTION] is a positional argument, which covers arbitrary values that get passed in like a function parameter would be, the docs for usage are here: https://github.com/urfave/cli/blob/master/docs/v2/manual.md#arguments
If [OPTION] should be a command, which covers a fixed number of different actions that could be taken, the docs are here: https://github.com/urfave/cli/blob/master/docs/v2/manual.md#subcommands
If the question is about how to pass the same flags to every command, there's two options:
- Define a list of flags, then use them as configuration for each command:
flags := []cli.Flag{
// ...
}
app := cli.NewApp()
app.Commands = []*cli.Command{
{
Name: "cmd1",
Flags: flags,
// ...
},
{
Name: "cmd2",
Flags: flags,
// ...
},
}
- Define them globally so they are available for all commands out of the box. If this option is picked, flags must be passed before the command rather than after, like so:
cli -flagA arg0 -flagB arg1 -flagC arg2 [COMMAND]
app := cli.NewApp()
app.Flags = []cli.Flag{
// ...
}
Let me know if that doesn't answer your question.
thanks my bro
This issue or PR has been automatically marked as stale because it has not had recent activity. Please add a comment bumping this if you're still interested in it's resolution! Thanks for your help, please let us know if you need anything else.
Closing this as it has become stale.
I think (?) this is resolved? @hnistlzy Please let us know if this should be reopened if that's not the case 😁