aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/command/base_command.rs
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-08-19 23:45:37 +0900
committernsfisis <nsfisis@gmail.com>2026-08-19 23:45:37 +0900
commit0800c90a7ec0bc7a3d4c13063dfe6d2298a557bc (patch)
treeba5602549ce20b8d71136423e85dffc25deafff4 /crates/shirabe/src/command/base_command.rs
parent6ed3a85dd636366d194c9810fd777db7f25e263f (diff)
downloadphp-shirabe-0800c90a7ec0bc7a3d4c13063dfe6d2298a557bc.tar.gz
php-shirabe-0800c90a7ec0bc7a3d4c13063dfe6d2298a557bc.tar.zst
php-shirabe-0800c90a7ec0bc7a3d4c13063dfe6d2298a557bc.zip
fix(input): thread a typed InputValue through the input layer
Options and arguments were stored and passed as PhpMixed even though Symfony only ever puts a string, a bool, a list of strings or null in one. get_option already narrowed to InputOptionValue at the boundary; this widens that enum into InputValue and pushes it through InputInterface, InputOption/InputArgument defaults, the Input storage, ArgvInput/ArrayInput/StringInput/CompletionInput, Command::add_option and add_argument, and the Composer-side wrappers. Two neighbouring string|int unions get types of their own: InputDefinition::{get_argument,has_argument} take an ArgumentName, and ArrayInput keys its parameters by ParameterName. has_parameter_option and get_parameter_option take the values they look for as &[&str], which is what PHP's `(array) $values` cast produced anyway. Two behaviours change along the way. Input::set_option on a negated option now negates with PHP's loose bool cast rather than treating a non-bool as false, matching `!$value`. ArrayInput::parse now resolves an integer key to an argument position instead of looking up an argument literally named "0". Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/src/command/base_command.rs')
-rw-r--r--crates/shirabe/src/command/base_command.rs40
1 files changed, 16 insertions, 24 deletions
diff --git a/crates/shirabe/src/command/base_command.rs b/crates/shirabe/src/command/base_command.rs
index 8ec9f350..d1d9ecf2 100644
--- a/crates/shirabe/src/command/base_command.rs
+++ b/crates/shirabe/src/command/base_command.rs
@@ -26,7 +26,9 @@ use shirabe_symfony_console::Terminal;
use shirabe_symfony_console::command::{Command, CommandData, SetDefinitionArg};
use shirabe_symfony_console::helper::Table;
use shirabe_symfony_console::helper::TableSeparator;
+use shirabe_symfony_console::input::ArgumentName;
use shirabe_symfony_console::input::InputInterface;
+use shirabe_symfony_console::input::InputValue;
use shirabe_symfony_console::output::OutputInterface;
pub const SUCCESS: i64 = 0;
@@ -122,7 +124,7 @@ pub trait BaseCommand: Command {
name: &str,
mode: Option<i64>,
description: &str,
- default: PhpMixed,
+ default: InputValue,
) -> &Self
where
Self: Sized,
@@ -139,14 +141,11 @@ pub trait BaseCommand: Command {
shortcut: Option<&str>,
mode: Option<i64>,
description: &str,
- default: PhpMixed,
+ default: InputValue,
) -> &Self
where
Self: Sized,
{
- let shortcut = shortcut
- .map(|s| PhpMixed::from(s.to_string()))
- .unwrap_or(PhpMixed::Null);
self.command_data()
.add_option(name, shortcut, mode, description, default)
.expect("command option definitions in configure() are statically valid");
@@ -400,11 +399,11 @@ impl BaseCommand for BaseCommandData {
let disable_plugins = disable_plugins
|| input
.borrow()
- .has_parameter_option(PhpMixed::from(vec!["--no-plugins"]), false);
+ .has_parameter_option(&["--no-plugins"], false);
let disable_scripts = disable_scripts.unwrap_or(false)
|| input
.borrow()
- .has_parameter_option(PhpMixed::from(vec!["--no-scripts"]), false);
+ .has_parameter_option(&["--no-scripts"], false);
let (disable_plugins, disable_scripts) =
apply_application_defaults(self.get_application(), disable_plugins, disable_scripts);
@@ -478,12 +477,12 @@ impl BaseCommand for BaseCommandData {
"dist" => {
input
.borrow_mut()
- .set_option("prefer-dist", PhpMixed::Bool(true))?;
+ .set_option("prefer-dist", InputValue::Bool(true))?;
}
"source" => {
input
.borrow_mut()
- .set_option("prefer-source", PhpMixed::Bool(true))?;
+ .set_option("prefer-source", InputValue::Bool(true))?;
}
"auto" => {
prefer_dist = false;
@@ -771,7 +770,7 @@ pub fn base_command_complete(
} else if CompletionInput::TYPE_ARGUMENT_VALUE == input.get_completion_type()
&& cmd
.get_definition()
- .has_argument(&PhpMixed::String(name.clone()))
+ .has_argument(&ArgumentName::Name(name.clone()))
{
let argument = cmd
.base_command_data()
@@ -799,10 +798,10 @@ pub fn base_command_initialize(
// initialize a plugin-enabled Composer instance, either local or global
let disable_plugins = input
.borrow()
- .has_parameter_option(PhpMixed::from(vec!["--no-plugins"]), false);
+ .has_parameter_option(&["--no-plugins"], false);
let disable_scripts = input
.borrow()
- .has_parameter_option(PhpMixed::from(vec!["--no-scripts"]), false);
+ .has_parameter_option(&["--no-scripts"], false);
let (mut disable_plugins, mut disable_scripts) =
apply_application_defaults(cmd.get_application(), disable_plugins, disable_scripts);
@@ -839,14 +838,12 @@ pub fn base_command_initialize(
)?;
}
- if input
- .borrow()
- .has_parameter_option(PhpMixed::from(vec!["--no-ansi"]), false)
+ if input.borrow().has_parameter_option(&["--no-ansi"], false)
&& input.borrow().has_option("no-progress")
{
input
.borrow_mut()
- .set_option("no-progress", PhpMixed::Bool(true));
+ .set_option("no-progress", InputValue::Bool(true));
}
let env_options: IndexMap<&str, Vec<&str>> = [
@@ -879,7 +876,7 @@ pub fn base_command_initialize(
{
input
.borrow_mut()
- .set_option(option_name, PhpMixed::Bool(true));
+ .set_option(option_name, InputValue::Bool(true));
}
}
}
@@ -895,7 +892,7 @@ pub fn base_command_initialize(
{
input
.borrow_mut()
- .set_option("ignore-platform-reqs", PhpMixed::Bool(true));
+ .set_option("ignore-platform-reqs", InputValue::Bool(true));
io.write_error("<warning>COMPOSER_IGNORE_PLATFORM_REQS is set. You may experience unexpected errors.</warning>");
}
@@ -917,12 +914,7 @@ pub fn base_command_initialize(
{
input.borrow_mut().set_option(
"ignore-platform-req",
- PhpMixed::List(
- explode(",", &ignore_str)
- .into_iter()
- .map(PhpMixed::String)
- .collect(),
- ),
+ InputValue::Array(explode(",", &ignore_str)),
);
io.write_error(&format!(