diff options
Diffstat (limited to 'crates/shirabe/src/command/config_command.rs')
| -rw-r--r-- | crates/shirabe/src/command/config_command.rs | 74 |
1 files changed, 38 insertions, 36 deletions
diff --git a/crates/shirabe/src/command/config_command.rs b/crates/shirabe/src/command/config_command.rs index 135b47f..342797c 100644 --- a/crates/shirabe/src/command/config_command.rs +++ b/crates/shirabe/src/command/config_command.rs @@ -126,7 +126,7 @@ impl ConfigCommand { self.initialize(input.clone(), output)?; let auth_config_file = - self.get_auth_config_file(input.clone(), &*self.config.as_ref().unwrap().borrow()); + self.get_auth_config_file(input.clone(), &*self.config.as_ref().unwrap().borrow())?; let auth_config_file_jf = std::rc::Rc::new(std::cell::RefCell::new(JsonFile::new( auth_config_file, @@ -137,7 +137,7 @@ impl ConfigCommand { self.auth_config_source = Some(JsonConfigSource::new(auth_config_file_jf, true)); // Initialize the global file if it's not there, ignoring any warnings or notices - if input.borrow().get_option("global").as_bool() == Some(true) + if input.borrow().get_option("global")?.as_bool() == Some(true) && !self.auth_config_file.as_ref().unwrap().borrow().exists() { touch(self.auth_config_file.as_ref().unwrap().borrow().get_path()); @@ -182,7 +182,7 @@ impl ConfigCommand { output: std::rc::Rc<std::cell::RefCell<dyn OutputInterface>>, ) -> anyhow::Result<i64> { // Open file in editor - if input.borrow().get_option("editor").as_bool() == Some(true) { + if input.borrow().get_option("editor")?.as_bool() == Some(true) { let mut editor = Platform::get_env("EDITOR"); if editor.is_none() || editor.as_deref() == Some("") { if Platform::is_windows() { @@ -202,7 +202,7 @@ impl ConfigCommand { editor = Some(escapeshellcmd(&editor.unwrap())); } - let file = if input.borrow().get_option("auth").as_bool() == Some(true) { + let file = if input.borrow().get_option("auth")?.as_bool() == Some(true) { self.auth_config_file .as_ref() .unwrap() @@ -234,7 +234,7 @@ impl ConfigCommand { return Ok(0); } - if input.borrow().get_option("global").as_bool() != Some(true) { + if input.borrow().get_option("global")?.as_bool() != Some(true) { let config_read = self.config_file.as_ref().unwrap().borrow_mut().read()?; let config_map = match config_read { PhpMixed::Array(m) => m @@ -272,7 +272,7 @@ impl ConfigCommand { } // List the configuration of the file settings - if input.borrow().get_option("list").as_bool() == Some(true) { + if input.borrow().get_option("list")?.as_bool() == Some(true) { let all_map = self.config.as_ref().unwrap().borrow_mut().all(0)?; let raw_map = self.config.as_ref().unwrap().borrow().raw(); let to_mixed = |m: IndexMap<String, PhpMixed>| -> PhpMixed { @@ -283,20 +283,20 @@ impl ConfigCommand { to_mixed(raw_map), output, None, - input.borrow().get_option("source").as_bool() == Some(true), + input.borrow().get_option("source")?.as_bool() == Some(true), ); return Ok(0); } - let setting_key_arg = input.borrow().get_argument("setting-key"); + let setting_key_arg = input.borrow().get_argument("setting-key")?; let setting_key = match setting_key_arg.as_string() { Some(s) => s.to_string(), None => return Ok(0), }; // If the user enters in a config variable, parse it and save to file - let setting_values_raw = input.borrow().get_argument("setting-value"); + let setting_values_raw = input.borrow().get_argument("setting-value")?; let setting_values: Vec<String> = setting_values_raw .as_list() .map(|l| { @@ -305,7 +305,7 @@ impl ConfigCommand { .collect() }) .unwrap_or_default(); - if !setting_values.is_empty() && input.borrow().get_option("unset").as_bool() == Some(true) + if !setting_values.is_empty() && input.borrow().get_option("unset")?.as_bool() == Some(true) { return Err(RuntimeException { message: "You can not combine a setting value with --unset".to_string(), @@ -315,7 +315,8 @@ impl ConfigCommand { } // show the value if no value is provided - if setting_values.is_empty() && input.borrow().get_option("unset").as_bool() != Some(true) { + if setting_values.is_empty() && input.borrow().get_option("unset")?.as_bool() != Some(true) + { let properties: Vec<&'static str> = Self::CONFIGURABLE_PACKAGE_PROPERTIES.to_vec(); let mut properties_defaults: IndexMap<String, PhpMixed> = IndexMap::new(); properties_defaults.insert("type".to_string(), PhpMixed::String("library".to_string())); @@ -421,7 +422,7 @@ impl ConfigCommand { { value = self.config.as_ref().unwrap().borrow_mut().get_with_flags( &setting_key, - if input.borrow().get_option("absolute").as_bool() == Some(true) { + if input.borrow().get_option("absolute")?.as_bool() == Some(true) { 0 } else { Config::RELATIVE_PATHS @@ -504,7 +505,7 @@ impl ConfigCommand { }; let mut source_of_config_value = String::new(); - if input.borrow().get_option("source").as_bool() == Some(true) { + if input.borrow().get_option("source")?.as_bool() == Some(true) { source_of_config_value = format!(" ({})", source); } @@ -542,7 +543,7 @@ impl ConfigCommand { let multi_config_values = build_multi_config_values(); // allow unsetting audit config entirely - if input.borrow().get_option("unset").as_bool() == Some(true) && setting_key == "audit" { + if input.borrow().get_option("unset")?.as_bool() == Some(true) && setting_key == "audit" { self.config_source .as_mut() .unwrap() @@ -551,7 +552,7 @@ impl ConfigCommand { return Ok(0); } - if input.borrow().get_option("unset").as_bool() == Some(true) + if input.borrow().get_option("unset")?.as_bool() == Some(true) && (unique_config_values.contains_key(&setting_key) || multi_config_values.contains_key(&setting_key)) { @@ -596,7 +597,7 @@ impl ConfigCommand { ) .unwrap_or(false) { - if input.borrow().get_option("unset").as_bool() == Some(true) { + if input.borrow().get_option("unset")?.as_bool() == Some(true) { self.config_source .as_mut() .unwrap() @@ -637,7 +638,7 @@ impl ConfigCommand { ) .unwrap_or(false) { - if input.borrow().get_option("unset").as_bool() == Some(true) { + if input.borrow().get_option("unset")?.as_bool() == Some(true) { self.config_source .as_mut() .unwrap() @@ -668,7 +669,7 @@ impl ConfigCommand { let unique_props = build_unique_props(); let multi_props = build_multi_props(); - if input.borrow().get_option("global").as_bool() == Some(true) + if input.borrow().get_option("global")?.as_bool() == Some(true) && (unique_props.contains_key(&setting_key) || multi_props.contains_key(&setting_key) || strpos(&setting_key, "extra.") == Some(0)) @@ -679,7 +680,7 @@ impl ConfigCommand { } .into()); } - if input.borrow().get_option("unset").as_bool() == Some(true) + if input.borrow().get_option("unset")?.as_bool() == Some(true) && (unique_props.contains_key(&setting_key) || multi_props.contains_key(&setting_key)) { self.config_source @@ -709,7 +710,7 @@ impl ConfigCommand { ) .unwrap_or(false) { - if input.borrow().get_option("unset").as_bool() == Some(true) { + if input.borrow().get_option("unset")?.as_bool() == Some(true) { self.config_source .as_mut() .unwrap() @@ -731,7 +732,7 @@ impl ConfigCommand { self.config_source.as_mut().unwrap().add_repository( &matches[1], PhpMixed::Array(repo), - input.borrow().get_option("append").as_bool() == Some(true), + input.borrow().get_option("append")?.as_bool() == Some(true), ); return Ok(0); @@ -747,7 +748,7 @@ impl ConfigCommand { self.config_source.as_mut().unwrap().add_repository( &matches[1], PhpMixed::Bool(false), - input.borrow().get_option("append").as_bool() == Some(true), + input.borrow().get_option("append")?.as_bool() == Some(true), ); return Ok(0); @@ -757,7 +758,7 @@ impl ConfigCommand { self.config_source.as_mut().unwrap().add_repository( &matches[1], value, - input.borrow().get_option("append").as_bool() == Some(true), + input.borrow().get_option("append")?.as_bool() == Some(true), ); return Ok(0); @@ -774,7 +775,7 @@ impl ConfigCommand { // handle extra let mut matches: IndexMap<CaptureKey, String> = IndexMap::new(); if Preg::is_match3("/^extra\\.(.+)/", &setting_key, Some(&mut matches)).unwrap_or(false) { - if input.borrow().get_option("unset").as_bool() == Some(true) { + if input.borrow().get_option("unset")?.as_bool() == Some(true) { self.config_source .as_mut() .unwrap() @@ -784,9 +785,9 @@ impl ConfigCommand { } let mut value = PhpMixed::String(values[0].clone()); - if input.borrow().get_option("json").as_bool() == Some(true) { + if input.borrow().get_option("json")?.as_bool() == Some(true) { value = JsonFile::parse_json(Some(&values[0]), Some("composer.json"))?; - if input.borrow().get_option("merge").as_bool() == Some(true) { + if input.borrow().get_option("merge")?.as_bool() == Some(true) { let current_value_outer = self.config_file.as_ref().unwrap().borrow_mut().read()?; let bits = explode(".", &setting_key); @@ -833,7 +834,7 @@ impl ConfigCommand { // handle suggest let mut matches: IndexMap<CaptureKey, String> = IndexMap::new(); if Preg::is_match3("/^suggest\\.(.+)/", &setting_key, Some(&mut matches)).unwrap_or(false) { - if input.borrow().get_option("unset").as_bool() == Some(true) { + if input.borrow().get_option("unset")?.as_bool() == Some(true) { self.config_source .as_mut() .unwrap() @@ -855,7 +856,7 @@ impl ConfigCommand { setting_key.as_str().into(), &vec!["suggest".to_string(), "extra".to_string()].into(), true, - ) && input.borrow().get_option("unset").as_bool() == Some(true) + ) && input.borrow().get_option("unset")?.as_bool() == Some(true) { self.config_source .as_mut() @@ -869,7 +870,7 @@ impl ConfigCommand { let mut matches: IndexMap<CaptureKey, String> = IndexMap::new(); if Preg::is_match3("/^platform\\.(.+)/", &setting_key, Some(&mut matches)).unwrap_or(false) { - if input.borrow().get_option("unset").as_bool() == Some(true) { + if input.borrow().get_option("unset")?.as_bool() == Some(true) { self.config_source .as_mut() .unwrap() @@ -892,7 +893,8 @@ impl ConfigCommand { } // handle unsetting platform - if setting_key == "platform" && input.borrow().get_option("unset").as_bool() == Some(true) { + if setting_key == "platform" && input.borrow().get_option("unset")?.as_bool() == Some(true) + { self.config_source .as_mut() .unwrap() @@ -911,7 +913,7 @@ impl ConfigCommand { .into(), true, ) { - if input.borrow().get_option("unset").as_bool() == Some(true) { + if input.borrow().get_option("unset")?.as_bool() == Some(true) { self.config_source .as_mut() .unwrap() @@ -926,7 +928,7 @@ impl ConfigCommand { .map(|s| Box::new(PhpMixed::String(s.clone()))) .collect(), ); - if input.borrow().get_option("json").as_bool() == Some(true) { + if input.borrow().get_option("json")?.as_bool() == Some(true) { value = JsonFile::parse_json(Some(&values[0]), Some("composer.json"))?; if !is_array(&value) { return Err(RuntimeException { @@ -937,7 +939,7 @@ impl ConfigCommand { } } - if input.borrow().get_option("merge").as_bool() == Some(true) { + if input.borrow().get_option("merge")?.as_bool() == Some(true) { let current_config = self.config_file.as_ref().unwrap().borrow_mut().read()?; let key_suffix = str_replace("audit.", "", &setting_key); let current_value = current_config @@ -990,7 +992,7 @@ impl ConfigCommand { // handle auth let mut matches: IndexMap<CaptureKey, String> = IndexMap::new(); if Preg::is_match3("/^(bitbucket-oauth|github-oauth|gitlab-oauth|gitlab-token|http-basic|custom-headers|bearer|forgejo-token)\\.(.+)/", &setting_key, Some(&mut matches)).unwrap_or(false) { - if input.borrow().get_option("unset").as_bool() == Some(true) { + if input.borrow().get_option("unset")?.as_bool() == Some(true) { self.auth_config_source.as_mut().unwrap().remove_config_setting(&format!("{}.{}", matches[1], matches[2])); self.config_source.as_mut().unwrap().remove_config_setting(&format!("{}.{}", matches[1], matches[2])); @@ -1096,7 +1098,7 @@ impl ConfigCommand { // handle script let mut matches: IndexMap<CaptureKey, String> = IndexMap::new(); if Preg::is_match3("/^scripts\\.(.+)/", &setting_key, Some(&mut matches)).unwrap_or(false) { - if input.borrow().get_option("unset").as_bool() == Some(true) { + if input.borrow().get_option("unset")?.as_bool() == Some(true) { self.config_source .as_mut() .unwrap() @@ -1124,7 +1126,7 @@ impl ConfigCommand { } // handle unsetting other top level properties - if input.borrow().get_option("unset").as_bool() == Some(true) { + if input.borrow().get_option("unset")?.as_bool() == Some(true) { self.config_source .as_mut() .unwrap() |
