Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to clap 4.x #1079

Merged
merged 4 commits into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,7 @@ dusk-bls12_381-sign = { version = "0.4", default-features = false }
console-subscriber = { version = "0.1.8", optional = true }
smallvec = "1.10.0"

## Binary dependencies
clap = { version = "3.1", features = ["env"] }
toml = "0.5"
serde = "1.0"
dirs = "4"

[dev-dependencies]
fake = { version = "2.5", features = ['derive'] }
Expand Down
10 changes: 4 additions & 6 deletions node/src/databroker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,13 @@ pub struct DataBrokerSrv {
}

impl DataBrokerSrv {
pub fn new(conf: &conf::Params) -> Self {
pub fn new(conf: conf::Params) -> Self {
info!("DataBrokerSrv::new with conf: {}", conf);

let permits = conf.max_ongoing_requests;
Self {
conf: conf.clone(),
conf,
requests: AsyncQueue::default(),
limit_ongoing_requests: Arc::new(Semaphore::new(
conf.max_ongoing_requests,
)),
limit_ongoing_requests: Arc::new(Semaphore::new(permits)),
}
}
}
Expand Down
32 changes: 1 addition & 31 deletions node/src/databroker/conf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

use std::fmt::Formatter;

use clap::{Arg, ArgMatches, Command};
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize, Clone)]
Expand All @@ -29,7 +28,7 @@ impl Default for Params {
}
}

impl std::fmt::Display for &Params {
impl std::fmt::Display for Params {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(
f,
Expand All @@ -38,32 +37,3 @@ impl std::fmt::Display for &Params {
)
}
}

impl Params {
pub fn merge(&mut self, matches: &ArgMatches) {
if let Some(delay_on_resp_msg) = matches.value_of("delay_on_resp_msg") {
match delay_on_resp_msg.parse() {
Ok(delay_on_resp_msg) => {
self.delay_on_resp_msg = Some(delay_on_resp_msg);
}
Err(e) => {
tracing::error!(
"Failed to parse delay_on_resp_msg: {:?}",
e
);
}
}
};
}

pub fn inject_args(command: Command<'_>) -> Command<'_> {
command.arg(
Arg::new("delay_on_resp_msg")
.long("delay_on_resp_msg")
.help("Delay in milliseconds to mitigate UDP drops for DataBroker service in localnet")
.env("DELAY_ON_RESP_MSG")
.takes_value(true)
.required(false),
)
}
}
2 changes: 1 addition & 1 deletion rusk-recovery/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ once_cell = "1.13"
dusk-bytes = "0.1"
dusk-bls12_381 = "0.11"
dusk-bls12_381-sign = "0.4"
clap = { version = "3.1", features = ["cargo", "env", "derive"] }
clap = { version = "4", features = ["env", "derive"] }
thiserror = "1.0"
tracing = { version = "0.1", features = ["log"] }
tracing-subscriber = { version = "0.2.0", features = ["fmt"] }
Expand Down
9 changes: 5 additions & 4 deletions rusk-recovery/src/bin/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
mod task;
mod version;

use clap::Parser;
use clap::builder::BoolishValueParser;
use clap::{ArgAction, Parser};
use std::path::PathBuf;
use version::VERSION_BUILD;

Expand All @@ -19,18 +20,18 @@ struct Cli {
#[clap(
short,
long,
parse(from_os_str),
value_parser,
value_name = "PATH",
env = "RUSK_PROFILE_PATH"
)]
profile: Option<PathBuf>,

/// Keeps untracked keys
#[clap(short, long, env = "RUSK_KEEP_KEYS")]
#[clap(short, long, value_parser = BoolishValueParser::new(), env = "RUSK_KEEP_KEYS")]
keep: bool,

/// Sets different levels of verbosity
#[clap(short, long, parse(from_occurrences))]
#[clap(short, long, action = ArgAction::Count)]
verbose: usize,
}

Expand Down
11 changes: 6 additions & 5 deletions rusk-recovery/src/bin/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
mod task;
mod version;

use clap::builder::{ArgAction, BoolishValueParser};
use clap::Parser;
use rusk_recovery_tools::Theme;
use std::error::Error;
Expand All @@ -25,27 +26,27 @@ struct Cli {
#[clap(
short,
long,
parse(from_os_str),
value_parser,
value_name = "PATH",
env = "RUSK_PROFILE_PATH"
)]
profile: Option<PathBuf>,

/// Forces a build/download even if the state is in the profile path.
#[clap(short = 'f', long, env = "RUSK_FORCE_STATE")]
#[clap(short = 'f', value_parser = BoolishValueParser::new(), long, env = "RUSK_FORCE_STATE")]
force: bool,

/// Create a state applying the init config specified in this file.
#[clap(short, long, parse(from_os_str), env = "RUSK_RECOVERY_INPUT")]
#[clap(short, long, value_parser, env = "RUSK_RECOVERY_INPUT")]
init: Option<PathBuf>,

/// Sets different levels of verbosity
#[clap(short, long, parse(from_occurrences))]
#[clap(short, long, action = ArgAction::Count)]
verbose: usize,

/// If specified, the generated state is written on this file instead of
/// save the state in the profile path.
#[clap(short, long, parse(from_os_str), takes_value(true))]
#[clap(short, long, value_parser, num_args(1))]
output: Option<PathBuf>,
}

Expand Down
2 changes: 1 addition & 1 deletion rusk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ tracing-subscriber = { version = "0.3.0", features = [
"env-filter",
"json",
] }
clap = { version = "3.1", features = ["env"] }
clap = { version = "4", features = ["env", "string", "derive"] }
semver = "1.0"
anyhow = "1.0"
rustc_tools_util = "0.3"
Expand Down
84 changes: 84 additions & 0 deletions rusk/src/bin/args.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
//
// Copyright (c) DUSK NETWORK. All rights reserved.

use std::path::PathBuf;

use clap::builder::PossibleValuesParser;
use clap::Parser;

use crate::version::VERSION_BUILD;

#[derive(Parser, Debug)]
#[command(
author="Dusk Network B.V. All Rights Reserved.",
version = &VERSION_BUILD[..],
about = "Rusk server node",
)]
pub struct Args {
/// Sets the profile path
#[clap(long, short, env = "RUSK_CONFIG_TOML", value_parser)]
pub config: Option<PathBuf>,

/// Output log level
#[clap(long)]
pub log_level: Option<tracing::Level>,

// Change the log format accordingly
#[clap(long, value_parser = PossibleValuesParser::new(["coloured", "plain", "json"]))]
pub log_type: Option<String>,

/// Add log filter(s)
#[clap(long)]
pub log_filter: Option<String>,

/// Sets the profile path
#[clap(long, value_parser)]
pub profile: Option<PathBuf>,

#[cfg(feature = "ephemeral")]
/// Ephemeral state file (archive)
#[clap(short, long = "state", value_parser)]
pub state_path: Option<PathBuf>,

#[clap(long, value_parser)]
/// path to blockchain database
pub db_path: Option<PathBuf>,

#[clap(long, value_parser)]
/// path to encrypted BLS keys
pub consensus_keys_path: Option<PathBuf>,

#[clap(long)]
/// Delay in milliseconds to mitigate UDP drops for DataBroker service in
/// localnet
pub delay_on_resp_msg: Option<u64>,

#[clap(long)]
/// Address http server should listen on
pub http_listen_addr: Option<String>,

#[clap(long, env = "KADCAST_BOOTSTRAP", verbatim_doc_comment)]
/// Kadcast list of bootstrapping server addresses
pub kadcast_bootstrap: Option<Vec<String>>,

#[clap(long, env = "KADCAST_PUBLIC_ADDRESS", verbatim_doc_comment)]
/// Public address you want to be identified with. Eg: 193.xxx.xxx.198:9999
///
/// This is the address where other peer can contact you.
/// This address MUST be accessible from any peer of the network"
pub kadcast_public_address: Option<String>,

#[clap(long, env = "KADCAST_LISTEN_ADDRESS", verbatim_doc_comment)]
/// Optional internal address to listen incoming connections. Eg:
/// 127.0.0.1:9999
///
/// This address is the one bound for the incoming connections.
/// Use this argument if your host is not publicly reachable from other
/// peer in the network (Eg: if you are behind a NAT)
/// If this is not specified, the public address is used for binding
/// incoming connection
pub kadcast_listen_address: Option<String>,
}
Loading