Skip to content

Commit fa52961

Browse files
committed
refactor: simplify platform specific logic
1 parent cba59a7 commit fa52961

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

src/main.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -90,30 +90,27 @@ fn run_command_in_directory(options: &Options, path: &PathBuf) -> Result<(), Err
9090
println!("Entering '{}'", path.display());
9191
}
9292

93-
let shell_binary = if cfg!(target_os = "windows") {
94-
"cmd"
93+
let (shell_binary, shell_arg) = if cfg!(target_os = "windows") {
94+
("cmd", "/C")
9595
} else {
96-
"/bin/sh"
97-
};
98-
99-
let shell_arg = if cfg!(target_os = "windows") {
100-
"/C".to_string()
101-
} else {
102-
"-c".to_string()
96+
("/bin/sh", "-c")
10397
};
10498

10599
let shell_command = options.command.join(" ");
106100

107101
if options.dry_run {
108102
println!(
109-
"dry-run: would run '{shell_binary} {shell_arg} \"{shell_command}\"' in '{}'",
103+
"dry-run: would run '{} {} \"{}\"' in '{}'",
104+
shell_binary,
105+
shell_arg,
106+
shell_command,
110107
path.display()
111108
);
112109
return Ok(());
113110
}
114111

115112
let status = std::process::Command::new(shell_binary)
116-
.args([shell_arg, shell_command])
113+
.args([shell_arg, &shell_command])
117114
.current_dir(path)
118115
.status();
119116

0 commit comments

Comments
 (0)