Skip to content

Commit

Permalink
--path -> --lib-path
Browse files Browse the repository at this point in the history
  • Loading branch information
smoelius committed Feb 4, 2024
1 parent b72fce7 commit e52da02
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 13 deletions.
20 changes: 15 additions & 5 deletions cargo-dylint/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,15 @@ struct NameOpts {
#[clap(long, help = "Load all discovered libraries")]
all: bool,

#[clap(
action = ArgAction::Append,
number_of_values = 1,
long = "lib-path",
value_name = "path",
help = "Library path to load lints from"
)]
lib_paths: Vec<String>,

#[clap(
action = ArgAction::Append,
number_of_values = 1,
Expand Down Expand Up @@ -210,8 +219,7 @@ struct NameOpts {
action = ArgAction::Append,
number_of_values = 1,
long = "path",
value_name = "path",
help = "Library path to load lints from"
hide = true,
)]
paths: Vec<String>,
}
Expand All @@ -225,10 +233,11 @@ impl From<Dylint> for dylint::Dylint {
NameOpts {
all,
libs,
lib_paths,
manifest_path,
no_build,
no_metadata,
paths,
paths: _,
},
allow_downgrade,
bisect,
Expand Down Expand Up @@ -258,6 +267,7 @@ impl From<Dylint> for dylint::Dylint {
force,
isolate,
keep_going,
lib_paths,
libs,
list,
manifest_path,
Expand All @@ -266,7 +276,7 @@ impl From<Dylint> for dylint::Dylint {
no_deps,
no_metadata,
packages,
paths,
// paths,
pipe_stderr,
pipe_stdout,
quiet,
Expand Down Expand Up @@ -301,7 +311,7 @@ fn process_deprecated_options(mut opts: Dylint) -> Dylint {
if !opts.names.is_empty() {
dylint::__warn(
&dylint::Dylint::default(),
"Referring to libraries by bare name is deprecated. Use `--lib` or `--path`.",
"Referring to libraries by bare name is deprecated. Use `--lib` or `--lib-path`.",
);
}
if let Some(subcmd) = opts.subcmd.take() {
Expand Down
2 changes: 1 addition & 1 deletion docs/how_dylint_works.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ It is considered an error if a name used on the command line resolves to multipl

If `--lib name` is used, then `name` is is treated only as a library name, and not as a path.

If `--path name` is used, then `name` is is treated only as a path, and not as a library name.
If `--lib-path name` is used, then `name` is is treated only as a path, and not as a library name.

If `--all` is used, Dylint runs all lints in all libraries discovered via 1 and 2 above.

Expand Down
17 changes: 10 additions & 7 deletions dylint/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ pub struct Dylint {

pub keep_going: bool,

pub lib_paths: Vec<String>,

pub libs: Vec<String>,

#[deprecated]
Expand All @@ -91,7 +93,8 @@ pub struct Dylint {

pub packages: Vec<String>,

pub paths: Vec<String>,
// smoelius: Temporarily removed to ensure all uses are gone.
// pub paths: Vec<String>,

pub pipe_stderr: Option<String>,

Expand Down Expand Up @@ -176,7 +179,7 @@ pub fn run(opts: &Dylint) -> Result<()> {
}

fn run_with_name_toolchain_map(opts: &Dylint, name_toolchain_map: &NameToolchainMap) -> Result<()> {
if opts.libs.is_empty() && opts.paths.is_empty() && opts.names.is_empty() && !opts.all {
if opts.libs.is_empty() && opts.lib_paths.is_empty() && opts.names.is_empty() && !opts.all {
if opts.list {
warn_if_empty(opts, name_toolchain_map)?;
return list_libs(name_toolchain_map);
Expand All @@ -190,7 +193,7 @@ fn run_with_name_toolchain_map(opts: &Dylint, name_toolchain_map: &NameToolchain

if resolved.is_empty() {
assert!(opts.libs.is_empty());
assert!(opts.paths.is_empty());
assert!(opts.lib_paths.is_empty());
assert!(opts.names.is_empty());

let name_toolchain_map_is_empty = warn_if_empty(opts, name_toolchain_map)?;
Expand Down Expand Up @@ -278,7 +281,7 @@ fn resolve(opts: &Dylint, name_toolchain_map: &NameToolchainMap) -> Result<Toolc
toolchain_map.entry(toolchain).or_default().insert(path);
}

for name in &opts.paths {
for name in &opts.lib_paths {
let (toolchain, path) = name_as_path(name, true)?.unwrap_or_else(|| unreachable!());
toolchain_map.entry(toolchain).or_default().insert(path);
}
Expand All @@ -290,7 +293,7 @@ fn resolve(opts: &Dylint, name_toolchain_map: &NameToolchainMap) -> Result<Toolc
ensure!(
!opts.all,
"`{}` is a library name and cannot be used with `--all`; if a path was meant, use \
`--path {}`",
`--lib-path {}`",
name,
name
);
Expand Down Expand Up @@ -380,7 +383,7 @@ fn name_as_path(name: &str, as_path_only: bool) -> Result<Option<(String, PathBu

ensure!(
!as_path_only,
"`--path {}` was used, but the filename does not have the required form: {}",
"`--lib-path {}` was used, but the filename does not have the required form: {}",
name,
*REQUIRED_FORM
);
Expand All @@ -396,7 +399,7 @@ fn name_as_path(name: &str, as_path_only: bool) -> Result<Option<(String, PathBu

ensure!(
!as_path_only,
"`--path {}` was used, but it is invalid",
"`--lib-path {}` was used, but it is invalid",
name
);
}
Expand Down

0 comments on commit e52da02

Please sign in to comment.