mirror of
https://github.com/jht5945/rust_util.git
synced 2025-12-27 15:40:03 +08:00
feat: opt use_clap
This commit is contained in:
@@ -16,7 +16,7 @@ pub trait DefaultCommand {
|
||||
fn run(&self, arg_matches: &ArgMatches) -> CommandError;
|
||||
}
|
||||
|
||||
pub struct DefaultCommandImpl {}
|
||||
pub struct DefaultCommandImpl;
|
||||
impl DefaultCommand for DefaultCommandImpl {
|
||||
fn process_command<'a>(&self, app: App<'a, 'a>) -> App<'a, 'a> {
|
||||
app.arg(Arg::with_name("verbose").long("verbose").short("v").multiple(true).help("Show verbose info"))
|
||||
@@ -36,6 +36,10 @@ pub struct CommandExecutor {
|
||||
}
|
||||
|
||||
impl CommandExecutor {
|
||||
pub fn new_default() -> Self {
|
||||
Self::new(None)
|
||||
}
|
||||
|
||||
pub fn new(default_cmd: Option<Box<dyn DefaultCommand>>) -> Self {
|
||||
CommandExecutor{
|
||||
default_cmd,
|
||||
@@ -48,6 +52,13 @@ impl CommandExecutor {
|
||||
self
|
||||
}
|
||||
|
||||
pub fn add_commands(&mut self, cmds: Vec<Box<dyn Command>>) -> &mut Self {
|
||||
for cmd in cmds.into_iter() {
|
||||
self.add(cmd);
|
||||
}
|
||||
self
|
||||
}
|
||||
|
||||
pub fn run(&self) -> XResult<()> {
|
||||
let mut app = App::new(env!("CARGO_PKG_NAME"))
|
||||
.version(env!("CARGO_PKG_VERSION"))
|
||||
|
||||
Reference in New Issue
Block a user