Skip to content

Commit

Permalink
feat: append additional args to script invocation, if any
Browse files Browse the repository at this point in the history
  • Loading branch information
Yakiyo committed Jul 31, 2023
1 parent 92e94d1 commit 50b467c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
4 changes: 4 additions & 0 deletions crates/cli/src/commands.rs
Expand Up @@ -87,6 +87,10 @@ impl AddArgs {
pub struct RunArgs {
/// A pre-defined package script.
pub command: String,

/// Any additional arguments passed after the script name
pub args: Vec<String>,

/// You can use the --if-present flag to avoid exiting with a non-zero exit code when the
/// script is undefined. This lets you run potentially undefined scripts without breaking the
/// execution chain.
Expand Down
7 changes: 6 additions & 1 deletion crates/cli/src/lib.rs
Expand Up @@ -70,7 +70,12 @@ async fn run_commands(cli: Cli) -> Result<()> {
Subcommands::Run(args) => {
let package_json = PackageJson::from_path(&package_json_path)?;
if let Some(script) = package_json.get_script(&args.command, args.if_present)? {
execute_shell(script)?;
let mut command = script.to_string();
// append an empty space between script and additional args
command.push(' ');
// then append the additional args
command.push_str(args.args.join(" ").as_str());
execute_shell(command.trim())?;
}
}
Subcommands::Start => {
Expand Down

0 comments on commit 50b467c

Please sign in to comment.