made most of cli boolean arguments optional (#2819)

so that if not provided, they would not overwrite config values
This commit is contained in:
Jędrzej Stuczyński
2023-01-11 12:14:16 +00:00
committed by GitHub
parent b0960091c1
commit bf5b8fab85
10 changed files with 42 additions and 36 deletions
+2 -2
View File
@@ -41,7 +41,7 @@ pub(crate) struct Init {
/// Whether to not start the websocket
#[clap(long)]
disable_socket: bool,
disable_socket: Option<bool>,
/// Port for the socket (if applicable) to listen on in all subsequent runs
#[clap(short, long)]
@@ -60,7 +60,7 @@ pub(crate) struct Init {
/// with bandwidth credential requirement.
#[cfg(feature = "coconut")]
#[clap(long)]
enabled_credentials_mode: bool,
enabled_credentials_mode: Option<bool>,
/// Save a summary of the initialization to a json file
#[clap(long)]
+5 -5
View File
@@ -54,7 +54,7 @@ pub(crate) enum Commands {
// Configuration that can be overridden.
pub(crate) struct OverrideConfig {
nym_apis: Option<Vec<url::Url>>,
disable_socket: bool,
disable_socket: Option<bool>,
port: Option<u16>,
fastmode: bool,
no_cover: bool,
@@ -62,7 +62,7 @@ pub(crate) struct OverrideConfig {
#[cfg(feature = "coconut")]
nyxd_urls: Option<Vec<url::Url>>,
#[cfg(feature = "coconut")]
enabled_credentials_mode: bool,
enabled_credentials_mode: Option<bool>,
}
pub(crate) async fn execute(args: &Cli) -> Result<(), Box<dyn Error + Send + Sync>> {
@@ -80,7 +80,7 @@ pub(crate) async fn execute(args: &Cli) -> Result<(), Box<dyn Error + Send + Syn
pub(crate) fn override_config(mut config: Config, args: OverrideConfig) -> Config {
config = config
.with_disabled_socket(args.disable_socket)
.with_optional(Config::with_disabled_socket, args.disable_socket)
.with_base(BaseConfig::with_high_default_traffic_volume, args.fastmode)
.with_base(BaseConfig::with_disabled_cover_traffic, args.no_cover)
.with_optional(Config::with_port, args.port)
@@ -100,9 +100,9 @@ pub(crate) fn override_config(mut config: Config, args: OverrideConfig) -> Confi
network_defaults::var_names::NYXD,
config::parse_urls,
)
.with_base(
.with_optional_ext(
BaseConfig::with_disabled_credentials,
!args.enabled_credentials_mode,
args.enabled_credentials_mode.map(|b| !b),
);
}
+2 -2
View File
@@ -38,7 +38,7 @@ pub(crate) struct Run {
/// Whether to not start the websocket
#[clap(long)]
disable_socket: bool,
disable_socket: Option<bool>,
/// Port for the socket to listen on
#[clap(short, long)]
@@ -57,7 +57,7 @@ pub(crate) struct Run {
/// with bandwidth credential requirement.
#[cfg(feature = "coconut")]
#[clap(long)]
enabled_credentials_mode: bool,
enabled_credentials_mode: Option<bool>,
}
impl From<Run> for OverrideConfig {
+2 -2
View File
@@ -31,7 +31,7 @@ pub(crate) struct Init {
/// Note that some service providers might not support this.
// the alias here is included for backwards compatibility (1.1.4 and before)
#[clap(long, alias = "use_anonymous_sender_tag")]
use_reply_surbs: bool,
use_reply_surbs: Option<bool>,
/// Id of the gateway we are going to connect to.
#[clap(long)]
@@ -69,7 +69,7 @@ pub(crate) struct Init {
/// with bandwidth credential requirement.
#[cfg(feature = "coconut")]
#[clap(long)]
enabled_credentials_mode: bool,
enabled_credentials_mode: Option<bool>,
/// Save a summary of the initialization to a json file
#[clap(long)]
+5 -5
View File
@@ -57,14 +57,14 @@ pub(crate) enum Commands {
pub(crate) struct OverrideConfig {
nym_apis: Option<Vec<url::Url>>,
port: Option<u16>,
use_anonymous_replies: bool,
use_anonymous_replies: Option<bool>,
fastmode: bool,
no_cover: bool,
#[cfg(feature = "coconut")]
nyxd_urls: Option<Vec<url::Url>>,
#[cfg(feature = "coconut")]
enabled_credentials_mode: bool,
enabled_credentials_mode: Option<bool>,
}
pub(crate) async fn execute(args: &Cli) -> Result<(), Box<dyn Error + Send + Sync>> {
@@ -84,7 +84,7 @@ pub(crate) fn override_config(mut config: Config, args: OverrideConfig) -> Confi
config = config
.with_base(BaseConfig::with_high_default_traffic_volume, args.fastmode)
.with_base(BaseConfig::with_disabled_cover_traffic, args.no_cover)
.with_anonymous_replies(args.use_anonymous_replies)
.with_optional(Config::with_anonymous_replies, args.use_anonymous_replies)
.with_optional(Config::with_port, args.port)
.with_optional_custom_env_ext(
BaseConfig::with_custom_nym_apis,
@@ -102,9 +102,9 @@ pub(crate) fn override_config(mut config: Config, args: OverrideConfig) -> Confi
network_defaults::var_names::NYXD,
config::parse_urls,
)
.with_base(
.with_optional_ext(
BaseConfig::with_disabled_credentials,
!args.enabled_credentials_mode,
args.enabled_credentials_mode.map(|b| !b),
);
}
+2 -2
View File
@@ -31,7 +31,7 @@ pub(crate) struct Run {
/// Note that some service providers might not support this.
// the alias here is included for backwards compatibility (1.1.4 and before)
#[clap(long, alias = "use_anonymous_sender_tag")]
use_anonymous_replies: bool,
use_anonymous_replies: Option<bool>,
/// Address of the socks5 provider to send messages to.
#[clap(long)]
@@ -68,7 +68,7 @@ pub(crate) struct Run {
/// with bandwidth credential requirement.
#[cfg(feature = "coconut")]
#[clap(long)]
enabled_credentials_mode: bool,
enabled_credentials_mode: Option<bool>,
}
impl From<Run> for OverrideConfig {
+4 -4
View File
@@ -68,11 +68,11 @@ pub struct Init {
/// bypass bandwidth credential requirement
#[cfg(feature = "coconut")]
#[clap(long)]
only_coconut_credentials: bool,
only_coconut_credentials: Option<bool>,
/// Enable/disable gateway anonymized statistics that get sent to a statistics aggregator server
#[clap(long)]
enabled_statistics: bool,
enabled_statistics: Option<bool>,
/// URL where a statistics aggregator is running. The default value is a Nym aggregator server
#[clap(long)]
@@ -182,11 +182,11 @@ mod tests {
nym_apis: None,
mnemonic: None,
statistics_service_url: None,
enabled_statistics: false,
enabled_statistics: None,
#[cfg(feature = "coconut")]
nyxd_urls: None,
#[cfg(feature = "coconut")]
only_coconut_credentials: false,
only_coconut_credentials: None,
};
std::env::set_var(BECH32_PREFIX, "n");
+7 -4
View File
@@ -52,7 +52,7 @@ pub(crate) struct OverrideConfig {
clients_port: Option<u16>,
datastore: Option<PathBuf>,
announce_host: Option<String>,
enabled_statistics: bool,
enabled_statistics: Option<bool>,
statistics_service_url: Option<url::Url>,
nym_apis: Option<Vec<url::Url>>,
mnemonic: Option<bip39::Mnemonic>,
@@ -60,7 +60,7 @@ pub(crate) struct OverrideConfig {
#[cfg(feature = "coconut")]
nyxd_urls: Option<Vec<url::Url>>,
#[cfg(feature = "coconut")]
only_coconut_credentials: bool,
only_coconut_credentials: Option<bool>,
}
pub(crate) async fn execute(args: Cli) {
@@ -103,7 +103,7 @@ pub(crate) fn override_config(mut config: Config, args: OverrideConfig) -> Confi
NYM_API,
config::parse_urls,
)
.with_enabled_statistics(args.enabled_statistics)
.with_optional(Config::with_enabled_statistics, args.enabled_statistics)
.with_optional_env(
Config::with_custom_statistics_service_url,
args.statistics_service_url,
@@ -130,7 +130,10 @@ pub(crate) fn override_config(mut config: Config, args: OverrideConfig) -> Confi
NYXD,
config::parse_urls,
)
.with_only_coconut_credentials(args.only_coconut_credentials);
.with_optional(
Config::with_only_coconut_credentials,
args.only_coconut_credentials,
);
}
config
+2 -2
View File
@@ -68,11 +68,11 @@ pub struct Run {
/// bypass bandwidth credential requirement
#[cfg(feature = "coconut")]
#[clap(long)]
only_coconut_credentials: bool,
only_coconut_credentials: Option<bool>,
/// Enable/disable gateway anonymized statistics that get sent to a statistics aggregator server
#[clap(long)]
enabled_statistics: bool,
enabled_statistics: Option<bool>,
/// URL where a statistics aggregator is running. The default value is a Nym aggregator server
#[clap(long)]
+11 -8
View File
@@ -94,11 +94,11 @@ struct ApiArgs {
/// Specifies whether network monitoring is enabled on this API
#[clap(short = 'm', long)]
enable_monitor: bool,
enable_monitor: Option<bool>,
/// Specifies whether network rewarding is enabled on this API
#[clap(short = 'r', long, requires = "enable_monitor", requires = "mnemonic")]
enable_rewarding: bool,
enable_rewarding: Option<bool>,
/// Endpoint to nyxd instance from which the monitor will grab nodes to test
#[clap(long)]
@@ -132,7 +132,7 @@ struct ApiArgs {
/// Set this nym api to work in a enabled credentials that would attempt to use gateway with the bandwidth credential requirement
#[clap(long)]
enabled_credentials_mode: bool,
enabled_credentials_mode: Option<bool>,
/// Announced address where coconut clients will connect.
#[cfg(feature = "coconut")]
@@ -142,7 +142,7 @@ struct ApiArgs {
/// Flag to indicate whether coconut signer authority is enabled on this API
#[cfg(feature = "coconut")]
#[clap(long, requires = "mnemonic", requires = "announce-address")]
enable_coconut: bool,
enable_coconut: Option<bool>,
}
async fn wait_for_interrupt(mut shutdown: TaskManager) {
@@ -186,15 +186,18 @@ fn override_config(mut config: Config, args: ApiArgs) -> Config {
Config::with_min_gateway_reliability,
args.min_gateway_reliability,
)
.with_network_monitor_enabled(args.enable_monitor)
.with_rewarding_enabled(args.enable_rewarding)
.with_disabled_credentials_mode(!args.enabled_credentials_mode);
.with_optional(Config::with_network_monitor_enabled, args.enable_monitor)
.with_optional(Config::with_rewarding_enabled, args.enable_rewarding)
.with_optional(
Config::with_disabled_credentials_mode,
args.enabled_credentials_mode.map(|b| !b),
);
#[cfg(feature = "coconut")]
{
config = config
.with_optional(Config::with_announce_address, args.announce_address)
.with_coconut_signer_enabled(args.enable_coconut);
.with_optional(Config::with_coconut_signer_enabled, args.enable_coconut);
}
if args.save_config {