diff options
Diffstat (limited to 'crates/shirabe/src/command')
| -rw-r--r-- | crates/shirabe/src/command/bump_command.rs | 8 | ||||
| -rw-r--r-- | crates/shirabe/src/command/create_project_command.rs | 4 | ||||
| -rw-r--r-- | crates/shirabe/src/command/diagnose_command.rs | 15 | ||||
| -rw-r--r-- | crates/shirabe/src/command/home_command.rs | 5 | ||||
| -rw-r--r-- | crates/shirabe/src/command/install_command.rs | 8 | ||||
| -rw-r--r-- | crates/shirabe/src/command/package_discovery_trait.rs | 30 | ||||
| -rw-r--r-- | crates/shirabe/src/command/remove_command.rs | 5 | ||||
| -rw-r--r-- | crates/shirabe/src/command/require_command.rs | 23 | ||||
| -rw-r--r-- | crates/shirabe/src/command/self_update_command.rs | 11 | ||||
| -rw-r--r-- | crates/shirabe/src/command/show_command.rs | 2 | ||||
| -rw-r--r-- | crates/shirabe/src/command/status_command.rs | 10 | ||||
| -rw-r--r-- | crates/shirabe/src/command/suggests_command.rs | 5 | ||||
| -rw-r--r-- | crates/shirabe/src/command/update_command.rs | 22 | ||||
| -rw-r--r-- | crates/shirabe/src/command/validate_command.rs | 16 |
14 files changed, 73 insertions, 91 deletions
diff --git a/crates/shirabe/src/command/bump_command.rs b/crates/shirabe/src/command/bump_command.rs index 0f62bb8..64ec54b 100644 --- a/crates/shirabe/src/command/bump_command.rs +++ b/crates/shirabe/src/command/bump_command.rs @@ -13,6 +13,7 @@ use crate::console::input::InputArgument; use crate::console::input::InputOption; use crate::factory::Factory; use crate::io::IOInterface; +use crate::io::IOInterfaceImmutable; use crate::json::JsonFile; use crate::json::JsonManipulator; use crate::package::AliasPackage; @@ -72,10 +73,9 @@ impl BumpCommand { let dev_only = input.get_option("dev-only").as_bool().unwrap_or(false); let no_dev_only = input.get_option("no-dev-only").as_bool().unwrap_or(false); let dry_run = input.get_option("dry-run").as_bool().unwrap_or(false); - // TODO(phase-b): do_bump expects &dyn IOInterface but get_io() requires &mut self; needs IO sharing refactor - let io_ref: &dyn IOInterface = todo!("share IOInterface across calls in do_bump"); + let io = self.get_io().clone(); self.do_bump( - io_ref, + io, dev_only, no_dev_only, dry_run, @@ -86,7 +86,7 @@ impl BumpCommand { pub fn do_bump( &mut self, - io: &dyn IOInterface, + io: std::rc::Rc<std::cell::RefCell<dyn IOInterface>>, dev_only: bool, no_dev_only: bool, dry_run: bool, diff --git a/crates/shirabe/src/command/create_project_command.rs b/crates/shirabe/src/command/create_project_command.rs index c669aa5..e52fe39 100644 --- a/crates/shirabe/src/command/create_project_command.rs +++ b/crates/shirabe/src/command/create_project_command.rs @@ -816,7 +816,7 @@ impl CreateProjectCommand { &stability, None, 0, - Some(&*io.borrow()), + Some(io.clone()), PhpMixed::Bool(true), )?; @@ -926,7 +926,7 @@ impl CreateProjectCommand { true, false, )?; - im.notify_installs(&*io.borrow()); + im.notify_installs(io.clone()); // collect suggestions // TODO(phase-b): self.suggested_packages_reporter is on the outer scope via &self diff --git a/crates/shirabe/src/command/diagnose_command.rs b/crates/shirabe/src/command/diagnose_command.rs index 945d1e9..bcedf30 100644 --- a/crates/shirabe/src/command/diagnose_command.rs +++ b/crates/shirabe/src/command/diagnose_command.rs @@ -79,7 +79,7 @@ impl DiagnoseCommand { output: &dyn OutputInterface, ) -> anyhow::Result<i64> { let mut composer = self.try_composer(None, None); - let io_boxed: std::rc::Rc<std::cell::RefCell<dyn IOInterface>> = self.get_io().clone(); + let io: std::rc::Rc<std::cell::RefCell<dyn IOInterface>> = self.get_io().clone(); let config: std::rc::Rc<std::cell::RefCell<Config>>; if let Some(ref mut c) = composer { @@ -104,7 +104,7 @@ impl DiagnoseCommand { .map(std::rc::Rc::clone) .unwrap_or_else(|| { std::rc::Rc::new(std::cell::RefCell::new(ProcessExecutor::new(Some( - io_boxed.clone(), + io.clone(), )))) }), ); @@ -112,14 +112,9 @@ impl DiagnoseCommand { config = std::rc::Rc::new(std::cell::RefCell::new(Factory::create_config(None, None)?)); self.process = Some(std::rc::Rc::new(std::cell::RefCell::new( - ProcessExecutor::new(Some(io_boxed.clone())), + ProcessExecutor::new(Some(io.clone())), ))); } - // TODO(phase-b): clone_box to release self borrow held by get_io. - let io_box = self.get_io().clone(); - let io_ref = io_box.borrow(); - let io: &dyn IOInterface = &*io_ref; - let mut config_inner: IndexMap<String, Box<PhpMixed>> = IndexMap::new(); config_inner.insert("secure-http".to_string(), Box::new(PhpMixed::Bool(false))); let mut secure_http_wrap: IndexMap<String, PhpMixed> = IndexMap::new(); @@ -130,12 +125,12 @@ impl DiagnoseCommand { .merge(&secure_http_wrap, Config::SOURCE_COMMAND); let _ = config.borrow_mut().prohibit_url_by_config( "http://repo.packagist.org", - Some(&NullIO::new()), + Some(std::rc::Rc::new(std::cell::RefCell::new(NullIO::new()))), &IndexMap::new(), ); self.http_downloader = Some(std::rc::Rc::new(std::cell::RefCell::new( - Factory::create_http_downloader(io_box.clone(), &config, indexmap::IndexMap::new())?, + Factory::create_http_downloader(io.clone(), &config, indexmap::IndexMap::new())?, ))); if strpos(file!(), "phar:") == Some(0) { diff --git a/crates/shirabe/src/command/home_command.rs b/crates/shirabe/src/command/home_command.rs index 0038add..067af8f 100644 --- a/crates/shirabe/src/command/home_command.rs +++ b/crates/shirabe/src/command/home_command.rs @@ -73,10 +73,7 @@ impl HomeCommand { _output: &dyn OutputInterface, ) -> Result<i64> { let repos = self.initialize_repos()?; - // TODO(phase-b): clone_box to release self borrow held by get_io. - let io_box = self.get_io().clone(); - let io_ref = io_box.borrow(); - let io: &dyn IOInterface = &*io_ref; + let io = self.get_io().clone(); let mut return_code: i64 = 0; let packages: Vec<String> = input diff --git a/crates/shirabe/src/command/install_command.rs b/crates/shirabe/src/command/install_command.rs index 4c869f4..768f75f 100644 --- a/crates/shirabe/src/command/install_command.rs +++ b/crates/shirabe/src/command/install_command.rs @@ -11,6 +11,7 @@ use crate::console::input::InputArgument; use crate::console::input::InputOption; use crate::installer::Installer; use crate::io::IOInterface; +use crate::io::IOInterfaceImmutable; use crate::plugin::CommandEvent; use crate::plugin::PluginEvents; use crate::util::HttpDownloader; @@ -66,10 +67,7 @@ impl InstallCommand { input: &dyn InputInterface, output: &dyn OutputInterface, ) -> Result<i64> { - // TODO(phase-b): clone_box to release self borrow held by get_io. - let io_box = self.get_io().clone(); - let io_ref = io_box.borrow(); - let io: &dyn IOInterface = &*io_ref; + let io = self.get_io().clone(); if input.get_option("dev").as_bool().unwrap_or(false) { io.write_error("<warning>You are using the deprecated option \"--dev\". It has no effect and will break in Composer 3.</warning>"); @@ -115,7 +113,7 @@ impl InstallCommand { .borrow_mut() .dispatch(Some(command_event.get_name()), None); - let mut install = Installer::create(io_box.clone(), &composer_handle); + let mut install = Installer::create(io.clone(), &composer_handle); let config = composer.get_config(); let (prefer_source, prefer_dist) = diff --git a/crates/shirabe/src/command/package_discovery_trait.rs b/crates/shirabe/src/command/package_discovery_trait.rs index f036103..7da2b9a 100644 --- a/crates/shirabe/src/command/package_discovery_trait.rs +++ b/crates/shirabe/src/command/package_discovery_trait.rs @@ -178,10 +178,15 @@ pub trait PackageDiscoveryTrait { if !requirement.contains_key("version") { // determine the best version automatically - // TODO(phase-b): self.get_io() borrow conflicts with self.find_best_version_and_name_for_package - let (name, version): (String, String) = todo!( - "borrow conflict between get_io and find_best_version_and_name_for_package" - ); + let (name, version): (String, String) = self + .find_best_version_and_name_for_package( + io.clone(), + input, + requirement.get("name").map(|s| s.as_str()).unwrap_or(""), + platform_repo, + preferred_stability, + fixed, + )?; // replace package name from packagist.org requirement.insert("name".to_string(), name); @@ -431,10 +436,15 @@ pub trait PackageDiscoveryTrait { let constraint: String = match &constraint_mixed { PhpMixed::Bool(false) => { - // TODO(phase-b): self.get_io() borrow conflicts with self.find_best_version_and_name_for_package - let (_name, c): (String, String) = todo!( - "borrow conflict between get_io and find_best_version_and_name_for_package" - ); + let (_name, c): (String, String) = self + .find_best_version_and_name_for_package( + io.clone(), + input, + &package, + platform_repo, + preferred_stability, + fixed, + )?; io.write_error3( &sprintf( @@ -475,7 +485,7 @@ pub trait PackageDiscoveryTrait { /// @return array{string, string} name version fn find_best_version_and_name_for_package( &mut self, - io: &dyn IOInterface, + io: std::rc::Rc<std::cell::RefCell<dyn IOInterface>>, input: &dyn InputInterface, name: &str, platform_repo: Option<&PlatformRepository>, @@ -734,7 +744,7 @@ pub trait PackageDiscoveryTrait { if let Ok(idx) = idx_str.parse::<usize>() { if let Some(selected) = similar.get(idx) { return self.find_best_version_and_name_for_package( - io, + io.clone(), input, selected, platform_repo, diff --git a/crates/shirabe/src/command/remove_command.rs b/crates/shirabe/src/command/remove_command.rs index 9ea7329..a393f0f 100644 --- a/crates/shirabe/src/command/remove_command.rs +++ b/crates/shirabe/src/command/remove_command.rs @@ -511,10 +511,7 @@ impl RemoveCommand { .borrow_mut() .set_output_progress(!input.get_option("no-progress").as_bool().unwrap_or(false)); - // TODO(phase-b): Installer::create expects std::rc::Rc<std::cell::RefCell<dyn IOInterface>>; io here is &mut dyn IOInterface - let io_box: std::rc::Rc<std::cell::RefCell<dyn IOInterface>> = - todo!("share IOInterface as Box<dyn IOInterface>"); - let mut install = Installer::create(io_box, &composer_handle); + let mut install = Installer::create(self.get_io().clone(), &composer_handle); let update_dev_mode = !input.get_option("update-no-dev").as_bool().unwrap_or(false); let optimize = input diff --git a/crates/shirabe/src/command/require_command.rs b/crates/shirabe/src/command/require_command.rs index 93ec469..f59d60f 100644 --- a/crates/shirabe/src/command/require_command.rs +++ b/crates/shirabe/src/command/require_command.rs @@ -553,17 +553,9 @@ impl RequireCommand { .borrow_mut() .deactivate_installed_plugins(); - // try/catch/finally - // TODO(phase-b): do_update borrows io from self while also needing &mut self for state - // mutations; needs an Rc<dyn IOInterface> on self for clean sharing. - let do_update_result = self.do_update( - input, - output, - todo!("share io reference for do_update"), - &requirements, - require_key, - remove_key, - ); + let io = self.get_io().clone(); + let do_update_result = + self.do_update(input, output, io, &requirements, require_key, remove_key); let dry_run = input.get_option("dry-run").as_bool().unwrap_or(false); let result = match do_update_result { @@ -682,7 +674,7 @@ impl RequireCommand { &mut self, input: &dyn InputInterface, output: &dyn OutputInterface, - io: &dyn IOInterface, + io: std::rc::Rc<std::cell::RefCell<dyn IOInterface>>, requirements: &IndexMap<String, String>, require_key: &str, _remove_key: &str, @@ -848,12 +840,7 @@ impl RequireCommand { .borrow_mut() .set_output_progress(!input.get_option("no-progress").as_bool().unwrap_or(false)); - // TODO(phase-b): Installer::create takes std::rc::Rc<std::cell::RefCell<dyn IOInterface>> for ownership but io is a - // borrowed &dyn here; needs Rc<dyn IOInterface> for proper sharing. - let mut install = Installer::create( - todo!("share io as std::rc::Rc<std::cell::RefCell<dyn IOInterface>>"), - &composer_handle, - ); + let mut install = Installer::create(io.clone(), &composer_handle); let (prefer_source, prefer_dist) = self.get_preferred_install_options(&*composer.get_config().borrow(), input, false)?; diff --git a/crates/shirabe/src/command/self_update_command.rs b/crates/shirabe/src/command/self_update_command.rs index fc22ab7..9b960f0 100644 --- a/crates/shirabe/src/command/self_update_command.rs +++ b/crates/shirabe/src/command/self_update_command.rs @@ -143,7 +143,7 @@ impl SelfUpdateCommand { for channel in Versions::CHANNELS { if input.get_option(channel).as_bool().unwrap_or(false) { requested_channel = Some(channel.to_string()); - versions_util.set_channel(channel.to_string(), Some(&*io.borrow()))??; + versions_util.set_channel(channel.to_string(), Some(io.clone()))??; break; } } @@ -184,8 +184,7 @@ impl SelfUpdateCommand { } if input.get_option("update-keys").as_bool().unwrap_or(false) { - // TODO(phase-b): re-borrow `io` after fetch_keys conflicts with the earlier `let io = self.get_io()` borrow - let _ = io; + self.fetch_keys(io.clone(), &*config.borrow())?; return Ok(0); } @@ -656,7 +655,11 @@ RGv89BPD+2DLnJysngsvVaUCAwEAAQ==\n\ } /// @throws \Exception - pub(crate) fn fetch_keys(&self, io: &dyn IOInterface, config: &Config) -> Result<()> { + pub(crate) fn fetch_keys( + &self, + io: std::rc::Rc<std::cell::RefCell<dyn IOInterface>>, + config: &Config, + ) -> Result<()> { if !io.is_interactive() { return Err(RuntimeException { message: "Public keys can not be fetched in non-interactive mode, please run Composer interactively".to_string(), diff --git a/crates/shirabe/src/command/show_command.rs b/crates/shirabe/src/command/show_command.rs index 5a9c676..19e7712 100644 --- a/crates/shirabe/src/command/show_command.rs +++ b/crates/shirabe/src/command/show_command.rs @@ -2674,7 +2674,7 @@ impl ShowCommand { &best_stability, None, 0, - Some(&*self.get_io().borrow()), + Some(self.get_io().clone()), PhpMixed::Bool(true), )?; while let Some(ref c) = candidate { diff --git a/crates/shirabe/src/command/status_command.rs b/crates/shirabe/src/command/status_command.rs index 9f66adf..dba4cc8 100644 --- a/crates/shirabe/src/command/status_command.rs +++ b/crates/shirabe/src/command/status_command.rs @@ -8,6 +8,7 @@ use shirabe_external_packages::symfony::component::console::output::OutputInterf use crate::command::{BaseCommand, BaseCommandData, HasBaseCommandData}; use crate::console::input::InputOption; use crate::io::IOInterface; +use crate::io::IOInterfaceImmutable; use crate::package::dumper::ArrayDumper; use crate::package::version::VersionGuesser; use crate::package::version::VersionParser; @@ -86,10 +87,7 @@ impl StatusCommand { fn do_execute(&mut self, input: &dyn InputInterface) -> Result<i64> { let composer = self.require_composer(None, None)?; let mut composer = crate::command::composer_full_mut(&composer); - // TODO(phase-b): release the &mut self borrow held by get_io via clone_box. - let io_box = self.get_io().clone(); - let io_ref = io_box.borrow(); - let io: &dyn IOInterface = &*io_ref; + let io = self.get_io().clone(); let mut errors: IndexMap<String, String> = IndexMap::new(); let mut unpushed_changes: IndexMap<String, String> = IndexMap::new(); @@ -104,14 +102,14 @@ impl StatusCommand { .map(std::rc::Rc::clone) .unwrap_or_else(|| { std::rc::Rc::new(std::cell::RefCell::new(ProcessExecutor::new(Some( - io_box.clone(), + io.clone(), )))) }); let mut guesser = VersionGuesser::new( composer.get_config(), process_executor.clone(), parser.clone(), - Some(io_box.clone()), + Some(io.clone()), ); let dumper = ArrayDumper::new(); diff --git a/crates/shirabe/src/command/suggests_command.rs b/crates/shirabe/src/command/suggests_command.rs index 9105474..5006790 100644 --- a/crates/shirabe/src/command/suggests_command.rs +++ b/crates/shirabe/src/command/suggests_command.rs @@ -90,10 +90,7 @@ impl SuggestsCommand { } let installed_repo = InstalledRepository::new(installed_repos); - // TODO(phase-b): SuggestedPackagesReporter::new expects std::rc::Rc<std::cell::RefCell<dyn IOInterface>>; self.get_io() returns &mut dyn IOInterface - let io_box: std::rc::Rc<std::cell::RefCell<dyn IOInterface>> = - todo!("share IOInterface as Box<dyn IOInterface>"); - let mut reporter = SuggestedPackagesReporter::new(io_box); + let mut reporter = SuggestedPackagesReporter::new(self.get_io().clone()); let filter = input.get_argument("packages"); let mut packages = RepositoryInterface::get_packages(&installed_repo); diff --git a/crates/shirabe/src/command/update_command.rs b/crates/shirabe/src/command/update_command.rs index f1b05af..22ce506 100644 --- a/crates/shirabe/src/command/update_command.rs +++ b/crates/shirabe/src/command/update_command.rs @@ -24,6 +24,7 @@ use crate::console::input::InputOption; use crate::dependency_resolver::request::{self, Request, UpdateAllowTransitiveDeps}; use crate::installer::Installer; use crate::io::IOInterface; +use crate::io::IOInterfaceImmutable; use crate::package::loader::RootPackageLoader; use crate::package::version::VersionParser; use crate::package::version::VersionSelector; @@ -75,11 +76,7 @@ impl UpdateCommand { input: &dyn InputInterface, output: &dyn OutputInterface, ) -> Result<i64> { - // TODO(phase-b): clone_box avoids the &mut self conflict with require_composer - // below; revisit when get_io can return an Rc/Arc owned handle. - let io_box = self.get_io().clone(); - let io_ref = io_box.borrow(); - let io: &dyn IOInterface = &*io_ref; + let io = self.get_io().clone(); if input.get_option("dev").as_bool().unwrap_or(false) { io.write_error3( "<warning>You are using the deprecated option \"--dev\". It has no effect and will break in Composer 3.</warning>", @@ -248,8 +245,13 @@ impl UpdateCommand { } if input.get_option("interactive").as_bool().unwrap_or(false) { - packages = - self.get_packages_interactively(io, input, output, &composer_handle, packages)?; + packages = self.get_packages_interactively( + io.clone(), + input, + output, + &composer_handle, + packages, + )?; } if input.get_option("root-reqs").as_bool().unwrap_or(false) { @@ -312,7 +314,7 @@ impl UpdateCommand { .borrow_mut() .set_output_progress(!input.get_option("no-progress").as_bool().unwrap_or(false)); - let mut install = Installer::create(io_box.clone(), &composer_handle); + let mut install = Installer::create(io.clone(), &composer_handle); let config = composer.get_config(); let (prefer_source, prefer_dist) = @@ -432,7 +434,7 @@ impl UpdateCommand { // set_composer here requires a shared PartialComposer handle. // bump_command.set_composer(composer); result = bump_command.do_bump( - io, + io.clone(), bump_after_update.as_string() == Some("dev"), bump_after_update.as_string() == Some("no-dev"), input.get_option("dry-run").as_bool().unwrap_or(false), @@ -457,7 +459,7 @@ impl UpdateCommand { /// @return array<string> fn get_packages_interactively( &self, - io: &dyn IOInterface, + io: std::rc::Rc<std::cell::RefCell<dyn IOInterface>>, input: &dyn InputInterface, output: &dyn OutputInterface, composer: &PartialComposerHandle, diff --git a/crates/shirabe/src/command/validate_command.rs b/crates/shirabe/src/command/validate_command.rs index 12eadd7..da76eca 100644 --- a/crates/shirabe/src/command/validate_command.rs +++ b/crates/shirabe/src/command/validate_command.rs @@ -9,6 +9,7 @@ use crate::console::input::InputArgument; use crate::console::input::InputOption; use crate::factory::Factory; use crate::io::IOInterface; +use crate::io::IOInterfaceImmutable; use crate::package::loader::ValidatingArrayLoader; use crate::plugin::CommandEvent; use crate::plugin::PluginEvents; @@ -118,10 +119,7 @@ impl ValidateCommand { .map(|s| s.to_string()) .map(Ok) .unwrap_or_else(Factory::get_composer_file)?; - // TODO(phase-b): get_io() takes &mut self via BaseCommand; clone_box to release the borrow. - let io_box = self.get_io().clone(); - let io_ref = io_box.borrow(); - let io: &dyn IOInterface = &*io_ref; + let io = self.get_io().clone(); if !std::path::Path::new(&file).exists() { io.write_error(&format!("<error>{} not found.</error>", file)); @@ -132,7 +130,7 @@ impl ValidateCommand { return Ok(3); } - let validator = ConfigValidator::new(io_box.clone()); + let validator = ConfigValidator::new(io.clone()); let check_all = if input.get_option("no-check-all").as_bool().unwrap_or(false) { 0 } else { @@ -157,7 +155,7 @@ impl ValidateCommand { validator.validate(&file, check_all, check_version); let mut lock_errors: Vec<String> = vec![]; - let composer = self.create_composer_instance(input, io_box.clone(), None, false, None)?; + let composer = self.create_composer_instance(input, io.clone(), None, false, None)?; let mut composer = crate::command::composer_full_mut(&composer); let check_lock = (check_lock && composer @@ -182,7 +180,7 @@ impl ValidateCommand { } self.output_result( - io, + io.clone(), &file, &mut errors, &mut warnings, @@ -229,7 +227,7 @@ impl ValidateCommand { validator.validate(&dep_file, check_all, check_version); self.output_result( - io, + io.clone(), &package.get_pretty_name(), &mut dep_errors, &mut dep_warnings, @@ -264,7 +262,7 @@ impl ValidateCommand { fn output_result( &self, - io: &dyn IOInterface, + io: std::rc::Rc<std::cell::RefCell<dyn IOInterface>>, name: &str, errors: &mut Vec<String>, warnings: &mut Vec<String>, |
