Skip to content

Commit

Permalink
Deprecate --force
Browse files Browse the repository at this point in the history
  • Loading branch information
smoelius committed May 28, 2022
1 parent d41351a commit 3cd5ef0
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 10 deletions.
5 changes: 5 additions & 0 deletions cargo-dylint/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ pub struct Dylint {
#[clap(long, help = "Automatically apply lint suggestions")]
pub fix: bool,

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

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

Expand Down Expand Up @@ -163,6 +166,7 @@ impl From<Dylint> for dylint::Dylint {
allow_downgrade,
bisect,
fix,
force,
isolate,
keep_going,
libs,
Expand All @@ -185,6 +189,7 @@ impl From<Dylint> for dylint::Dylint {
allow_downgrade,
bisect,
fix,
force,
isolate,
keep_going,
libs,
Expand Down
35 changes: 25 additions & 10 deletions dylint/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,13 @@ lazy_static! {
}

#[allow(clippy::struct_excessive_bools)]
#[derive(Debug, Default)]
#[derive(Clone, Debug, Default)]
pub struct Dylint {
pub all: bool,
pub allow_downgrade: bool,
pub bisect: bool,
pub fix: bool,
pub force: bool,
pub isolate: bool,
pub keep_going: bool,
pub libs: Vec<String>,
Expand All @@ -68,22 +69,36 @@ pub struct Dylint {
}

pub fn run(opts: &Dylint) -> Result<()> {
let opts = {
if opts.force {
warn(
opts,
"`--force` is deprecated and its meaning may change in the future. Use \
`--allow-downgrade`.",
);
}
Dylint {
allow_downgrade: opts.allow_downgrade || opts.force,
..opts.clone()
}
};

if opts.allow_downgrade && opts.upgrade_path.is_none() {
bail!("`--allow-downgrade` can be used only with `--upgrade`");
}

if opts.bisect {
#[cfg(not(unix))]
bail!("`--bisect` is supported only on Unix platforms");

#[cfg(unix)]
warn(opts, "`--bisect` is experimental");
warn(&opts, "`--bisect` is experimental");
}

if opts.bisect && opts.upgrade_path.is_none() {
bail!("`--bisect` can be used only with `--upgrade`");
}

if opts.allow_downgrade && opts.upgrade_path.is_none() {
bail!("`--allow-downgrade` can be used only with `--upgrade`");
}

if opts.isolate && opts.new_path.is_none() {
bail!("`--isolate` can be used only with `--new`");
}
Expand All @@ -94,17 +109,17 @@ pub fn run(opts: &Dylint) -> Result<()> {

#[cfg(feature = "package_options")]
if let Some(path) = &opts.new_path {
return package_options::new_package(opts, Path::new(path));
return package_options::new_package(&opts, Path::new(path));
}

#[cfg(feature = "package_options")]
if let Some(path) = &opts.upgrade_path {
return package_options::upgrade_package(opts, Path::new(path));
return package_options::upgrade_package(&opts, Path::new(path));
}

let name_toolchain_map = NameToolchainMap::new(opts);
let name_toolchain_map = NameToolchainMap::new(&opts);

run_with_name_toolchain_map(opts, &name_toolchain_map)
run_with_name_toolchain_map(&opts, &name_toolchain_map)
}

fn run_with_name_toolchain_map(opts: &Dylint, name_toolchain_map: &NameToolchainMap) -> Result<()> {
Expand Down

0 comments on commit 3cd5ef0

Please sign in to comment.