ref cmd format
This commit is contained in:
@@ -4,9 +4,9 @@ pub type CommandError = Result<(), Box<dyn std::error::Error>>;
|
||||
|
||||
pub trait Command {
|
||||
|
||||
fn subcommand<'a>(&self) -> App<'a, 'a>;
|
||||
|
||||
fn name(&self) -> &str;
|
||||
|
||||
fn subcommand<'a>(&self) -> App<'a, 'a>;
|
||||
|
||||
fn run(&self, arg_matches: &ArgMatches, _: &ArgMatches) -> CommandError;
|
||||
}
|
||||
|
||||
@@ -14,16 +14,14 @@ pub struct CommandNewCliApp;
|
||||
|
||||
impl Command for CommandNewCliApp {
|
||||
|
||||
fn name(&self) -> &str { "newcliapp" }
|
||||
|
||||
fn subcommand<'a>(&self) -> App<'a, 'a> {
|
||||
SubCommand::with_name(self.name()).about("New cli app")
|
||||
.arg(Arg::with_name("APP_NAME").required(true).index(1).help("App name"))
|
||||
.arg(Arg::with_name("verbose").long("verbose").short("V").help("Verbose"))
|
||||
}
|
||||
|
||||
fn name(&self) -> &str {
|
||||
"newcliapp"
|
||||
}
|
||||
|
||||
fn run(&self, _arg_matches: &ArgMatches, sub_arg_matches: &ArgMatches) -> CommandError {
|
||||
let is_verbose = sub_arg_matches.is_present("verbose");
|
||||
|
||||
|
||||
@@ -5,14 +5,12 @@ pub struct CommandSample;
|
||||
|
||||
impl Command for CommandSample {
|
||||
|
||||
fn name(&self) -> &str { "sample" }
|
||||
|
||||
fn subcommand<'a>(&self) -> App<'a, 'a> {
|
||||
SubCommand::with_name(self.name()).about("Sample subcommand")
|
||||
}
|
||||
|
||||
fn name(&self) -> &str {
|
||||
"sample"
|
||||
}
|
||||
|
||||
fn run(&self, _arg_matches: &ArgMatches, _sub_arg_matches: &ArgMatches) -> CommandError {
|
||||
println!("This is test command!");
|
||||
Ok(())
|
||||
|
||||
Reference in New Issue
Block a user