func (cdr *Commander) Execute(ctx context.Context, args ...interface{}) ExitStatus {
	if cdr.topFlags.NArg() < 1 {
		cdr.topFlags.Usage()
		return ExitUsageError
	}

	name := cdr.topFlags.Arg(0)

	for _, group := range cdr.commands {
		for _, cmd := range group.commands {
			if name != cmd.Name() {
				continue
			}
			f := flag.NewFlagSet(name, flag.ContinueOnError)
			f.Usage = func() { explain(cdr.Error, cmd) }
			cmd.SetFlags(f)
			if f.Parse(cdr.topFlags.Args()[1:]) != nil {
				return ExitUsageError
			}
			return cmd.Execute(ctx, f, args...)
		}
	}

	// Cannot find this command.
	cdr.topFlags.Usage()
	return ExitUsageError
}
func (cdr *Commander) Execute(ctx context.Context, args ...interface{}) ExitStatus {
	if cdr.topFlags.NArg() < 1 {
		cdr.topFlags.Usage()
		return ExitUsageError
	}

	name := cdr.topFlags.Arg(0)

	for _, group := range cdr.commands {
		for _, cmd := range group.commands {
			if name != cmd.Name() {
				continue
			}
			f := flag.NewFlagSet(name, flag.ContinueOnError)
			f.Usage = func() { explain(cdr.Error, cmd) }
			cmd.SetFlags(f)
			if f.Parse(cdr.topFlags.Args()[1:]) != nil {
				return ExitUsageError
			}
			return cmd.Execute(ctx, f, args...)
		}
	}

	
	cdr.topFlags.Usage()
	return ExitUsageError
}
func ( cdr * Commander ) Execute ( ctx context . Context , args ... interface { } ) ExitStatus { if cdr . topFlags . NArg ( ) < 1 { cdr . topFlags . Usage ( ) return ExitUsageError } name := cdr . topFlags . Arg ( 0 ) for _ , group := range cdr . commands { for _ , cmd := range group . commands { if name != cmd . Name ( ) { continue } f := flag . NewFlagSet ( name , flag . ContinueOnError ) f . Usage = func ( ) { explain ( cdr . Error , cmd ) } cmd . SetFlags ( f ) if f . Parse ( cdr . topFlags . Args ( ) [ 1 : ] ) != nil { return ExitUsageError } return cmd . Execute ( ctx , f , args ... ) } } // Cannot find this command. cdr . topFlags . Usage ( ) return ExitUsageError }
// Execute should be called once the top-level-flags on a Commander
// have been initialized. It finds the correct subcommand and executes
// it, and returns an ExitStatus with the result. On a usage error, an
// appropriate message is printed to os.Stderr, and ExitUsageError is
// returned. The additional args are provided as-is to the Execute method
// of the selected Command.
Execute should be called once the top - level - flags on a Commander have been initialized . It finds the correct subcommand and executes it and returns an ExitStatus with the result . On a usage error an appropriate message is printed to os . Stderr and ExitUsageError is returned . The additional args are provided as - is to the Execute method of the selected Command .