Skip to content

Commit

Permalink
feat: #18 ✨ Support running arbitrary commands
Browse files Browse the repository at this point in the history
  • Loading branch information
ddanier committed May 20, 2024
1 parent 0a2f763 commit 98426b2
Showing 1 changed file with 19 additions and 21 deletions.
40 changes: 19 additions & 21 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,10 @@ fn main() -> Result<ExitCode, miette::ErrReport> {

// Show help if no task call was found
// (error exit if --help was not passed)
if !nur_engine.state.has_task_call {
if !nur_engine.state.has_task_call
&& parsed_nur_args.run_commands.is_none()
&& !parsed_nur_args.enter_shell
{
nur_engine.print_help(&Nur);
if parsed_nur_args.show_help {
std::process::exit(0);
Expand All @@ -115,20 +118,6 @@ fn main() -> Result<ExitCode, miette::ErrReport> {
}
}

// Ensure we have a task name
if nur_engine.state.task_name.is_none() {
return Err(miette::ErrReport::from(NurError::TaskNotFound(
nur_engine.state.task_call.join(" "),
)));
}
#[cfg(feature = "debug")]
if parsed_nur_args.debug_output {
eprintln!(
"full task name: {}",
nur_engine.state.task_name.clone().unwrap()
);
}

// Handle help
if parsed_nur_args.show_help {
if !nur_engine.state.has_task_call {
Expand Down Expand Up @@ -170,13 +159,17 @@ fn main() -> Result<ExitCode, miette::ErrReport> {

// Execute the task
let exit_code: i64;
let full_task_call = nur_engine.state.task_call.join(" ");
let run_command = if parsed_nur_args.run_commands.is_some() {
parsed_nur_args.run_commands.clone().unwrap().item
} else {
nur_engine.state.task_call.join(" ")
};
#[cfg(feature = "debug")]
if parsed_nur_args.debug_output {
eprintln!("full task call: {}", full_task_call);
eprintln!("full command call: {}", run_command);
}
if parsed_nur_args.quiet_execution {
exit_code = nur_engine.eval_and_print(full_task_call, input)?;
exit_code = nur_engine.eval_and_print(run_command, input)?;

#[cfg(feature = "debug")]
if parsed_nur_args.debug_output {
Expand All @@ -188,9 +181,13 @@ fn main() -> Result<ExitCode, miette::ErrReport> {
"Project path: {}",
nur_engine.state.project_path.to_str().unwrap()
);
println!("Executing task: {}", nur_engine.get_short_task_name());
if parsed_nur_args.run_commands.is_some() {
println!("Running command: {}", run_command);
} else {
println!("Executing task: {}", nur_engine.get_short_task_name());
}
println!();
exit_code = nur_engine.eval_and_print(full_task_call, input)?;
exit_code = nur_engine.eval_and_print(run_command, input)?;
#[cfg(feature = "debug")]
if parsed_nur_args.debug_output {
println!("Exit code {:?}", exit_code);
Expand All @@ -211,12 +208,13 @@ fn main() -> Result<ExitCode, miette::ErrReport> {
);
} else {
println!(
"{}Task execution failed{}",
"{}Task execution failed (exit code: {}){}",
if use_color {
Color::Red.prefix().to_string()
} else {
String::from("")
},
exit_code,
if use_color {
Color::Red.suffix().to_string()
} else {
Expand Down

0 comments on commit 98426b2

Please sign in to comment.