Skip to content

Commit 91995b6

Browse files
Expyroncalebcartwright
authored andcommitted
Replace structopt dependency by clap
1 parent 7d6ca7c commit 91995b6

File tree

5 files changed

+130
-119
lines changed

5 files changed

+130
-119
lines changed

Cargo.lock

+64-63
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ annotate-snippets = { version = "0.9", features = ["color"] }
3737
anyhow = "1.0"
3838
bytecount = "0.6"
3939
cargo_metadata = "0.14"
40+
clap = { version = "3.1", features = ["derive"] }
4041
derive-new = "0.5"
4142
diff = "0.1"
4243
dirs = "4.0"
@@ -49,7 +50,6 @@ log = "0.4"
4950
regex = "1.5"
5051
serde = { version = "1.0", features = ["derive"] }
5152
serde_json = "1.0"
52-
structopt = "0.3"
5353
term = "0.7"
5454
thiserror = "1.0"
5555
toml = "0.5"

src/cargo-fmt/main.rs

+19-14
Original file line numberDiff line numberDiff line change
@@ -15,54 +15,59 @@ use std::path::{Path, PathBuf};
1515
use std::process::Command;
1616
use std::str;
1717

18-
use structopt::StructOpt;
18+
use clap::{CommandFactory, Parser};
1919

2020
#[path = "test/mod.rs"]
2121
#[cfg(test)]
2222
mod cargo_fmt_tests;
2323

24-
#[derive(StructOpt, Debug)]
25-
#[structopt(
24+
#[derive(Parser)]
25+
#[clap(
2626
bin_name = "cargo fmt",
2727
about = "This utility formats all bin and lib files of \
2828
the current crate using rustfmt."
2929
)]
3030
pub struct Opts {
3131
/// No output printed to stdout
32-
#[structopt(short = "q", long = "quiet")]
32+
#[clap(short = 'q', long = "quiet")]
3333
quiet: bool,
3434

3535
/// Use verbose output
36-
#[structopt(short = "v", long = "verbose")]
36+
#[clap(short = 'v', long = "verbose")]
3737
verbose: bool,
3838

3939
/// Print rustfmt version and exit
40-
#[structopt(long = "version")]
40+
#[clap(long = "version")]
4141
version: bool,
4242

4343
/// Specify package to format
44-
#[structopt(short = "p", long = "package", value_name = "package")]
44+
#[clap(
45+
short = 'p',
46+
long = "package",
47+
value_name = "package",
48+
multiple_values = true
49+
)]
4550
packages: Vec<String>,
4651

4752
/// Specify path to Cargo.toml
48-
#[structopt(long = "manifest-path", value_name = "manifest-path")]
53+
#[clap(long = "manifest-path", value_name = "manifest-path")]
4954
manifest_path: Option<String>,
5055

5156
/// Specify message-format: short|json|human
52-
#[structopt(long = "message-format", value_name = "message-format")]
57+
#[clap(long = "message-format", value_name = "message-format")]
5358
message_format: Option<String>,
5459

5560
/// Options passed to rustfmt
5661
// 'raw = true' to make `--` explicit.
57-
#[structopt(name = "rustfmt_options", raw(true))]
62+
#[clap(name = "rustfmt_options", raw(true))]
5863
rustfmt_options: Vec<String>,
5964

6065
/// Format all packages, and also their local path-based dependencies
61-
#[structopt(long = "all")]
66+
#[clap(long = "all")]
6267
format_all: bool,
6368

6469
/// Run rustfmt in check mode
65-
#[structopt(long = "check")]
70+
#[clap(long = "check")]
6671
check: bool,
6772
}
6873

@@ -87,7 +92,7 @@ fn execute() -> i32 {
8792
}
8893
});
8994

90-
let opts = Opts::from_iter(args);
95+
let opts = Opts::parse_from(args);
9196

9297
let verbosity = match (opts.verbose, opts.quiet) {
9398
(false, false) => Verbosity::Normal,
@@ -204,7 +209,7 @@ fn convert_message_format_to_rustfmt_args(
204209

205210
fn print_usage_to_stderr(reason: &str) {
206211
eprintln!("{}", reason);
207-
let app = Opts::clap();
212+
let app = Opts::command();
208213
app.after_help("")
209214
.write_help(&mut io::stderr())
210215
.expect("failed to write to stderr");

0 commit comments

Comments
 (0)