aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-05-09 14:15:53 +0900
committernsfisis <nsfisis@gmail.com>2026-05-09 14:15:53 +0900
commit75b15f58b778b4574e74c86c103b7e36baf4eeb3 (patch)
tree381281bf52f940ef32f8542943b01b37b8de0855 /crates
parentf18c18cd15f180b5067069ec6f10530515715f3d (diff)
downloadphp-mozart-75b15f58b778b4574e74c86c103b7e36baf4eeb3.tar.gz
php-mozart-75b15f58b778b4574e74c86c103b7e36baf4eeb3.tar.zst
php-mozart-75b15f58b778b4574e74c86c103b7e36baf4eeb3.zip
refactor(show): make format field non-optional with default "text"
Replace `Option<String>` with `String` + `default_value = "text"` and derive `Default` on `ShowArgs`, eliminating local `as_deref().unwrap_or` bindings. outdated.rs switches to `..Default::default()` for the fields it doesn't set. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to 'crates')
-rw-r--r--crates/mozart/src/commands/outdated.rs19
-rw-r--r--crates/mozart/src/commands/show.rs29
2 files changed, 13 insertions, 35 deletions
diff --git a/crates/mozart/src/commands/outdated.rs b/crates/mozart/src/commands/outdated.rs
index c17360d..12646f4 100644
--- a/crates/mozart/src/commands/outdated.rs
+++ b/crates/mozart/src/commands/outdated.rs
@@ -58,11 +58,7 @@ pub struct OutdatedArgs {
pub ignore_platform_reqs: bool,
}
-/// `outdated` is a proxy command — it mirrors Composer's `OutdatedCommand::execute`
-/// (see `composer/src/Composer/Command/OutdatedCommand.php` 68–126), which remaps
-/// its options into a `show --latest [--outdated]` invocation. Keeping the logic
-/// in one place means every behavioral aspect (rendering, JSON shape, --strict,
-/// mutual-exclusion checks, ignore warnings, etc.) has a single source of truth.
+/// `outdated` is a proxy command, forwarding to `show --latest`.
pub async fn execute(
args: &OutdatedArgs,
cli: &super::Cli,
@@ -70,18 +66,8 @@ pub async fn execute(
) -> anyhow::Result<()> {
let show_args = super::show::ShowArgs {
package: args.package.clone(),
- version: None,
- all: false,
locked: args.locked,
- installed: false,
- platform: false,
- available: false,
- self_info: false,
- name_only: false,
- path: false,
- tree: false,
latest: true,
- // Composer: `if (!--all) $args['--outdated'] = true;`
outdated: !args.all,
ignore: args.ignore.clone(),
major_only: args.major_only,
@@ -90,10 +76,11 @@ pub async fn execute(
sort_by_age: args.sort_by_age,
direct: args.direct,
strict: args.strict,
- format: Some(args.format.clone()),
+ format: args.format.clone(),
no_dev: args.no_dev,
ignore_platform_req: args.ignore_platform_req.clone(),
ignore_platform_reqs: args.ignore_platform_reqs,
+ ..Default::default()
};
super::show::execute(&show_args, cli, console).await
diff --git a/crates/mozart/src/commands/show.rs b/crates/mozart/src/commands/show.rs
index 6a07fb0..f0b82b3 100644
--- a/crates/mozart/src/commands/show.rs
+++ b/crates/mozart/src/commands/show.rs
@@ -8,7 +8,7 @@ use mozart_core::platform::is_platform_package;
use std::collections::BTreeMap;
use std::path::Path;
-#[derive(Args)]
+#[derive(Default, Args)]
pub struct ShowArgs {
/// Package to inspect
pub package: Option<String>,
@@ -89,8 +89,8 @@ pub struct ShowArgs {
pub strict: bool,
/// Output format (text, json)
- #[arg(short, long)]
- pub format: Option<String>,
+ #[arg(short, long, default_value = "text")]
+ pub format: String,
/// Disables listing of require-dev packages
#[arg(long)]
@@ -152,13 +152,10 @@ pub async fn execute(
}
// --format validation
- if let Some(ref fmt) = args.format
- && fmt != "text"
- && fmt != "json"
- {
+ if args.format != "text" && args.format != "json" {
anyhow::bail!(
"Unsupported format \"{}\". See help for supported formats.",
- fmt
+ args.format
);
}
@@ -539,7 +536,6 @@ fn render_package_list(
console: &mozart_core::console::Console,
) -> anyhow::Result<bool> {
let show_latest = args.latest || args.outdated;
- let format = args.format.as_deref().unwrap_or("text");
// A4: --sort-by-age (mirrors Composer 497-504)
if args.sort_by_age {
@@ -548,7 +544,7 @@ fn render_package_list(
let has_outdated = entries.iter().any(|e| e.latest_info.is_some());
- if format == "json" {
+ if args.format == "json" {
render_list_json(entries, section_key, console)?;
return Ok(has_outdated);
}
@@ -934,8 +930,7 @@ async fn print_package_detail(
repo_cache: &mozart_registry::cache::Cache,
console: &mozart_core::console::Console,
) -> anyhow::Result<()> {
- let format = args.format.as_deref().unwrap_or("text");
- if format == "json" {
+ if args.format == "json" {
return print_package_detail_json(detail, args, repo_cache, console).await;
}
@@ -1777,8 +1772,7 @@ fn show_platform(
platform_packages.sort_by(|a, b| a.0.cmp(&b.0));
- let format = args.format.as_deref().unwrap_or("text");
- if format == "json" {
+ if args.format == "json" {
let json_entries: Vec<serde_json::Value> = platform_packages
.iter()
.map(|(name, version, source)| {
@@ -1898,9 +1892,7 @@ async fn show_available(
);
console_writeln!(console, "");
- let format = args.format.as_deref().unwrap_or("text");
-
- if format == "json" {
+ if args.format == "json" {
let mut json_entries: Vec<serde_json::Value> = Vec::new();
for pkg in &installed.packages {
if is_platform_package(&pkg.name) {
@@ -1952,8 +1944,7 @@ async fn show_available_versions(
return Ok(());
}
- let format = args.format.as_deref().unwrap_or("text");
- if format == "json" {
+ if args.format == "json" {
let version_strings: Vec<String> = versions.iter().map(|v| v.version.clone()).collect();
let output = serde_json::json!({
"name": pkg_name,