aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/command/config_command.rs
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-06-20 01:16:50 +0900
committernsfisis <nsfisis@gmail.com>2026-06-20 02:22:41 +0900
commitefec43b3b8827820cf35fe1b73d8e33f5fe84eb4 (patch)
treea62bbba72324de48be5f8e689559f8d9e288fc61 /crates/shirabe/src/command/config_command.rs
parentcac18ef73a39b4ac41fa4d6ccb753804d4c42cb7 (diff)
downloadphp-shirabe-efec43b3b8827820cf35fe1b73d8e33f5fe84eb4.tar.gz
php-shirabe-efec43b3b8827820cf35fe1b73d8e33f5fe84eb4.tar.zst
php-shirabe-efec43b3b8827820cf35fe1b73d8e33f5fe84eb4.zip
refactor: auto-fix clippy warnings
Diffstat (limited to 'crates/shirabe/src/command/config_command.rs')
-rw-r--r--crates/shirabe/src/command/config_command.rs57
1 files changed, 29 insertions, 28 deletions
diff --git a/crates/shirabe/src/command/config_command.rs b/crates/shirabe/src/command/config_command.rs
index 0752052..556dbdd 100644
--- a/crates/shirabe/src/command/config_command.rs
+++ b/crates/shirabe/src/command/config_command.rs
@@ -70,6 +70,12 @@ impl ConfigCommand {
];
}
+impl Default for ConfigCommand {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
impl ConfigCommand {
pub fn new() -> Self {
let mut command = ConfigCommand {
@@ -157,7 +163,7 @@ impl Command for ConfigCommand {
)?;
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,
@@ -299,7 +305,7 @@ impl Command for ConfigCommand {
let config_rc = self.config.as_ref().unwrap().clone();
self.get_io()
.borrow_mut()
- .load_configuration(&mut *config_rc.borrow_mut())?;
+ .load_configuration(&mut config_rc.borrow_mut())?;
}
// List the configuration of the file settings
@@ -407,12 +413,7 @@ impl Command for ConfigCommand {
let bits = explode(".", &setting_key);
// PHP: $data here is the mixed dot-segment cursor; the rest of the loop walks it.
let mut cursor: PhpMixed = if bits[0] == "extra" || bits[0] == "suggest" {
- PhpMixed::Array(
- raw_data
- .as_array()
- .map(|a| a.clone())
- .unwrap_or_else(IndexMap::new),
- )
+ PhpMixed::Array(raw_data.as_array().cloned().unwrap_or_else(IndexMap::new))
} else {
data.get("config").cloned().unwrap_or(PhpMixed::Null)
};
@@ -425,12 +426,12 @@ impl Command for ConfigCommand {
};
key_acc = Some(new_key.clone());
r#match = false;
- if let Some(arr) = cursor.as_array() {
- if let Some(v) = arr.get(&new_key) {
- r#match = true;
- cursor = (**v).clone();
- key_acc = None;
- }
+ if let Some(arr) = cursor.as_array()
+ && let Some(v) = arr.get(&new_key)
+ {
+ r#match = true;
+ cursor = (**v).clone();
+ key_acc = None;
}
}
@@ -564,7 +565,7 @@ impl Command for ConfigCommand {
};
let boolean_normalizer = |val: &PhpMixed| -> PhpMixed {
let s = val.as_string().unwrap_or("");
- PhpMixed::Bool(s != "false" && s != "" && s != "0")
+ PhpMixed::Bool(s != "false" && !s.is_empty() && s != "0")
};
// handle config values
@@ -1133,7 +1134,7 @@ impl Command for ConfigCommand {
.unwrap()
.add_config_setting(&key, PhpMixed::Array(obj));
} else if matches[1] == "custom-headers" {
- if values.len() == 0 {
+ if values.is_empty() {
return Err(RuntimeException {
message: "Expected at least one argument (header), got none".to_string(),
code: 0,
@@ -1279,7 +1280,7 @@ impl ConfigCommand {
&mut self,
key: &str,
callbacks: &(ValidatorFn, NormalizerFn),
- values: &Vec<String>,
+ values: &[String],
method: &str,
) -> anyhow::Result<()> {
let (validator, normalizer) = callbacks;
@@ -1349,7 +1350,7 @@ impl ConfigCommand {
&mut self,
key: &str,
callbacks: &(ValidatorFn, NormalizerFn),
- values: &Vec<String>,
+ values: &[String],
method: &str,
) -> anyhow::Result<()> {
let (validator, normalizer) = callbacks;
@@ -1551,7 +1552,7 @@ fn boolean_validator(val: &PhpMixed) -> PhpMixed {
fn boolean_normalizer(val: &PhpMixed) -> PhpMixed {
let s = val.as_string().unwrap_or("");
- PhpMixed::Bool(s != "false" && s != "" && s != "0")
+ PhpMixed::Bool(s != "false" && !s.is_empty() && s != "0")
}
fn build_unique_config_values() -> IndexMap<String, (ValidatorFn, NormalizerFn)> {
@@ -1624,7 +1625,7 @@ fn build_unique_config_values() -> IndexMap<String, (ValidatorFn, NormalizerFn)>
if s == "prompt" {
PhpMixed::String("prompt".to_string())
} else {
- PhpMixed::Bool(s != "false" && s != "" && s != "0")
+ PhpMixed::Bool(s != "false" && !s.is_empty() && s != "0")
}
}),
),
@@ -1772,7 +1773,7 @@ fn build_unique_config_values() -> IndexMap<String, (ValidatorFn, NormalizerFn)>
if s == "stash" {
PhpMixed::String("stash".to_string())
} else {
- PhpMixed::Bool(s != "false" && s != "" && s != "0")
+ PhpMixed::Bool(s != "false" && !s.is_empty() && s != "0")
}
}),
),
@@ -1845,7 +1846,7 @@ fn build_unique_config_values() -> IndexMap<String, (ValidatorFn, NormalizerFn)>
if s == "dev" || s == "no-dev" {
val.clone()
} else {
- PhpMixed::Bool(s != "false" && s != "" && s != "0")
+ PhpMixed::Bool(s != "false" && !s.is_empty() && s != "0")
}
}),
),
@@ -1924,7 +1925,7 @@ fn build_unique_config_values() -> IndexMap<String, (ValidatorFn, NormalizerFn)>
if s == "php-only" {
PhpMixed::String("php-only".to_string())
} else {
- PhpMixed::Bool(s != "false" && s != "" && s != "0")
+ PhpMixed::Bool(s != "false" && !s.is_empty() && s != "0")
}
}),
),
@@ -1949,7 +1950,7 @@ fn build_unique_config_values() -> IndexMap<String, (ValidatorFn, NormalizerFn)>
if s == "prompt" {
PhpMixed::String("prompt".to_string())
} else {
- PhpMixed::Bool(s != "false" && s != "" && s != "0")
+ PhpMixed::Bool(s != "false" && !s.is_empty() && s != "0")
}
}),
),
@@ -2197,10 +2198,10 @@ fn key_first_key(value: &PhpMixed) -> Option<String> {
if let Some(arr) = value.as_array() {
return arr.keys().next().cloned();
}
- if let Some(list) = value.as_list() {
- if !list.is_empty() {
- return Some("0".to_string());
- }
+ if let Some(list) = value.as_list()
+ && !list.is_empty()
+ {
+ return Some("0".to_string());
}
None
}