Skip to content

Commit 9e3478d

Browse files
committed
rust: upgrade clap to 3.1
Let's stay modern.
1 parent 29855de commit 9e3478d

File tree

4 files changed

+63
-59
lines changed

4 files changed

+63
-59
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ edition = "2018"
77
[dependencies]
88
anyhow = "1"
99
bytes = "1.1"
10-
clap = "2"
10+
clap = "3"
1111
duct = "0"
1212
flate2 = "1"
1313
futures = "0"

src/github.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ async fn fetch_artifact(client: &Octocrab, artifact: WorkflowListArtifact) -> Re
2121
Ok(res.bytes().await?)
2222
}
2323

24-
pub async fn command_fetch_release_distributions(args: &ArgMatches<'_>) -> Result<()> {
24+
pub async fn command_fetch_release_distributions(args: &ArgMatches) -> Result<()> {
2525
let dest_dir = PathBuf::from(args.value_of("dest").expect("dest directory should be set"));
2626
let org = args
2727
.value_of("organization")
@@ -162,7 +162,7 @@ pub async fn command_fetch_release_distributions(args: &ArgMatches<'_>) -> Resul
162162
Ok(())
163163
}
164164

165-
pub async fn command_upload_release_distributions(args: &ArgMatches<'_>) -> Result<()> {
165+
pub async fn command_upload_release_distributions(args: &ArgMatches) -> Result<()> {
166166
let dist_dir = PathBuf::from(args.value_of("dist").expect("dist should be specified"));
167167
let datetime = args
168168
.value_of("datetime")

src/main.rs

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ mod validation;
1010

1111
use {
1212
anyhow::{anyhow, Context, Result},
13-
clap::{App, AppSettings, Arg, SubCommand},
13+
clap::{Arg, Command},
1414
std::{io::Read, path::Path},
1515
};
1616

@@ -25,43 +25,43 @@ pub fn open_distribution_archive(path: &Path) -> Result<tar::Archive<impl Read>>
2525
}
2626

2727
fn main_impl() -> Result<()> {
28-
let app = App::new("Python Build")
29-
.setting(AppSettings::ArgRequiredElseHelp)
28+
let app = Command::new("Python Build")
29+
.arg_required_else_help(true)
3030
.version("0.1")
3131
.author("Gregory Szorc <[email protected]>")
3232
.about("Perform tasks related to building Python distributions");
3333
let app = app.subcommand(
34-
SubCommand::with_name("fetch-release-distributions")
34+
Command::new("fetch-release-distributions")
3535
.about("Fetch builds from GitHub Actions that are release artifacts")
3636
.arg(
37-
Arg::with_name("token")
37+
Arg::new("token")
3838
.long("--token")
3939
.required(true)
4040
.takes_value(true)
4141
.help("GitHub API token"),
4242
)
4343
.arg(
44-
Arg::with_name("commit")
44+
Arg::new("commit")
4545
.long("--commit")
4646
.takes_value(true)
4747
.help("Git commit whose artifacts to fetch"),
4848
)
4949
.arg(
50-
Arg::with_name("dest")
50+
Arg::new("dest")
5151
.long("dest")
5252
.required(true)
5353
.takes_value(true)
5454
.help("Destination directory"),
5555
)
5656
.arg(
57-
Arg::with_name("organization")
57+
Arg::new("organization")
5858
.long("--org")
5959
.takes_value(true)
6060
.default_value("indygreg")
6161
.help("GitHub organization"),
6262
)
6363
.arg(
64-
Arg::with_name("repo")
64+
Arg::new("repo")
6565
.long("--repo")
6666
.takes_value(true)
6767
.default_value("python-build-standalone")
@@ -70,50 +70,50 @@ fn main_impl() -> Result<()> {
7070
);
7171

7272
let app = app.subcommand(
73-
SubCommand::with_name("upload-release-distributions")
73+
Command::new("upload-release-distributions")
7474
.about("Upload release distributions to a GitHub release")
7575
.arg(
76-
Arg::with_name("token")
76+
Arg::new("token")
7777
.long("--token")
7878
.required(true)
7979
.takes_value(true)
8080
.help("GitHub API token"),
8181
)
8282
.arg(
83-
Arg::with_name("dist")
83+
Arg::new("dist")
8484
.long("--dist")
8585
.required(true)
8686
.takes_value(true)
8787
.help("Directory with release artifacts"),
8888
)
8989
.arg(
90-
Arg::with_name("datetime")
90+
Arg::new("datetime")
9191
.long("--datetime")
9292
.required(true)
9393
.takes_value(true)
9494
.help("Date/time tag associated with builds"),
9595
)
9696
.arg(
97-
Arg::with_name("tag")
97+
Arg::new("tag")
9898
.long("--tag")
9999
.required(true)
100100
.takes_value(true)
101101
.help("Release tag"),
102102
)
103103
.arg(
104-
Arg::with_name("ignore_missing")
104+
Arg::new("ignore_missing")
105105
.long("--ignore-missing")
106106
.help("Continue even if there are missing artifacts"),
107107
)
108108
.arg(
109-
Arg::with_name("organization")
109+
Arg::new("organization")
110110
.long("--org")
111111
.takes_value(true)
112112
.default_value("indygreg")
113113
.help("GitHub organization"),
114114
)
115115
.arg(
116-
Arg::with_name("repo")
116+
Arg::new("repo")
117117
.long("--repo")
118118
.takes_value(true)
119119
.default_value("python-build-standalone")
@@ -122,39 +122,40 @@ fn main_impl() -> Result<()> {
122122
);
123123

124124
let app = app.subcommand(
125-
SubCommand::with_name("validate-distribution")
125+
Command::new("validate-distribution")
126126
.about("Ensure a distribution archive conforms to standards")
127127
.arg(
128-
Arg::with_name("run")
128+
Arg::new("run")
129129
.long("--run")
130130
.help("Run the interpreter to verify behavior"),
131131
)
132132
.arg(
133-
Arg::with_name("path")
133+
Arg::new("path")
134134
.help("Path to tar.zst file to validate")
135-
.multiple(true)
135+
.multiple_occurrences(true)
136+
.multiple_values(true)
136137
.required(true),
137138
),
138139
);
139140

140141
let matches = app.get_matches();
141142

142143
match matches.subcommand() {
143-
("fetch-release-distributions", Some(args)) => {
144+
Some(("fetch-release-distributions", args)) => {
144145
tokio::runtime::Builder::new_current_thread()
145146
.enable_all()
146147
.build()
147148
.unwrap()
148149
.block_on(crate::github::command_fetch_release_distributions(args))
149150
}
150-
("upload-release-distributions", Some(args)) => {
151+
Some(("upload-release-distributions", args)) => {
151152
tokio::runtime::Builder::new_current_thread()
152153
.enable_all()
153154
.build()
154155
.unwrap()
155156
.block_on(crate::github::command_upload_release_distributions(args))
156157
}
157-
("validate-distribution", Some(args)) => {
158+
Some(("validate-distribution", args)) => {
158159
crate::validation::command_validate_distribution(args)
159160
}
160161
_ => Err(anyhow!("invalid sub-command")),

0 commit comments

Comments
 (0)