From 065d1a89a62c29450b8a5ea38ce4c53fde993f62 Mon Sep 17 00:00:00 2001 From: Hatter Jiang Date: Sat, 2 Jul 2022 18:50:01 +0800 Subject: [PATCH] feat: add subcommands cli, serve --- src/cli.rs | 18 ++++++++++++++++++ src/main.rs | 8 +++++++- src/serve.rs | 18 ++++++++++++++++++ 3 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 src/cli.rs create mode 100644 src/serve.rs diff --git a/src/cli.rs b/src/cli.rs new file mode 100644 index 0000000..e16ad8c --- /dev/null +++ b/src/cli.rs @@ -0,0 +1,18 @@ +use clap::{App, Arg, ArgMatches, SubCommand}; +use rust_util::simple_error; +use rust_util::util_clap::{Command, CommandError}; + +pub struct CommandImpl; + +impl Command for CommandImpl { + fn name(&self) -> &str { "cli" } + + fn subcommand<'a>(&self) -> App<'a, 'a> { + SubCommand::with_name(self.name()).about("Local mini KMS cli") + .arg(Arg::with_name("connect").long("connect").takes_value(true).default_value("127.0.0.1:6567").help("Connect server")) + } + + fn run(&self, _arg_matches: &ArgMatches, sub_arg_matches: &ArgMatches) -> CommandError { + simple_error!("Not implemented") + } +} \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 2bc38ee..97309b9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,6 +2,9 @@ use clap::{App, AppSettings, ArgMatches}; use rust_util::{failure_and_exit, information}; use rust_util::util_clap::{Command, CommandError}; +mod cli; +mod serve; + pub struct DefaultCommandImpl; impl DefaultCommandImpl { @@ -21,7 +24,10 @@ fn main() { } fn inner_main() -> CommandError { - let commands: Vec> = vec![]; + let commands: Vec> = vec![ + Box::new(cli::CommandImpl), + Box::new(serve::CommandImpl), + ]; let mut app = App::new(env!("CARGO_PKG_NAME")) .version(env!("CARGO_PKG_VERSION")) .about(env!("CARGO_PKG_DESCRIPTION")) diff --git a/src/serve.rs b/src/serve.rs new file mode 100644 index 0000000..bc6aa6c --- /dev/null +++ b/src/serve.rs @@ -0,0 +1,18 @@ +use clap::{App, Arg, ArgMatches, SubCommand}; +use rust_util::simple_error; +use rust_util::util_clap::{Command, CommandError}; + +pub struct CommandImpl; + +impl Command for CommandImpl { + fn name(&self) -> &str { "serve" } + + fn subcommand<'a>(&self) -> App<'a, 'a> { + SubCommand::with_name(self.name()).about("Local mini KMS serve") + .arg(Arg::with_name("listen").long("listen").takes_value(true).default_value("127.0.0.1:6567").help("Listen")) + } + + fn run(&self, _arg_matches: &ArgMatches, sub_arg_matches: &ArgMatches) -> CommandError { + simple_error!("Not implemented") + } +} \ No newline at end of file