Skip to content

Commit

Permalink
Merge pull request #81 from bertjwregeer/feature/exit-without-exec
Browse files Browse the repository at this point in the history
Add support for exiting with an exit code
  • Loading branch information
digitalresistor committed Oct 2, 2022
2 parents c73a44b + 3c7c862 commit b73673a
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "barnacle"
version = "0.2.0"
version = "0.3.0"
edition = "2021"
authors = ["Bert JW Regeer <[email protected]>"]
license = "ISC"
Expand Down
6 changes: 5 additions & 1 deletion src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,13 @@ pub struct Cli {
pub output: PathBuf,

/// The command + arguments to execute once template is rendered
#[arg(required(true))]
#[arg(group = "command_or_exit", required(true))]
pub command: Vec<String>,

/// Exit with error code, exclusive with a command to exeute
#[arg(short, long, group = "command_or_exit", required(true))]
pub exit: Option<u8>,

/// Turn debugging information on
#[arg(short, long, action = clap::ArgAction::Count)]
pub verbose: u8,
Expand Down
6 changes: 6 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,11 @@ fn main() {

fs::write(&matches.output, output).expect("Failed to write output file");

// If we have an exit code, use it
if let Some(exit) = matches.exit {
std::process::exit(exit.into());
}

// Otherwise we execute the command provided on the CLI
exec(&matches.command);
}

0 comments on commit b73673a

Please sign in to comment.