Skip to content

Commit 1b1508f

Browse files
Use clap environment variable
1 parent 5bbfea1 commit 1b1508f

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ tokio = { version = "1.43", default-features = false, features = [
5151
"rt-multi-thread",
5252
"macros",
5353
] }
54-
clap = { version = "4.5", features = ["derive"] }
54+
clap = { version = "4.5", features = ["derive", "env"] }
5555
clap_complete = "4.5"
5656
parking_lot = "0.12"
5757
serde_json = "1.0"

src/cli.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ use std::path::PathBuf;
1111

1212
#[derive(Clone, Debug, Parser)]
1313
#[clap(author, version, about)]
14-
#[clap(arg_required_else_help = true)]
1514
pub struct Ferium {
1615
#[clap(subcommand)]
1716
pub subcommand: SubCommands,
@@ -23,12 +22,10 @@ pub struct Ferium {
2322
#[clap(long, short = 'p', default_value_t = DEFAULT_PARALLEL_NETWORK)]
2423
pub parallel_network: usize,
2524
/// Set a GitHub personal access token for increasing the GitHub API rate limit.
26-
/// You can also use the environment variable `GITHUB_TOKEN`.
27-
#[clap(long, visible_alias = "gh")]
25+
#[clap(long, visible_alias = "gh", env = "GITHUB_TOKEN")]
2826
pub github_token: Option<String>,
2927
/// Set a custom Curseforge API key.
30-
/// You can also use the environment variable `CURSEFORGE_API_KEY`.
31-
#[clap(long, visible_alias = "cf")]
28+
#[clap(long, visible_alias = "cf", env = "CURSEFORGE_API_KEY")]
3229
pub curseforge_api_key: Option<String>,
3330
/// Set the file to read the config from.
3431
/// This does not change the `cache` and `tmp` directories.

src/main.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
clippy::complexity,
1010
clippy::create_dir,
1111
clippy::unwrap_used,
12-
clippy::expect_used, // use anyhow::Context instead
1312
clippy::correctness,
14-
clippy::allow_attributes,
13+
clippy::allow_attributes
1514
)]
15+
#![deny(clippy::expect_used, reason = "Use anyhow::Context instead")]
1616
#![warn(clippy::dbg_macro)]
1717
#![expect(clippy::multiple_crate_versions, clippy::too_many_lines)]
1818

@@ -140,10 +140,14 @@ async fn actual_main(mut cli_app: Ferium) -> Result<()> {
140140
}
141141

142142
if let Some(token) = cli_app.github_token {
143-
set_var("GITHUB_TOKEN", token);
143+
if !token.is_empty() {
144+
set_var("GITHUB_TOKEN", token);
145+
}
144146
}
145147
if let Some(key) = cli_app.curseforge_api_key {
146-
set_var("CURSEFORGE_API_KEY", key);
148+
if !key.is_empty() {
149+
set_var("CURSEFORGE_API_KEY", key);
150+
}
147151
}
148152
let _ = SEMAPHORE.set(tokio::sync::Semaphore::new(cli_app.parallel_network));
149153

0 commit comments

Comments
 (0)