Skip to content

Commit

Permalink
chore: some minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
pplmx committed Jan 31, 2024
1 parent c08d898 commit 68265ce
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,14 @@ pub fn get_agent_ip() -> io::Result<String> {

// Set or unset a configuration for a given tool.
fn set_config(key: &str, value: Option<&str>, tool: &str) {
let mut args = match value {
Some(v) => vec!["config", "--global", key, v],
None => vec!["config", "--global", "--unset", key],
// Use match instead of if else to construct the args vector
let args = match (value, tool) {
(Some(v), "git") => vec!["config", "--global", key, v],
(None, "git") => vec!["config", "--global", "--unset", key],
(Some(v), NPM) => vec!["config", "set", key, v],
(None, NPM) => vec!["config", "delete", key],
_ => panic!("Invalid tool: {}", tool),
};
if tool == NPM {
args = match value {
Some(v) => vec!["config", "set", key, v],
None => vec!["config", "delete", key],
};
}
if let Err(e) = Command::new(tool).args(&args).output() {
eprintln!("Failed to set config for {}: {}", tool, e);
}
Expand Down

0 comments on commit 68265ce

Please sign in to comment.