From 9b3baf40abeee23b89447e9698a3c3ef2f793e84 Mon Sep 17 00:00:00 2001 From: magine Date: Tue, 9 Jul 2024 12:59:00 +0800 Subject: [PATCH] Handle missed subcommand --- src/main.rs | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/main.rs b/src/main.rs index 44e3495..cd78a77 100644 --- a/src/main.rs +++ b/src/main.rs @@ -77,7 +77,11 @@ fn parse_args() -> Command { .help("The multiaddr of the remote peer"), ); - app = app.subcommand(serve).subcommand(create_tunnel_server); + app = app + .arg_required_else_help(true) + .subcommand(serve) + .subcommand(create_tunnel_server); + app } @@ -176,13 +180,15 @@ async fn main() { .with_env_filter(tracing_subscriber::EnvFilter::from_default_env()) .try_init(); - let args = parse_args().get_matches(); - - if let Some(args) = args.subcommand_matches("serve") { - serve(args).await; - } + let cmd = parse_args(); - if let Some(args) = args.subcommand_matches("create_tunnel_server") { - create_tunnel_server(args).await; + match cmd.get_matches().subcommand() { + Some(("serve", args)) => { + serve(args).await; + } + Some(("create_tunnel_server", args)) => { + create_tunnel_server(args).await; + } + _ => unreachable!(), } }