// testInit checks that a command initialises correctly // with the given set of arguments. func testInit(c *C, com cmd.Command, args []string, errPat string) { err := com.Init(newFlagSet(), args) if errPat != "" { c.Assert(err, ErrorMatches, errPat) } else { c.Assert(err, IsNil) } }
// 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 runCommand(com cmd.Command, args ...string) (opc chan dummy.Operation, errc chan error) { errc = make(chan error, 1) opc = make(chan dummy.Operation, 200) dummy.Reset() dummy.Listen(opc) go func() { // signal that we're done with this ops channel. defer dummy.Listen(nil) err := com.Init(newFlagSet(), args) if err != nil { errc <- err return } err = com.Run(cmd.DefaultContext()) errc <- err }() return }
func initCmd(c cmd.Command, args []string) error { f := gnuflag.NewFlagSet("", gnuflag.ContinueOnError) f.SetOutput(ioutil.Discard) return c.Init(f, args) }