aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/command/validate_command.rs
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-05-17 02:53:53 +0900
committernsfisis <nsfisis@gmail.com>2026-05-17 02:53:53 +0900
commita1c7e6908a26e10f6e1f23a51721664b5e2d838d (patch)
treec575c76f1b43359ed74913da4c6a2636643f1ba0 /crates/shirabe/src/command/validate_command.rs
parent7f606f36fef0c0467c3c0db3d0da33af486dae8a (diff)
downloadphp-shirabe-a1c7e6908a26e10f6e1f23a51721664b5e2d838d.tar.gz
php-shirabe-a1c7e6908a26e10f6e1f23a51721664b5e2d838d.tar.zst
php-shirabe-a1c7e6908a26e10f6e1f23a51721664b5e2d838d.zip
chore(style): cargo fmt
Diffstat (limited to 'crates/shirabe/src/command/validate_command.rs')
-rw-r--r--crates/shirabe/src/command/validate_command.rs164
1 files changed, 138 insertions, 26 deletions
diff --git a/crates/shirabe/src/command/validate_command.rs b/crates/shirabe/src/command/validate_command.rs
index d2f726a..e95e5ca 100644
--- a/crates/shirabe/src/command/validate_command.rs
+++ b/crates/shirabe/src/command/validate_command.rs
@@ -26,14 +26,69 @@ impl ValidateCommand {
.set_name("validate")
.set_description("Validates a composer.json and composer.lock")
.set_definition(vec![
- InputOption::new("no-check-all", None, Some(InputOption::VALUE_NONE), "Do not validate requires for overly strict/loose constraints", None, vec![]),
- InputOption::new("check-lock", None, Some(InputOption::VALUE_NONE), "Check if lock file is up to date (even when config.lock is false)", None, vec![]),
- InputOption::new("no-check-lock", None, Some(InputOption::VALUE_NONE), "Do not check if lock file is up to date", None, vec![]),
- InputOption::new("no-check-publish", None, Some(InputOption::VALUE_NONE), "Do not check for publish errors", None, vec![]),
- InputOption::new("no-check-version", None, Some(InputOption::VALUE_NONE), "Do not report a warning if the version field is present", None, vec![]),
- InputOption::new("with-dependencies", Some(shirabe_php_shim::PhpMixed::String("A".to_string())), Some(InputOption::VALUE_NONE), "Also validate the composer.json of all installed dependencies", None, vec![]),
- InputOption::new("strict", None, Some(InputOption::VALUE_NONE), "Return a non-zero exit code for warnings as well as errors", None, vec![]),
- InputArgument::new("file", Some(InputArgument::OPTIONAL), "path to composer.json file", None, vec![]),
+ InputOption::new(
+ "no-check-all",
+ None,
+ Some(InputOption::VALUE_NONE),
+ "Do not validate requires for overly strict/loose constraints",
+ None,
+ vec![],
+ ),
+ InputOption::new(
+ "check-lock",
+ None,
+ Some(InputOption::VALUE_NONE),
+ "Check if lock file is up to date (even when config.lock is false)",
+ None,
+ vec![],
+ ),
+ InputOption::new(
+ "no-check-lock",
+ None,
+ Some(InputOption::VALUE_NONE),
+ "Do not check if lock file is up to date",
+ None,
+ vec![],
+ ),
+ InputOption::new(
+ "no-check-publish",
+ None,
+ Some(InputOption::VALUE_NONE),
+ "Do not check for publish errors",
+ None,
+ vec![],
+ ),
+ InputOption::new(
+ "no-check-version",
+ None,
+ Some(InputOption::VALUE_NONE),
+ "Do not report a warning if the version field is present",
+ None,
+ vec![],
+ ),
+ InputOption::new(
+ "with-dependencies",
+ Some(shirabe_php_shim::PhpMixed::String("A".to_string())),
+ Some(InputOption::VALUE_NONE),
+ "Also validate the composer.json of all installed dependencies",
+ None,
+ vec![],
+ ),
+ InputOption::new(
+ "strict",
+ None,
+ Some(InputOption::VALUE_NONE),
+ "Return a non-zero exit code for warnings as well as errors",
+ None,
+ vec![],
+ ),
+ InputArgument::new(
+ "file",
+ Some(InputArgument::OPTIONAL),
+ "path to composer.json file",
+ None,
+ vec![],
+ ),
])
.set_help(
"The validate command validates a given composer.json and composer.lock\n\n\
@@ -41,12 +96,14 @@ impl ValidateCommand {
1 validation warning(s), only when --strict is given\n\
2 validation error(s)\n\
3 file unreadable or missing\n\n\
- Read more at https://getcomposer.org/doc/03-cli.md#validate"
+ Read more at https://getcomposer.org/doc/03-cli.md#validate",
);
}
pub fn execute(&self, input: &dyn InputInterface, output: &dyn OutputInterface) -> Result<i64> {
- let file = input.get_argument("file").as_string_opt()
+ let file = input
+ .get_argument("file")
+ .as_string_opt()
.map(|s| s.to_string())
.unwrap_or_else(|| Factory::get_composer_file());
let io = self.inner.get_io();
@@ -66,19 +123,29 @@ impl ValidateCommand {
} else {
ValidatingArrayLoader::CHECK_ALL
};
- let check_publish = !input.get_option("no-check-publish").as_bool().unwrap_or(false);
+ let check_publish = !input
+ .get_option("no-check-publish")
+ .as_bool()
+ .unwrap_or(false);
let check_lock = !input.get_option("no-check-lock").as_bool().unwrap_or(false);
- let check_version = if input.get_option("no-check-version").as_bool().unwrap_or(false) {
+ let check_version = if input
+ .get_option("no-check-version")
+ .as_bool()
+ .unwrap_or(false)
+ {
0
} else {
ConfigValidator::CHECK_VERSION
};
let is_strict = input.get_option("strict").as_bool().unwrap_or(false);
- let (mut errors, mut publish_errors, mut warnings) = validator.validate(&file, check_all, check_version)?;
+ let (mut errors, mut publish_errors, mut warnings) =
+ validator.validate(&file, check_all, check_version)?;
let mut lock_errors: Vec<String> = vec![];
let composer = self.inner.create_composer_instance(input, io, vec![])?;
- let check_lock = (check_lock && composer.get_config().get("lock").as_bool().unwrap_or(true)) || input.get_option("check-lock").as_bool().unwrap_or(false);
+ let check_lock = (check_lock
+ && composer.get_config().get("lock").as_bool().unwrap_or(true))
+ || input.get_option("check-lock").as_bool().unwrap_or(false);
let locker = composer.get_locker();
if locker.is_locked() && !locker.is_fresh() {
lock_errors.push("- The lock file is not up to date with the latest changes in composer.json, it is recommended that you run `composer update` or `composer update <package name>`.".to_string());
@@ -88,7 +155,17 @@ impl ValidateCommand {
lock_errors.extend(locker.get_missing_requirement_info(composer.get_package(), true));
}
- self.output_result(io, &file, &mut errors, &mut warnings, check_publish, &mut publish_errors, check_lock, &mut lock_errors, true);
+ self.output_result(
+ io,
+ &file,
+ &mut errors,
+ &mut warnings,
+ check_publish,
+ &mut publish_errors,
+ check_lock,
+ &mut lock_errors,
+ true,
+ );
let exit_code = if !errors.is_empty() {
2
@@ -100,19 +177,37 @@ impl ValidateCommand {
let mut exit_code = exit_code;
- if input.get_option("with-dependencies").as_bool().unwrap_or(false) {
+ if input
+ .get_option("with-dependencies")
+ .as_bool()
+ .unwrap_or(false)
+ {
let local_repo = composer.get_repository_manager().get_local_repository();
for package in local_repo.get_packages() {
- let path = composer.get_installation_manager().get_install_path(package.as_ref());
+ let path = composer
+ .get_installation_manager()
+ .get_install_path(package.as_ref());
let path = match path {
Some(p) => p,
None => continue,
};
let dep_file = format!("{}/composer.json", path);
- if std::path::Path::new(&path).is_dir() && std::path::Path::new(&dep_file).exists() {
- let (mut dep_errors, mut dep_publish_errors, mut dep_warnings) = validator.validate(&dep_file, check_all, check_version)?;
+ if std::path::Path::new(&path).is_dir() && std::path::Path::new(&dep_file).exists()
+ {
+ let (mut dep_errors, mut dep_publish_errors, mut dep_warnings) =
+ validator.validate(&dep_file, check_all, check_version)?;
- self.output_result(io, package.get_pretty_name(), &mut dep_errors, &mut dep_warnings, check_publish, &mut dep_publish_errors, false, &mut vec![], false);
+ self.output_result(
+ io,
+ package.get_pretty_name(),
+ &mut dep_errors,
+ &mut dep_warnings,
+ check_publish,
+ &mut dep_publish_errors,
+ false,
+ &mut vec![],
+ false,
+ );
let dep_code = if !dep_errors.is_empty() {
2
@@ -135,7 +230,9 @@ impl ValidateCommand {
vec![],
vec![],
);
- let event_code = composer.get_event_dispatcher().dispatch(command_event.get_name(), &command_event);
+ let event_code = composer
+ .get_event_dispatcher()
+ .dispatch(command_event.get_name(), &command_event);
Ok(exit_code.max(event_code))
}
@@ -155,16 +252,31 @@ impl ValidateCommand {
let mut do_print_schema_url = false;
if !errors.is_empty() {
- io.write_error(&format!("<error>{} is invalid, the following errors/warnings were found:</error>", name));
+ io.write_error(&format!(
+ "<error>{} is invalid, the following errors/warnings were found:</error>",
+ name
+ ));
} else if !publish_errors.is_empty() && check_publish {
- io.write_error(&format!("<info>{} is valid for simple usage with Composer but has</info>", name));
- io.write_error("<info>strict errors that make it unable to be published as a package</info>");
+ io.write_error(&format!(
+ "<info>{} is valid for simple usage with Composer but has</info>",
+ name
+ ));
+ io.write_error(
+ "<info>strict errors that make it unable to be published as a package</info>",
+ );
do_print_schema_url = print_schema_url;
} else if !warnings.is_empty() {
- io.write_error(&format!("<info>{} is valid, but with a few warnings</info>", name));
+ io.write_error(&format!(
+ "<info>{} is valid, but with a few warnings</info>",
+ name
+ ));
do_print_schema_url = print_schema_url;
} else if !lock_errors.is_empty() {
- io.write(&format!("<info>{} is valid but your composer.lock has some {}</info>", name, if check_lock { "errors" } else { "warnings" }));
+ io.write(&format!(
+ "<info>{} is valid but your composer.lock has some {}</info>",
+ name,
+ if check_lock { "errors" } else { "warnings" }
+ ));
} else {
io.write(&format!("<info>{} is valid</info>", name));
}