Skip to content

Commit cbace28

Browse files
perryqhashleywillardtstannard
committed
Renaming check-unnecessary-dependencies to check-unused-dependencies
Co-authored-by: Ashley Willard <[email protected]> Co-authored-by: Teal Stannard <[email protected]>
1 parent 9c3204a commit cbace28

File tree

4 files changed

+43
-16
lines changed

4 files changed

+43
-16
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
[package]
44
name = "pks"
5-
version = "0.2.20"
5+
version = "0.2.21"
66
edition = "2021"
77
description = "Welcome! Please see https://github.com/rubyatscale/pks for more information!"
88
license = "MIT"

src/packs/checker.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -381,13 +381,14 @@ pub(crate) fn check_unnecessary_dependencies(
381381
"Found 1 unnecessary dependency".to_string()
382382
} else {
383383
format!(
384-
"Found {} unnecessary dependencies",
384+
"Found {} unused dependencies",
385385
unnecessary_dependencies.len()
386386
)
387387
};
388388
bail!(
389-
"{}. Run command with `--auto-correct` to remove them.",
389+
"{}. Run `{} check-unused-dependencies --auto-correct` to remove them.",
390390
found_message,
391+
bin_locater::packs_bin_name(),
391392
);
392393
}
393394
}

src/packs/cli.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,11 @@ enum Command {
109109
},
110110

111111
#[clap(
112-
about = "Check for dependencies that when removed produce no violations."
112+
about = "Check for dependencies that when removed produce no violations.",
113+
alias = "check-unnecessary-dependencies"
113114
)]
114-
CheckUnnecessaryDependencies {
115-
#[arg(long)]
115+
CheckUnusedDependencies {
116+
#[arg(short, long)]
116117
auto_correct: bool,
117118
},
118119

@@ -263,7 +264,7 @@ pub fn run() -> anyhow::Result<()> {
263264
packs::validate(&configuration)
264265
// Err("💡 Please use `packs check` to detect dependency cycles and run other configuration validations".into())
265266
}
266-
Command::CheckUnnecessaryDependencies { auto_correct } => {
267+
Command::CheckUnusedDependencies { auto_correct } => {
267268
packs::check_unnecessary_dependencies(&configuration, auto_correct)
268269
}
269270
Command::UpdateDependenciesForConstant { constant } => Ok(

tests/check_unnecessary_dependencies.rs tests/check_unused_dependencies.rs

+34-9
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ fn assert_check_unused_dependencies(cmd: &str) -> Result<(), Box<dyn Error>> {
88
.arg("--project-root")
99
.arg("tests/fixtures/app_with_dependency_cycles")
1010
.arg("--debug")
11-
.arg(&cmd)
11+
.arg(cmd)
1212
.assert()
1313
.failure()
1414
.stdout(predicate::str::contains(
@@ -18,8 +18,8 @@ fn assert_check_unused_dependencies(cmd: &str) -> Result<(), Box<dyn Error>> {
1818
"packs/foo depends on packs/bar but does not use it",
1919
))
2020
.stderr(predicate::str::contains(
21-
format!("Error: Found 3 unnecessary dependencies. Run `packs {}| --auto-correct` to remove them.", &cmd),
22-
));
21+
"Error: Found 3 unused dependencies. Run `packs check-unused-dependencies --auto-correct` to remove them.")
22+
);
2323
Ok(())
2424
}
2525

@@ -33,14 +33,30 @@ fn test_check_unused_dependencies() -> Result<(), Box<dyn Error>> {
3333
assert_check_unused_dependencies("check-unused-dependencies")
3434
}
3535

36+
fn assert_auto_correct_unused_dependencies(
37+
cmd: &str,
38+
flag: &str,
39+
) -> Result<(), Box<dyn Error>> {
40+
common::set_up_fixtures();
41+
42+
let expected_before_autocorrect = [
43+
"enforce_dependencies: true",
44+
"enforce_privacy: true",
45+
"layer: technical_services",
46+
"dependencies:",
47+
"- packs/bar",
48+
"- packs/baz\n",
49+
]
50+
.join("\n");
51+
let foo_package_yml = fs::read_to_string("tests/fixtures/app_with_unnecessary_dependencies/packs/foo/package.yml").unwrap();
52+
assert_eq!(foo_package_yml, expected_before_autocorrect);
3653

37-
fn assert_auto_correct_unused_dependencies(cmd: &str, flag: &str) -> Result<(), Box<dyn Error>> {
3854
Command::cargo_bin("pks")?
3955
.arg("--project-root")
4056
.arg("tests/fixtures/app_with_unnecessary_dependencies")
4157
.arg("--debug")
42-
.arg(&cmd)
43-
.arg(&flag)
58+
.arg(cmd)
59+
.arg(flag)
4460
.assert()
4561
.success();
4662

@@ -60,10 +76,19 @@ fn assert_auto_correct_unused_dependencies(cmd: &str, flag: &str) -> Result<(),
6076

6177
#[test]
6278
fn test_auto_correct_unnecessary_dependencies() -> Result<(), Box<dyn Error>> {
63-
assert_auto_correct_unused_dependencies("check-unused-dependencies", "--auto-correct")?;
79+
assert_auto_correct_unused_dependencies(
80+
"check-unused-dependencies",
81+
"--auto-correct",
82+
)?;
6483
assert_auto_correct_unused_dependencies("check-unused-dependencies", "-a")?;
65-
assert_auto_correct_unused_dependencies("check-unnecessary-dependencies", "-a")?;
66-
assert_auto_correct_unused_dependencies("check-unnecessary-dependencies", "--auto-correct")
84+
assert_auto_correct_unused_dependencies(
85+
"check-unnecessary-dependencies",
86+
"-a",
87+
)?;
88+
assert_auto_correct_unused_dependencies(
89+
"check-unnecessary-dependencies",
90+
"--auto-correct",
91+
)
6792
}
6893

6994
#[test]

0 commit comments

Comments
 (0)