Skip to content

Commit

Permalink
fix: use matches to get a command
Browse files Browse the repository at this point in the history
  • Loading branch information
therustmonk committed Mar 4, 2022
1 parent 42ceba2 commit 4f35513
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
3 changes: 1 addition & 2 deletions applications/tari_base_node/src/commands/command/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use std::{str::FromStr, sync::Arc, time::Instant};

use anyhow::Error;
use async_trait::async_trait;
use clap::{AppSettings, Parser, Subcommand};
use clap::{Parser, Subcommand};
use strum::{EnumVariantNames, VariantNames};
use tari_common::GlobalConfig;
use tari_comms::{
Expand All @@ -58,7 +58,6 @@ use tokio::sync::watch;
use crate::{builder::BaseNodeContext, commands::parser::FromHex};

#[derive(Debug, Parser)]
#[clap(setting = AppSettings::NoBinaryName)]
pub struct Args {
#[clap(subcommand)]
pub command: Command,
Expand Down
8 changes: 5 additions & 3 deletions applications/tari_base_node/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ use std::{
time::{Duration, Instant},
};

use clap::Parser as _;
use clap::{CommandFactory, FromArgMatches};
use commands::{
command::{CommandContext, HandleCommand},
command::{Args, CommandContext, HandleCommand},
parser::Parser,
reader::{CommandEvent, CommandReader},
};
Expand Down Expand Up @@ -422,7 +422,9 @@ async fn cli_loop(mut context: CommandContext) {
first_signal = false;
if !line.is_empty() {
let sw = line.split_whitespace();
let args = commands::command::Args::try_parse_from(sw);
let args = Args::command().no_binary_name(true)
.try_get_matches_from(sw)
.and_then(|matches| Args::from_arg_matches(&matches));
match args {
Ok(args) => {
let fut = context.handle_command(args.command);
Expand Down

0 comments on commit 4f35513

Please sign in to comment.