pub fn run_sub(&self, app: &App, args: &[&str]) -> XcliResult {
        if !args.is_empty() {
            for cmd in &self.subcommands {
                if args[0] == cmd.name || cmd.alias.as_ref().map_or(false, |a| a == args[0]) {
                    return cmd.run_sub(app, args[1..].to_vec().as_ref());
                }
            }
        }

        // hit an action
        if let Some(action) = &self.action {
            debug!("action for {}, arg={:?}", self.name, args);
            let ret = action(app, &args);
            match &ret {
                Err(XcliError::Other(err)) => {
                    println!("{}", err);
                }
                Err(err) => {
                    println!("{}\n", err);
                    self.show_command_usage();
                }
                Ok(_) => {}
            }

            return ret;
        } else {
            // no action defined, print error message if there are some unrecognized args
            // otherwise, show help message for this command
            if !args.is_empty() {
                debug!("command without action, but with some args {:?}", args);
                println!("Unknown command or arguments : {:?}", args)
            } else {
                debug!("command with no action defined");
                self.show_command_help();
                self.show_subcommand_help();
            }
        }

        Ok(CmdExeCode::Ok)
    }
/// run sub commands
///
/// show error message when action not found but with extra args
///
/// show help messages when action not found for the sub command
///
/// execute sub command when action found
///
run sub commands
show error message when action not found but with extra args

show help messages when action not found for the sub command

execute sub command when action found
run sub commands show error message when action not found but with extra args show help messages when action not found for the sub command execute sub command when action found
pub fn run_sub(&self, app: &App, args: &[&str]) -> XcliResult {
        if !args.is_empty() {
            for cmd in &self.subcommands {
                if args[0] == cmd.name || cmd.alias.as_ref().map_or(false, |a| a == args[0]) {
                    return cmd.run_sub(app, args[1..].to_vec().as_ref());
                }
            }
        }
        // hit an action
        if let Some(action) = &self.action {
            debug!("action for {}, arg={:?}", self.name, args);
            let ret = action(app, &args);
            match &ret {
                Err(XcliError::Other(err)) => {
                    println!("{}", err);
                }
                Err(err) => {
                    println!("{}\n", err);
                    self.show_command_usage();
                }
                Ok(_) => {}
            }
            return ret;
        } else {
            // no action defined, print error message if there are some unrecognized args
            // otherwise, show help message for this command
            if !args.is_empty() {
                debug!("command without action, but with some args {:?}", args);
                println!("Unknown command or arguments : {:?}", args)
            } else {
                debug!("command with no action defined");
                self.show_command_help();
                self.show_subcommand_help();
            }
        }
        Ok(CmdExeCode::Ok)
    }
pub fn run_sub ( & self , app : & App , args : & [ & str ] ) -> XcliResult { if ! args . is_empty ( ) { for cmd in & self . subcommands { if args [ 0 ] == cmd . name || cmd . alias . as_ref ( ) . map_or ( false , | a | a == args [ 0 ] ) { return cmd . run_sub ( app , args [ 1 .. ] . to_vec ( ) . as_ref ( ) ) ; } } } // hit an action if let Some ( action ) = & self . action { debug ! ( " " self name args ) ; let ret = action ( app , & args ) ; match & ret { Err ( XcliError :: Other ( err ) ) => { println ! ( " " err ) ; } Err ( err ) => { println ! ( " \n " err ) ; self . show_command_usage ( ) ; } Ok ( _ ) => { } } return ret ; } else { // no action defined, print error message if there are some unrecognized args // otherwise, show help message for this command if ! args . is_empty ( ) { debug ! ( " " args ) ; println ! ( " " args ) } else { debug ! ( " " ) ; self . show_command_help ( ) ; self . show_subcommand_help ( ) ; } } Ok ( CmdExeCode :: Ok ) }
run sub commands
show error message when action not found but with extra args
run sub commands show error message when action not found but with extra args
&self
app
&App
args
&[&str]
&self
app
&App
args
&[&str]