Skip to content

Commit

Permalink
Replace structopt dependency by clap
Browse files Browse the repository at this point in the history
  • Loading branch information
Expyron authored and calebcartwright committed Apr 7, 2022
1 parent 7d6ca7c commit 91995b6
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 119 deletions.
127 changes: 64 additions & 63 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 @@ -37,6 +37,7 @@ annotate-snippets = { version = "0.9", features = ["color"] }
anyhow = "1.0"
bytecount = "0.6"
cargo_metadata = "0.14"
clap = { version = "3.1", features = ["derive"] }
derive-new = "0.5"
diff = "0.1"
dirs = "4.0"
Expand All @@ -49,7 +50,6 @@ log = "0.4"
regex = "1.5"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
structopt = "0.3"
term = "0.7"
thiserror = "1.0"
toml = "0.5"
Expand Down
33 changes: 19 additions & 14 deletions src/cargo-fmt/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,54 +15,59 @@ use std::path::{Path, PathBuf};
use std::process::Command;
use std::str;

use structopt::StructOpt;
use clap::{CommandFactory, Parser};

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

#[derive(StructOpt, Debug)]
#[structopt(
#[derive(Parser)]
#[clap(
bin_name = "cargo fmt",
about = "This utility formats all bin and lib files of \
the current crate using rustfmt."
)]
pub struct Opts {
/// No output printed to stdout
#[structopt(short = "q", long = "quiet")]
#[clap(short = 'q', long = "quiet")]
quiet: bool,

/// Use verbose output
#[structopt(short = "v", long = "verbose")]
#[clap(short = 'v', long = "verbose")]
verbose: bool,

/// Print rustfmt version and exit
#[structopt(long = "version")]
#[clap(long = "version")]
version: bool,

/// Specify package to format
#[structopt(short = "p", long = "package", value_name = "package")]
#[clap(
short = 'p',
long = "package",
value_name = "package",
multiple_values = true
)]
packages: Vec<String>,

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

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

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

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

/// Run rustfmt in check mode
#[structopt(long = "check")]
#[clap(long = "check")]
check: bool,
}

Expand All @@ -87,7 +92,7 @@ fn execute() -> i32 {
}
});

let opts = Opts::from_iter(args);
let opts = Opts::parse_from(args);

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

fn print_usage_to_stderr(reason: &str) {
eprintln!("{}", reason);
let app = Opts::clap();
let app = Opts::command();
app.after_help("")
.write_help(&mut io::stderr())
.expect("failed to write to stderr");
Expand Down
Loading

0 comments on commit 91995b6

Please sign in to comment.