Skip to content

Commit

Permalink
Remove deprecated options
Browse files Browse the repository at this point in the history
  • Loading branch information
smoelius committed Feb 9, 2024
1 parent 83e5eb0 commit 7fd2c4d
Show file tree
Hide file tree
Showing 11 changed files with 405 additions and 601 deletions.
1 change: 1 addition & 0 deletions cargo-dylint/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,4 @@ dylint_internal = { version = "=2.6.1", path = "../internal", features = [
default = ["cargo-lib"]
cargo-lib = ["dylint/__cargo_lib"]
cargo-cli = ["dylint/__cargo_cli"]
__clap_headings = []
273 changes: 106 additions & 167 deletions cargo-dylint/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,36 +41,15 @@ METADATA EXAMPLE:
]
"#,
)]
// smoelius: Please keep the field `name_opts` first, and the fields `subcmd`, `names`, and `args`
// last. Please keep all other fields sorted.
// smoelius: Please keep the last four fields `args`, `operation`, `lib_sel`, and `output`, in that
// order. Please keep all other fields sorted.
struct Dylint {
#[clap(flatten)]
name_opts: NameOpts,

#[clap(long, hide = true)]
allow_downgrade: bool,

#[clap(long, hide = true)]
bisect: bool,

#[clap(long, help = "Automatically apply lint suggestions")]
fix: bool,

#[clap(long, hide = true)]
force: bool,

#[clap(long, hide = true)]
isolate: bool,

#[clap(long, help = "Continue if `cargo check` fails")]
keep_going: bool,

#[clap(long, hide = true)]
list: bool,

#[clap(long = "new", hide = true)]
new_path: Option<String>,

#[clap(long, help = "Do not check other packages within the workspace")]
no_deps: bool,

Expand All @@ -84,42 +63,24 @@ struct Dylint {
)]
packages: Vec<String>,

#[clap(long, value_name = "path", help = "Path to pipe stderr to")]
pipe_stderr: Option<String>,

#[clap(long, value_name = "path", help = "Path to pipe stdout to")]
pipe_stdout: Option<String>,

#[clap(
global = true,
short,
long,
help = "Do not show warnings or progress running commands besides `cargo check` and \
`cargo fix`"
)]
quiet: bool,

#[clap(long, hide = true)]
rust_version: Option<String>,

#[clap(long = "upgrade", hide = true)]
upgrade_path: Option<String>,

#[clap(long, help = "Check all packages in the workspace")]
workspace: bool,

#[clap(last = true, help = "Arguments for `cargo check`")]
args: Vec<String>,

#[clap(subcommand)]
subcmd: Option<DylintSubcommand>,
operation: Option<Operation>,

#[clap(hide = true)]
names: Vec<String>,
#[clap(flatten)]
lib_sel: LibrarySelection,

#[clap(last = true, help = "Arguments for `cargo check`")]
args: Vec<String>,
#[clap(flatten)]
output: OutputOptions,
}

#[derive(Debug, Parser)]
enum DylintSubcommand {
enum Operation {
#[clap(
about = "List libraries or lints",
long_about = "If no libraries are named, list the name, toolchain, and location of all \
Expand All @@ -132,7 +93,7 @@ Combine with `--all` to list all lints in all discovered libraries."
)]
List {
#[clap(flatten)]
name_opts: NameOpts,
lib_sel: LibrarySelection,
},

#[clap(
Expand All @@ -156,13 +117,6 @@ Combine with `--all` to list all lints in all discovered libraries."
#[clap(long, hide = true)]
allow_downgrade: bool,

#[clap(
long,
help = "Unix only/experimental: Update dependencies and search for the most recent \
applicable toolchain"
)]
bisect: bool,

#[clap(
long,
value_name = "version",
Expand All @@ -176,7 +130,8 @@ Combine with `--all` to list all lints in all discovered libraries."
}

#[derive(Debug, Parser)]
struct NameOpts {
#[cfg_attr(feature = "__clap_headings", clap(next_help_heading = Some("Library Selection")))]
struct LibrarySelection {
#[clap(long, help = "Load all discovered libraries")]
all: bool,

Expand Down Expand Up @@ -261,130 +216,81 @@ struct NameOpts {
tag: Option<String>,
}

#[allow(deprecated)]
#[derive(Debug, Parser)]
#[cfg_attr(feature = "__clap_headings", clap(next_help_heading = Some("Output Options")))]
struct OutputOptions {
#[clap(long, value_name = "path", help = "Path to pipe stderr to")]
pipe_stderr: Option<String>,

#[clap(long, value_name = "path", help = "Path to pipe stdout to")]
pipe_stdout: Option<String>,

#[clap(
global = true,
short,
long,
help = "Do not show warnings or progress running commands besides `cargo check` and \
`cargo fix`"
)]
quiet: bool,
}

impl From<Dylint> for dylint::opts::Dylint {
fn from(opts: Dylint) -> Self {
let opts = process_deprecated_options(opts);
let Dylint {
name_opts:
NameOpts {
all,
branch,
git,
lib_paths,
libs,
manifest_path,
no_build,
no_metadata,
paths,
pattern,
rev,
tag,
},
allow_downgrade,
bisect,
fix,
force,
isolate,
keep_going,
list,
new_path,
no_deps,
packages,
pipe_stderr,
pipe_stdout,
quiet,
rust_version,
upgrade_path,
workspace,
subcmd: _,
names,
args,
operation,
mut lib_sel,
output:
OutputOptions {
pipe_stderr,
pipe_stdout,
quiet,
},
} = opts;
Self {
all,
allow_downgrade,
bisect,
branch,
fix,
force,
git,
isolate,
keep_going,
lib_paths,
libs,
list,
manifest_path,
new_path,
no_build,
no_deps,
no_metadata,
packages,
paths,
pattern,
pipe_stderr,
pipe_stdout,
quiet,
rev,
rust_version,
tag,
upgrade_path,
workspace,
names,
args,
}
}
}

fn process_deprecated_options(mut opts: Dylint) -> Dylint {
if opts.list {
dylint::__warn(
&dylint::opts::Dylint::default(),
"`--list` is deprecated. Use subcommand `list`.",
);
}
if opts.new_path.is_some() {
dylint::__warn(
&dylint::opts::Dylint::default(),
"`--new` is deprecated. Use subcommand `new`.",
);
}
if opts.upgrade_path.is_some() {
dylint::__warn(
&dylint::opts::Dylint::default(),
"`--upgrade` is deprecated. Use subcommand `upgrade`.",
);
}
if !opts.names.is_empty() {
dylint::__warn(
&dylint::opts::Dylint::default(),
"Referring to libraries by bare name is deprecated. Use `--lib` or `--lib-path`.",
);
}
if let Some(subcmd) = opts.subcmd.take() {
match subcmd {
DylintSubcommand::List { name_opts } => {
opts.name_opts.absorb(name_opts);
opts.list = true;
let operation = match operation {
None => dylint::opts::Operation::Check({
dylint::opts::Check {
lib_sel: lib_sel.into(),
fix,
keep_going,
no_deps,
packages,
workspace,
args,
}
}),
Some(Operation::List { lib_sel: other }) => {
lib_sel.absorb(other);
dylint::opts::Operation::List(dylint::opts::List {
lib_sel: lib_sel.into(),
})
}
DylintSubcommand::New { isolate, path } => {
opts.isolate |= isolate;
opts.new_path = Some(path);
Some(Operation::New { isolate, path }) => {
dylint::opts::Operation::New(dylint::opts::New { isolate, path })
}
DylintSubcommand::Upgrade {
Some(Operation::Upgrade {
allow_downgrade,
bisect,
rust_version,
path,
} => {
opts.allow_downgrade |= allow_downgrade;
opts.bisect |= bisect;
opts.rust_version = rust_version;
opts.upgrade_path = Some(path);
}
}) => dylint::opts::Operation::Upgrade(dylint::opts::Upgrade {
allow_downgrade,
rust_version,
path,
}),
};
Self {
pipe_stderr,
pipe_stdout,
quiet,
operation,
}
}
opts
}

macro_rules! option_absorb {
Expand All @@ -400,7 +306,7 @@ macro_rules! option_absorb {
};
}

impl NameOpts {
impl LibrarySelection {
pub fn absorb(&mut self, other: Self) {
let Self {
all,
Expand Down Expand Up @@ -431,6 +337,39 @@ impl NameOpts {
}
}

impl From<LibrarySelection> for dylint::opts::LibrarySelection {
fn from(lib_sel: LibrarySelection) -> Self {
let LibrarySelection {
all,
branch,
git,
lib_paths,
libs,
manifest_path,
no_build,
no_metadata,
paths,
pattern,
rev,
tag,
} = lib_sel;
Self {
all,
branch,
git,
lib_paths,
libs,
manifest_path,
no_build,
no_metadata,
paths,
pattern,
rev,
tag,
}
}
}

fn main() -> dylint::ColorizedResult<()> {
env_logger::try_init().unwrap_or_else(|error| {
dylint::__warn(
Expand Down
2 changes: 1 addition & 1 deletion cargo-dylint/tests/fix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ fn fix() {
std::process::Command::cargo_bin("cargo-dylint")
.unwrap()
.current_dir(&tempdir)
.args(["dylint", "--fix", LIB_NAME, "--", "--allow-dirty"])
.args(["dylint", "--lib", LIB_NAME, "--fix", "--", "--allow-dirty"])
.assert()
.success();

Expand Down
Loading

0 comments on commit 7fd2c4d

Please sign in to comment.