Skip to content

Commit 6de796a

Browse files
authored
Feature/eirikb/multi config fix (#205)
* Fix multi-config runner It needs special special handling in order to support both gg aliases and direct commands! * Update readme to show advanced-ish setup of alias sequential run
1 parent 03fa940 commit 6de796a

File tree

2 files changed

+58
-7
lines changed

2 files changed

+58
-7
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,8 @@ Aliases support `&&` for sequential execution:
121121

122122
```toml
123123
[aliases]
124-
build-and-test = "gradle clean build && npm test"
124+
clean-build = "gradle clean build"
125+
build-and-test = "clean-build && npm test"
125126
```
126127

127128
### Viewing Configuration

src/stage4/src/main.rs

Lines changed: 56 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -255,13 +255,63 @@ async fn main() -> ExitCode {
255255
for command_args in alias_commands {
256256
println!("Executing: {}", command_args.join(" "));
257257

258-
let mut gg_args =
259-
vec![env::current_exe().unwrap().to_string_lossy().to_string()];
260-
gg_args.extend(command_args.iter().map(|s| s.to_string()));
258+
if command_args.is_empty() {
259+
continue;
260+
}
261261

262-
let status = std::process::Command::new(&gg_args[0])
263-
.args(&gg_args[1..])
264-
.status();
262+
let execute_as_gg_command = |args: &[String]| {
263+
let mut gg_args = vec![env::args().next().unwrap_or_else(|| {
264+
env::current_exe().unwrap().to_string_lossy().to_string()
265+
})];
266+
gg_args.extend(args.iter().map(|s| s.to_string()));
267+
std::process::Command::new(&gg_args[0])
268+
.args(&gg_args[1..])
269+
.status()
270+
};
271+
272+
let status = if command_args.len() == 1 {
273+
if let Some(nested_alias_commands) =
274+
config.resolve_alias_with_and(&command_args[0])
275+
{
276+
let mut all_success = true;
277+
for nested_command_args in nested_alias_commands {
278+
if nested_command_args.is_empty() {
279+
continue;
280+
}
281+
let nested_status =
282+
std::process::Command::new(&nested_command_args[0])
283+
.args(&nested_command_args[1..])
284+
.status();
285+
match nested_status {
286+
Ok(exit_status) => {
287+
if !exit_status.success() {
288+
all_success = false;
289+
break;
290+
}
291+
}
292+
Err(_) => {
293+
all_success = false;
294+
break;
295+
}
296+
}
297+
}
298+
if all_success {
299+
std::process::Command::new("true").status()
300+
} else {
301+
std::process::Command::new("false").status()
302+
}
303+
} else if let Some(nested_alias_args) =
304+
config.resolve_alias(&command_args[0])
305+
{
306+
execute_as_gg_command(&nested_alias_args)
307+
} else {
308+
execute_as_gg_command(&command_args)
309+
}
310+
} else {
311+
std::process::Command::new(&command_args[0])
312+
.args(&command_args[1..])
313+
.status()
314+
};
265315

266316
match status {
267317
Ok(exit_status) => {

0 commit comments

Comments
 (0)