// InitCommand will create a new flag set, and call the Command's SetFlags and // Init methods with the appropriate args. func InitCommand(c cmd.Command, args []string) error { f := NewFlagSet() c.SetFlags(f) if err := cmd.ParseArgs(c, f, args); err != nil { return err } return c.Init(f.Args()) }
func RunPlugin(ctx *cmd.Context, subcommand string, args []string) error { plugin := &PluginCommand{name: JujuPluginPrefix + subcommand} flags := gnuflag.NewFlagSet(subcommand, gnuflag.ContinueOnError) flags.SetOutput(ioutil.Discard) plugin.SetFlags(flags) cmd.ParseArgs(plugin, flags, args) plugin.Init(flags.Args()) err := plugin.Run(ctx) _, execError := err.(*exec.Error) // exec.Error results are for when the executable isn't found, in // those cases, drop through. if !execError { return err } return &cmd.UnrecognizedCommand{subcommand} }