Skip to content

Commit

Permalink
[#136] Upgrade clap to 4.0 (#137)
Browse files Browse the repository at this point in the history
Resolves #136

This PR upgrades the `clap` dependency to `4.0`.

I can also upgrade the other dependencies in the same PR itself, since
they only involve modifications to the `Cargo.toml` and `Cargo.lock`
files, `clippy` lints and tests pass without any code modifications.


### Additional tasks

- [ ] Documentation for changes provided/changed
- [ ] Tests added
- [ ] Updated CHANGELOG.md

---

PS: I'm unsure if this requires a changelog entry, I can add one if
required.
  • Loading branch information
SanchithHegde authored Oct 14, 2022
1 parent 4796cf0 commit 5d1a6b6
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 54 deletions.
42 changes: 6 additions & 36 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ name = "tool"
path = "src/main.rs"

[dependencies]
clap = { version = "3.2.17", features = ["derive"] }
clap = { version = "4.0.15", features = ["derive"] }
serde = { version = "1.0", features = ["derive"] }
ureq = { version = "2.5.0", features = ["json"] }
zip = { version = "0.6.2", default-features = false, features = ["deflate"] }
Expand Down
10 changes: 5 additions & 5 deletions src/config/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ use std::path::PathBuf;
use clap::{Parser, Subcommand};

#[derive(Parser, Debug)]
#[clap(author="Dmitrii Kovanikov <[email protected]>", version, about="A CLI tool to manage other CLI tools", long_about = None)]
#[command(author="Dmitrii Kovanikov <[email protected]>", version, about="A CLI tool to manage other CLI tools", long_about = None)]
pub struct Cli {
/// Sets a path to a configuration file (default: $HOME/.tool.toml)
#[clap(short, long, value_name = "FILE")]
#[arg(short, long, value_name = "FILE")]
pub config: Option<PathBuf>,

#[clap(short, long, value_name = "uri")]
#[arg(short, long, value_name = "uri")]
pub proxy: Option<String>,

#[clap(subcommand)]
#[command(subcommand)]
pub command: Command,
}

Expand All @@ -24,7 +24,7 @@ pub enum Command {
/// Print a default .tool.toml configuration to std out
DefaultConfig {
/// Print the default config file location instead
#[clap(long)]
#[arg(long)]
path: bool,
},

Expand Down
18 changes: 6 additions & 12 deletions src/config/toml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,8 @@ fn decode_config(toml: Value, proxy: Option<String>) -> Result<Config, DecodeErr
},
)?;

let proxy: Option<String> = proxy.or_else(|| match toml.get("proxy") {
Some(p) => Some(p.as_str().unwrap_or("").into()),
None => None,
});
let proxy: Option<String> =
proxy.or_else(|| toml.get("proxy").map(|p| p.as_str().unwrap_or("").into()));

let mut tools = BTreeMap::new();

Expand Down Expand Up @@ -253,14 +251,10 @@ mod tests {
#[test]
fn test_parse_file_error() {
let test_config_path = PathBuf::from("src/main.rs");
match parse_file(&test_config_path, None) {
Ok(_) => {
assert!(false, "Unexpected succces")
}
Err(_) => {
assert!(true, "Exepected a parsing error")
}
};
assert!(
parse_file(&test_config_path, None).is_err(),
"Expected a parsing error, parsing succeeded instead"
);
}

#[test]
Expand Down

0 comments on commit 5d1a6b6

Please sign in to comment.