Skip to content

Commit

Permalink
Add --custom-command (r-darwish#927)
Browse files Browse the repository at this point in the history
* Add --custom-command
Fixes r-darwish#922

* fix
  • Loading branch information
r-darwish authored May 7, 2022
1 parent fdf03f6 commit c166d51
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
{
"type": "promptString",
"id": "step",
"description": "step nname",
"description": "step name",
}
]
}
12 changes: 12 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,10 @@ pub struct CommandLineArgs {
#[clap(long = "only", arg_enum)]
only: Vec<Step>,

/// Run only specific custom commands
#[clap(long = "custom-commands")]
custom_commands: Vec<String>,

/// Set environment variables
#[clap(long = "env")]
env: Vec<String>,
Expand Down Expand Up @@ -876,4 +880,12 @@ impl Config {
pub fn display_time(&self) -> bool {
self.config_file.display_time.unwrap_or(true)
}

pub fn should_run_custom_command(&self, name: &str) -> bool {
if self.opt.custom_commands.is_empty() {
return true;
}

self.opt.custom_commands.iter().any(|s| s == name)
}
}
8 changes: 5 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,9 +360,11 @@ fn run() -> Result<()> {

if let Some(commands) = config.commands() {
for (name, command) in commands {
runner.execute(Step::CustomCommands, name, || {
generic::run_custom_command(name, command, &ctx)
})?;
if config.should_run_custom_command(name) {
runner.execute(Step::CustomCommands, name, || {
generic::run_custom_command(name, command, &ctx)
})?;
}
}
}

Expand Down

0 comments on commit c166d51

Please sign in to comment.