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

Add env feature to clap and make clap parameters available as env variables #4957

Merged
merged 2 commits into from
Oct 22, 2024
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
2 changes: 1 addition & 1 deletion nym-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ bip39 = { workspace = true }
bincode.workspace = true
bloomfilter = { workspace = true }
cfg-if = { workspace = true }
clap = { workspace = true, features = ["cargo", "derive"] }
clap = { workspace = true, features = ["cargo", "derive", "env"] }
console-subscriber = { workspace = true, optional = true } # validator-api needs to be built with RUSTFLAGS="--cfg tokio_unstable"
dirs = { workspace = true }
futures = { workspace = true }
Expand Down
27 changes: 19 additions & 8 deletions nym-api/src/support/cli/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,33 @@ use anyhow::bail;
pub(crate) struct Args {
/// Id of the nym-api we want to initialise. if unspecified, a default value will be used.
/// default: "default"
#[clap(long, default_value = "default")]
#[clap(long, default_value = "default", env = "NYMAPI_ID_ARG")]
pub(crate) id: String,

/// Specifies whether network monitoring is enabled on this API
/// default: false
#[clap(short = 'm', long)]
#[clap(short = 'm', long, env = "NYMAPI_ENABLE_MONITOR_ARG")]
pub(crate) enable_monitor: bool,

/// Specifies whether network rewarding is enabled on this API
/// default: false
#[clap(short = 'r', long, requires = "enable_monitor", requires = "mnemonic")]
#[clap(
short = 'r',
long,
requires = "enable_monitor",
requires = "mnemonic",
env = "NYMAPI_ENABLE_REWARDING_ARG"
)]
pub(crate) enable_rewarding: bool,

/// Endpoint to nyxd instance used for contract information.
/// default: http://localhost:26657
#[clap(long)]
#[clap(long, env = "NYMAPI_NYXD_VALIDATOR_ARG")]
pub(crate) nyxd_validator: Option<url::Url>,

/// Mnemonic of the network monitor used for sending rewarding and zk-nyms transactions
/// default: None
#[clap(long)]
#[clap(long, env = "NYMAPI_MNEMONIC_ARG")]
pub(crate) mnemonic: Option<bip39::Mnemonic>,

/// Flag to indicate whether credential signer authority is enabled on this API
Expand All @@ -38,18 +44,23 @@ pub(crate) struct Args {
long,
requires = "mnemonic",
requires = "announce_address",
alias = "enable_coconut"
alias = "enable_coconut",
env = "NYMAPI_ENABLE_ZK_NYM_ARG"
)]
pub(crate) enable_zk_nym: bool,

/// Announced address that is going to be put in the DKG contract where zk-nym clients will connect
/// to obtain their credentials
/// default: None
#[clap(long)]
#[clap(long, env = "NYMAPI_ANNOUNCE_ADDRESS_NYM_ARG")]
pub(crate) announce_address: Option<url::Url>,

/// Set this nym api to work in a enabled credentials that would attempt to use gateway with the bandwidth credential requirement
#[clap(long, requires = "enable_monitor")]
#[clap(
long,
requires = "enable_monitor",
env = "NYMAPI_MONITOR_CREDENTIALS_MODE_ARG"
)]
pub(crate) monitor_credentials_mode: bool,
// #[clap(short, long, default_value_t = OutputFormat::default())]
// output: OutputFormat,
Expand Down
4 changes: 2 additions & 2 deletions nym-api/src/support/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ fn pretty_build_info_static() -> &'static str {
#[clap(author = "Nymtech", version, long_version = pretty_build_info_static(), about)]
pub(crate) struct Cli {
/// Path pointing to an env file that configures the Nym API.
#[clap(short, long)]
#[clap(short, long, env = "NYMAPI_CONFIG_ENV_FILE_ARG")]
pub(crate) config_env_file: Option<std::path::PathBuf>,

/// A no-op flag included for consistency with other binaries (and compatibility with nymvisor, oops)
#[clap(long)]
#[clap(long, env = "NYMAPI_NO_BANNER_ARG")]
pub(crate) no_banner: bool,

#[clap(subcommand)]
Expand Down
23 changes: 15 additions & 8 deletions nym-api/src/support/cli/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,33 @@ use cfg_if::cfg_if;
pub(crate) struct Args {
/// Id of the nym-api we want to run.if unspecified, a default value will be used.
/// default: "default"
#[clap(long, default_value = "default")]
#[clap(long, default_value = "default", env = "NYMAPI_ID_ARG")]
pub(crate) id: String,

/// Specifies whether network monitoring is enabled on this API
/// default: None - config value will be used instead
#[clap(short = 'm', long)]
#[clap(short = 'm', long, env = "NYMAPI_ENABLE_MONITOR_ARG")]
pub(crate) enable_monitor: Option<bool>,

/// Specifies whether network rewarding is enabled on this API
/// default: None - config value will be used instead
#[clap(short = 'r', long, requires = "enable_monitor", requires = "mnemonic")]
#[clap(
short = 'r',
long,
requires = "enable_monitor",
requires = "mnemonic",
env = "NYMAPI_ENABLE_REWARDING_ARG"
)]
pub(crate) enable_rewarding: Option<bool>,

/// Endpoint to nyxd instance used for contract information.
/// default: None - config value will be used instead
#[clap(long)]
#[clap(long, env = "NYMAPI_NYXD_VALIDATOR_ARG")]
pub(crate) nyxd_validator: Option<url::Url>,

/// Mnemonic of the network monitor used for sending rewarding and zk-nyms transactions
/// default: None - config value will be used instead
#[clap(long)]
#[clap(long, env = "NYMAPI_MNEMONIC_ARG")]
pub(crate) mnemonic: Option<bip39::Mnemonic>,

/// Flag to indicate whether coconut signer authority is enabled on this API
Expand All @@ -38,19 +44,20 @@ pub(crate) struct Args {
long,
requires = "mnemonic",
requires = "announce_address",
alias = "enable_coconut"
alias = "enable_coconut",
env = "NYMAPI_ENABLE_ZK_NYM_ARG"
)]
pub(crate) enable_zk_nym: Option<bool>,

/// Announced address that is going to be put in the DKG contract where zk-nym clients will connect
/// to obtain their credentials
/// default: None - config value will be used instead
#[clap(long)]
#[clap(long, env = "NYMAPI_ANNOUNCE_ADDRESS_ARG")]
pub(crate) announce_address: Option<url::Url>,

/// Set this nym api to work in a enabled credentials that would attempt to use gateway with the bandwidth credential requirement
/// default: None - config value will be used instead
#[clap(long)]
#[clap(long, env = "NYMAPI_MONITOR_CREDENTIALS_MODE_ARG")]
pub(crate) monitor_credentials_mode: Option<bool>,
}

Expand Down
Loading