Skip to content

Commit de238f7

Browse files
authored
chore: migrate to clap v4 (#54)
1 parent 691d859 commit de238f7

File tree

8 files changed

+41
-34
lines changed

8 files changed

+41
-34
lines changed

Cargo.lock

Lines changed: 17 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

curlz/Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ include = ["src/**/*", "LICENSE", "*.md"]
1010
[dependencies]
1111
env_logger = "0.10"
1212
log = "0.4"
13-
clap = { version = "3.2", features = ["derive", "std", "cargo"], default-features = false }
14-
clap-verbosity-flag = "1.0"
13+
clap = { version = "4.1", features = ["derive", "std", "cargo", "usage", "help"] }
14+
#clap_complete = "4.1"
15+
clap-verbosity-flag = "2.0"
1516
serde = { version = "1.0", features = ["derive"] }
1617
serde_yaml = "0.9"
1718
dotenvy = { version = "0.15" }

curlz/src/curlz/cli/execute.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@ use clap_verbosity_flag::{InfoLevel, Verbosity};
55
use env_logger::Target;
66

77
#[derive(Clone, Debug, Parser)]
8-
#[clap(author, version, about, long_about = None, arg_required_else_help(true))]
9-
#[clap(propagate_version = true)]
10-
#[clap(name = "curlz")]
8+
#[command(author, version, about, long_about = None )]
9+
#[clap(subcommand_required = true, arg_required_else_help = true)]
10+
#[command(propagate_version = true)]
11+
#[command(name = "curlz")]
1112
pub struct Cli {
12-
#[clap(flatten)]
13+
#[command(flatten)]
1314
verbose: Verbosity<InfoLevel>,
14-
#[clap(subcommand)]
15+
#[command(subcommand)]
1516
pub command: SubCommands,
1617
}
1718

curlz/src/curlz/cli/sub_commands/bookmark.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use clap::{Args, Subcommand};
22

33
#[derive(Clone, Debug, Args)]
4-
#[clap(arg_required_else_help(true))]
5-
#[clap(args_conflicts_with_subcommands = true)]
4+
#[command(arg_required_else_help = true)]
5+
#[command(args_conflicts_with_subcommands = true)]
66
pub struct BookmarkCli {
77
#[clap(subcommand)]
88
pub command: BookmarkCommands,

curlz/src/curlz/cli/sub_commands/http_file.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ use clap::Parser;
88
use std::path::PathBuf;
99

1010
#[derive(Clone, Debug, Parser)]
11-
#[clap(author, version, about, long_about = None, arg_required_else_help(true))]
11+
#[clap(author, version, about, long_about = None)]
12+
#[command(arg_required_else_help = true)]
1213
pub struct HttpFileCli {
1314
/// Provide an `.env` or a yaml containing template variables
1415
#[clap(long = "env-file", value_parser, default_value = ".env")]

curlz/src/curlz/cli/sub_commands/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ pub use http_file::*;
1313

1414
#[derive(Clone, Debug, Subcommand)]
1515
pub enum SubCommands {
16-
#[clap(alias("r"))]
16+
#[command(alias("r"))]
1717
Request(RequestCli),
18-
#[clap(alias("b"))]
18+
#[command(alias("b"))]
1919
/// similar to git remote, we want to support `list`, `add`, `rename`, `remove` and `show`
2020
Bookmark(BookmarkCli),
2121
#[cfg(feature = "x-http-lang")]

curlz/src/curlz/cli/sub_commands/request.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ use std::path::PathBuf;
2121
use std::str::FromStr;
2222

2323
#[derive(Clone, Debug, Parser)]
24-
#[clap(author, version, about, long_about = None, arg_required_else_help(true))]
24+
#[command(author, version, about, long_about = None)]
25+
#[clap(arg_required_else_help = true)]
2526
pub struct RequestCli {
2627
#[clap(flatten)]
2728
pub verbose: Verbosity<InfoLevel>,
@@ -78,7 +79,7 @@ pub struct RequestCli {
7879
#[clap(value_parser)]
7980
pub bookmark_or_url: Option<String>,
8081

81-
#[clap(value_parser, last = true, multiple = true)]
82+
#[clap(value_parser, last = true)]
8283
pub raw: Vec<String>,
8384
}
8485

curlz/tests/basics.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ mod testlib;
88

99
#[test]
1010
fn should_show_usage_when_no_args_passed() {
11-
binary()
12-
.assert()
13-
.failure()
14-
.stderr(predicate::str::contains("USAGE:"));
11+
#[cfg(windows)]
12+
let pattern = predicate::str::contains("Usage: curlz.exe [OPTIONS] <COMMAND>");
13+
#[cfg(not(windows))]
14+
let pattern = predicate::str::contains("Usage: curlz [OPTIONS] <COMMAND>");
15+
16+
binary().assert().failure().stderr(pattern);
1517
}
1618

1719
#[tokio::test]

0 commit comments

Comments
 (0)