From 427d70f83903e751621817049700d856fc9b8d21 Mon Sep 17 00:00:00 2001 From: Perry Hertler Date: Wed, 21 Aug 2024 12:16:34 -0500 Subject: [PATCH] Renaming check-unnecessary-dependencies to check-unused-dependencies Co-authored-by: Ashley Willard Co-authored-by: Teal Stannard --- Cargo.toml | 2 +- src/packs/checker.rs | 5 +++-- src/packs/cli.rs | 9 +++++---- tests/check_unnecessary_dependencies.rs | 18 ++++++++++++++++-- 4 files changed, 25 insertions(+), 9 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 03b25ce..4cf717c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ [package] name = "pks" -version = "0.2.20" +version = "0.2.21" edition = "2021" description = "Welcome! Please see https://github.com/rubyatscale/pks for more information!" license = "MIT" diff --git a/src/packs/checker.rs b/src/packs/checker.rs index 6ed37c1..06d46ea 100644 --- a/src/packs/checker.rs +++ b/src/packs/checker.rs @@ -381,13 +381,14 @@ pub(crate) fn check_unnecessary_dependencies( "Found 1 unnecessary dependency".to_string() } else { format!( - "Found {} unnecessary dependencies", + "Found {} unused dependencies", unnecessary_dependencies.len() ) }; bail!( - "{}. Run command with `--auto-correct` to remove them.", + "{}. Run `{} check-unused-dependencies --auto-correct` to remove them.", found_message, + bin_locater::packs_bin_name(), ); } } diff --git a/src/packs/cli.rs b/src/packs/cli.rs index 66c11bc..0a03f61 100644 --- a/src/packs/cli.rs +++ b/src/packs/cli.rs @@ -109,10 +109,11 @@ enum Command { }, #[clap( - about = "Check for dependencies that when removed produce no violations." + about = "Check for dependencies that when removed produce no violations.", + alias = "check-unnecessary-dependencies" )] - CheckUnnecessaryDependencies { - #[arg(long)] + CheckUnusedDependencies { + #[arg(short, long)] auto_correct: bool, }, @@ -263,7 +264,7 @@ pub fn run() -> anyhow::Result<()> { packs::validate(&configuration) // Err("💡 Please use `packs check` to detect dependency cycles and run other configuration validations".into()) } - Command::CheckUnnecessaryDependencies { auto_correct } => { + Command::CheckUnusedDependencies { auto_correct } => { packs::check_unnecessary_dependencies(&configuration, auto_correct) } Command::UpdateDependenciesForConstant { constant } => Ok( diff --git a/tests/check_unnecessary_dependencies.rs b/tests/check_unnecessary_dependencies.rs index dde8dc2..96286d8 100644 --- a/tests/check_unnecessary_dependencies.rs +++ b/tests/check_unnecessary_dependencies.rs @@ -18,8 +18,8 @@ fn assert_check_unused_dependencies(cmd: &str) -> Result<(), Box> { "packs/foo depends on packs/bar but does not use it", )) .stderr(predicate::str::contains( - format!("Error: Found 3 unnecessary dependencies. Run `packs {}| --auto-correct` to remove them.", &cmd), - )); + "Error: Found 3 unused dependencies. Run `packs check-unused-dependencies --auto-correct` to remove them.") + ); Ok(()) } @@ -35,6 +35,20 @@ fn test_check_unused_dependencies() -> Result<(), Box> { fn assert_auto_correct_unused_dependencies(cmd: &str, flag: &str) -> Result<(), Box> { + common::set_up_fixtures(); + + let expected_before_autocorrect = [ + "enforce_dependencies: true", + "enforce_privacy: true", + "layer: technical_services", + "dependencies:", + "- packs/bar", + "- packs/baz\n", + ] + .join("\n"); + let foo_package_yml = fs::read_to_string("tests/fixtures/app_with_unnecessary_dependencies/packs/foo/package.yml").unwrap(); + assert_eq!(foo_package_yml, expected_before_autocorrect); + Command::cargo_bin("pks")? .arg("--project-root") .arg("tests/fixtures/app_with_unnecessary_dependencies")