func (c *SuperCommand) Init(args []string) error {
	if c.showDescription {
		return CheckEmpty(args)
	}
	if len(args) == 0 {
		c.action = c.subcmds["help"]
		return c.action.command.Init(args)
	}

	if userAlias, found := c.userAliases[args[0]]; found && !c.noAlias {
		logger.Debugf("using alias %q=%q", args[0], strings.Join(userAlias, " "))
		args = append(userAlias, args[1:]...)
	}
	found := false
	// Look for the command.
	if c.action, found = c.subcmds[args[0]]; !found {
		if c.missingCallback != nil {
			c.action = commandReference{
				command: &missingCommand{
					callback:  c.missingCallback,
					superName: c.Name,
					name:      args[0],
					args:      args[1:],
				},
			}
			// Yes return here, no Init called on missing Command.
			return nil
		}
		return fmt.Errorf("unrecognized command: %s %s", c.Name, args[0])
	}
	args = args[1:]
	subcmd := c.action.command
	if subcmd.IsSuperCommand() {
		f := gnuflag.NewFlagSetWithFlagKnownAs(c.Info().Name, gnuflag.ContinueOnError, FlagAlias(subcmd, "flag"))
		f.SetOutput(ioutil.Discard)
		subcmd.SetFlags(f)
	} else {
		subcmd.SetFlags(c.commonflags)
	}
	if err := c.commonflags.Parse(subcmd.AllowInterspersedFlags(), args); err != nil {
		return err
	}
	args = c.commonflags.Args()
	if c.showHelp {
		// We want to treat help for the command the same way we would if we went "help foo".
		args = []string{c.action.name}
		c.action = c.subcmds["help"]
	}
	return c.action.command.Init(args)
}
// Init initializes the command for running.
Init initializes the command for running.
// Init initializes the command for running .
func (c *SuperCommand) Init(args []string) error {
	if c.showDescription {
		return CheckEmpty(args)
	}
	if len(args) == 0 {
		c.action = c.subcmds["help"]
		return c.action.command.Init(args)
	}
	if userAlias, found := c.userAliases[args[0]]; found && !c.noAlias {
		logger.Debugf("using alias %q=%q", args[0], strings.Join(userAlias, " "))
		args = append(userAlias, args[1:]...)
	}
	found := false
	if c.action, found = c.subcmds[args[0]]; !found {
		if c.missingCallback != nil {
			c.action = commandReference{
				command: &missingCommand{
					callback:  c.missingCallback,
					superName: c.Name,
					name:      args[0],
					args:      args[1:],
				},
			}
			return nil
		}
		return fmt.Errorf("unrecognized command: %s %s", c.Name, args[0])
	}
	args = args[1:]
	subcmd := c.action.command
	if subcmd.IsSuperCommand() {
		f := gnuflag.NewFlagSetWithFlagKnownAs(c.Info().Name, gnuflag.ContinueOnError, FlagAlias(subcmd, "flag"))
		f.SetOutput(ioutil.Discard)
		subcmd.SetFlags(f)
	} else {
		subcmd.SetFlags(c.commonflags)
	}
	if err := c.commonflags.Parse(subcmd.AllowInterspersedFlags(), args); err != nil {
		return err
	}
	args = c.commonflags.Args()
	if c.showHelp {
		args = []string{c.action.name}
		c.action = c.subcmds["help"]
	}
	return c.action.command.Init(args)
}
func ( c * SuperCommand ) Init ( args [ ] string ) error { if c . showDescription { return CheckEmpty ( args ) } if len ( args ) == 0 { c . action = c . subcmds [ " " ] return c . action . command . Init ( args ) } if userAlias , found := c . userAliases [ args [ 0 ] ] ; found && ! c . noAlias { logger . Debugf ( " " , args [ 0 ] , strings . Join ( userAlias , " " ) ) args = append ( userAlias , args [ 1 : ] ... ) } found := false if c . action , found = c . subcmds [ args [ 0 ] ] ; ! found { if c . missingCallback != nil { c . action = commandReference { command : & missingCommand { callback : c . missingCallback , superName : c . Name , name : args [ 0 ] , args : args [ 1 : ] , } , } return nil } return fmt . Errorf ( " " , c . Name , args [ 0 ] ) } args = args [ 1 : ] subcmd := c . action . command if subcmd . IsSuperCommand ( ) { f := gnuflag . NewFlagSetWithFlagKnownAs ( c . Info ( ) . Name , gnuflag . ContinueOnError , FlagAlias ( subcmd , " " ) ) f . SetOutput ( ioutil . Discard ) subcmd . SetFlags ( f ) } else { subcmd . SetFlags ( c . commonflags ) } if err := c . commonflags . Parse ( subcmd . AllowInterspersedFlags ( ) , args ) ; err != nil { return err } args = c . commonflags . Args ( ) if c . showHelp { args = [ ] string { c . action . name } c . action = c . subcmds [ " " ] } return c . action . command . Init ( args ) }
Init initializes the command for running.
Init initializes the command for running .
// Look for the command. // Yes return here, no Init called on missing Command. // We want to treat help for the command the same way we would if we went "help foo".