aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/command/self_update_command.rs
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-06-16 21:59:35 +0900
committernsfisis <nsfisis@gmail.com>2026-06-19 22:17:11 +0900
commitfd733a87364b877d5e66b4973bd61b5379ec4d61 (patch)
tree64bd6c37ca1c33581a851eba22e4261bf5b62b49 /crates/shirabe/src/command/self_update_command.rs
parent7f3171b14a89762b2f0c71969d7243f2297af7c9 (diff)
downloadphp-shirabe-fd733a87364b877d5e66b4973bd61b5379ec4d61.tar.gz
php-shirabe-fd733a87364b877d5e66b4973bd61b5379ec4d61.tar.zst
php-shirabe-fd733a87364b877d5e66b4973bd61b5379ec4d61.zip
feat(command): implement Symfony Command
Diffstat (limited to 'crates/shirabe/src/command/self_update_command.rs')
-rw-r--r--crates/shirabe/src/command/self_update_command.rs111
1 files changed, 72 insertions, 39 deletions
diff --git a/crates/shirabe/src/command/self_update_command.rs b/crates/shirabe/src/command/self_update_command.rs
index 8c7baeb..a32f931 100644
--- a/crates/shirabe/src/command/self_update_command.rs
+++ b/crates/shirabe/src/command/self_update_command.rs
@@ -1,15 +1,26 @@
//! ref: composer/src/Composer/Command/SelfUpdateCommand.php
-use crate::io::io_interface;
use anyhow::Result;
+use indexmap::IndexMap;
+use shirabe_external_packages::symfony::console::command::command::Command;
use shirabe_external_packages::symfony::console::input::InputInterface;
use shirabe_external_packages::symfony::console::output::OutputInterface;
use shirabe_php_shim::PhpMixed;
+use std::cell::RefCell;
+use std::rc::Rc;
-use crate::command::{BaseCommand, BaseCommandData, HasBaseCommandData};
+use crate::advisory::AuditConfig;
+use crate::command::BaseCommand;
+use crate::command::BaseCommandData;
+use crate::command::base_command::base_command_initialize;
+use crate::composer::PartialComposerHandle;
+use crate::config::Config;
use crate::console::input::InputArgument;
use crate::console::input::InputOption;
+use crate::filter::platform_requirement_filter::PlatformRequirementFilterInterface;
+use crate::io::IOInterface;
use crate::io::IOInterfaceImmutable;
+use crate::io::io_interface;
#[derive(Debug)]
pub struct SelfUpdateCommand {
@@ -17,43 +28,55 @@ pub struct SelfUpdateCommand {
}
impl SelfUpdateCommand {
- pub fn configure(&mut self) {
- self
- .set_name("self-update")
- .set_aliases(&["selfupdate".to_string()])
- .set_description("Updates composer.phar to the latest version")
- .set_definition(&[
- InputOption::new("rollback", Some(PhpMixed::String("r".to_string())), Some(InputOption::VALUE_NONE), "Revert to an older installation of composer", None).unwrap().into(),
- InputOption::new("clean-backups", None, Some(InputOption::VALUE_NONE), "Delete old backups during an update. This makes the current version of composer the only backup available after the update", None).unwrap().into(),
- InputArgument::new("version", Some(InputArgument::OPTIONAL), "The version to update to", None).unwrap().into(),
- InputOption::new("no-progress", None, Some(InputOption::VALUE_NONE), "Do not output download progress.", None).unwrap().into(),
- InputOption::new("update-keys", None, Some(InputOption::VALUE_NONE), "Prompt user for a key update", None).unwrap().into(),
- InputOption::new("stable", None, Some(InputOption::VALUE_NONE), "Force an update to the stable channel", None).unwrap().into(),
- InputOption::new("preview", None, Some(InputOption::VALUE_NONE), "Force an update to the preview channel", None).unwrap().into(),
- InputOption::new("snapshot", None, Some(InputOption::VALUE_NONE), "Force an update to the snapshot channel", None).unwrap().into(),
- InputOption::new("1", None, Some(InputOption::VALUE_NONE), "Force an update to the stable channel, but only use 1.x versions", None).unwrap().into(),
- InputOption::new("2", None, Some(InputOption::VALUE_NONE), "Force an update to the stable channel, but only use 2.x versions", None).unwrap().into(),
- InputOption::new("2.2", None, Some(InputOption::VALUE_NONE), "Force an update to the stable channel, but only use 2.2.x LTS versions", None).unwrap().into(),
- InputOption::new("set-channel-only", None, Some(InputOption::VALUE_NONE), "Only store the channel as the default one and then exit", None).unwrap().into(),
- ])
- .set_help(
- "The <info>self-update</info> command checks getcomposer.org for newer\n\
- versions of composer and if found, installs the latest.\n\
- \n\
- <info>php composer.phar self-update</info>\n\
- \n\
- Read more at https://getcomposer.org/doc/03-cli.md#self-update-selfupdate"
- );
+ pub fn new() -> Self {
+ let mut command = SelfUpdateCommand {
+ base_command_data: BaseCommandData::new(None),
+ };
+ command
+ .configure()
+ .expect("SelfUpdateCommand::configure uses static, valid metadata");
+ command
+ }
+}
+
+impl Command for SelfUpdateCommand {
+ fn configure(&mut self) -> anyhow::Result<()> {
+ self.set_name("self-update")?;
+ self.set_aliases(vec!["selfupdate".to_string()])?;
+ self.set_description("Updates composer.phar to the latest version");
+ self.set_definition(&[
+ InputOption::new("rollback", Some(PhpMixed::String("r".to_string())), Some(InputOption::VALUE_NONE), "Revert to an older installation of composer", None).unwrap().into(),
+ InputOption::new("clean-backups", None, Some(InputOption::VALUE_NONE), "Delete old backups during an update. This makes the current version of composer the only backup available after the update", None).unwrap().into(),
+ InputArgument::new("version", Some(InputArgument::OPTIONAL), "The version to update to", None).unwrap().into(),
+ InputOption::new("no-progress", None, Some(InputOption::VALUE_NONE), "Do not output download progress.", None).unwrap().into(),
+ InputOption::new("update-keys", None, Some(InputOption::VALUE_NONE), "Prompt user for a key update", None).unwrap().into(),
+ InputOption::new("stable", None, Some(InputOption::VALUE_NONE), "Force an update to the stable channel", None).unwrap().into(),
+ InputOption::new("preview", None, Some(InputOption::VALUE_NONE), "Force an update to the preview channel", None).unwrap().into(),
+ InputOption::new("snapshot", None, Some(InputOption::VALUE_NONE), "Force an update to the snapshot channel", None).unwrap().into(),
+ InputOption::new("1", None, Some(InputOption::VALUE_NONE), "Force an update to the stable channel, but only use 1.x versions", None).unwrap().into(),
+ InputOption::new("2", None, Some(InputOption::VALUE_NONE), "Force an update to the stable channel, but only use 2.x versions", None).unwrap().into(),
+ InputOption::new("2.2", None, Some(InputOption::VALUE_NONE), "Force an update to the stable channel, but only use 2.2.x LTS versions", None).unwrap().into(),
+ InputOption::new("set-channel-only", None, Some(InputOption::VALUE_NONE), "Only store the channel as the default one and then exit", None).unwrap().into(),
+ ]);
+ self.set_help(
+ "The <info>self-update</info> command checks getcomposer.org for newer\n\
+ versions of composer and if found, installs the latest.\n\
+ \n\
+ <info>php composer.phar self-update</info>\n\
+ \n\
+ Read more at https://getcomposer.org/doc/03-cli.md#self-update-selfupdate",
+ );
+ Ok(())
}
/// The self-update mechanism does not apply to Shirabe: the update flow
/// differs fundamentally from the PHP phar-based one, and no release has
/// been published yet. The command is therefore disabled.
- pub fn execute(
+ fn execute(
&mut self,
- _input: std::rc::Rc<std::cell::RefCell<dyn InputInterface>>,
- _output: std::rc::Rc<std::cell::RefCell<dyn OutputInterface>>,
- ) -> Result<i64> {
+ _input: Rc<RefCell<dyn InputInterface>>,
+ _output: Rc<RefCell<dyn OutputInterface>>,
+ ) -> anyhow::Result<i64> {
let io = self.get_io();
io.write_error3(
"<error>The self-update command is not available in Shirabe.</error>",
@@ -63,17 +86,27 @@ impl SelfUpdateCommand {
Ok(1)
}
-}
-impl HasBaseCommandData for SelfUpdateCommand {
- fn base_command_data(&self) -> &BaseCommandData {
- &self.base_command_data
+ fn initialize(
+ &mut self,
+ input: Rc<RefCell<dyn InputInterface>>,
+ output: Rc<RefCell<dyn OutputInterface>>,
+ ) -> anyhow::Result<()> {
+ base_command_initialize(self, input, output)
}
- fn base_command_data_mut(&mut self) -> &mut BaseCommandData {
- &mut self.base_command_data
+ shirabe_external_packages::delegate_command_trait_impls_to_inner!(base_command_data);
+}
+
+impl BaseCommand for SelfUpdateCommand {
+ fn command_data_mut(
+ &mut self,
+ ) -> &mut shirabe_external_packages::symfony::console::command::command::CommandData {
+ self.base_command_data.command_data_mut()
}
+ crate::delegate_base_command_trait_impls_to_inner!(base_command_data);
+
fn is_self_update_command(&self) -> bool {
true
}