feat(bonfire): add Passthrough and Long command fields
- Command.Passthrough turns off cobra flag parsing and uses arbitrary args, so every argument after the command name, including --help, -h and --, reaches Run through Input.Args unchanged - Command.Long sets cobra's Long text for the help command; without it the description is shown as before - both fields are additive: commands without Passthrough parse flags and reject unknown ones exactly as before - README and docs/console/writing-commands.md describe both fields
This commit is contained in:
@@ -54,6 +54,7 @@ func wrap(c Command, out Output) (*cobra.Command, error) {
|
||||
cmd := &cobra.Command{
|
||||
Use: commandUsage(c),
|
||||
Short: c.Description,
|
||||
Long: c.Long,
|
||||
Args: positionalArgs(c.Args),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
if c.Run == nil {
|
||||
@@ -62,6 +63,11 @@ func wrap(c Command, out Output) (*cobra.Command, error) {
|
||||
return c.Run(cmd.Context(), cobraInput{cmd: cmd, spec: c, args: args}, out)
|
||||
},
|
||||
}
|
||||
if c.Passthrough {
|
||||
// Every argument, flags included, reaches Run as given.
|
||||
cmd.DisableFlagParsing = true
|
||||
cmd.Args = cobra.ArbitraryArgs
|
||||
}
|
||||
for _, flag := range c.Flags {
|
||||
if flag.Repeatable {
|
||||
// D-19: an ordered, multi-occurrence string flag (Cobra
|
||||
|
||||
Reference in New Issue
Block a user