From 02cb88ceb547a788a14a9d3fdb07407a51fad83a Mon Sep 17 00:00:00 2001 From: Hatter Jiang Date: Sun, 14 Jun 2020 00:28:38 +0800 Subject: [PATCH] ref cmd format --- src/cmd.rs | 4 ++-- src/cmd_newcliapp.rs | 6 ++---- src/cmd_sample.rs | 6 ++---- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/src/cmd.rs b/src/cmd.rs index 7b40197..6ecaf42 100644 --- a/src/cmd.rs +++ b/src/cmd.rs @@ -4,9 +4,9 @@ pub type CommandError = Result<(), Box>; 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; } diff --git a/src/cmd_newcliapp.rs b/src/cmd_newcliapp.rs index 6f3f322..b0abeed 100644 --- a/src/cmd_newcliapp.rs +++ b/src/cmd_newcliapp.rs @@ -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"); diff --git a/src/cmd_sample.rs b/src/cmd_sample.rs index b1bd812..5d8e812 100644 --- a/src/cmd_sample.rs +++ b/src/cmd_sample.rs @@ -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(())