Skip to content

Commit

Permalink
Handle missed subcommand
Browse files Browse the repository at this point in the history
  • Loading branch information
Ma233 committed Jul 9, 2024
1 parent 3d0e517 commit 9b3baf4
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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!(),
}
}

0 comments on commit 9b3baf4

Please sign in to comment.