Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: customisable task entrypoint #86

Merged
merged 6 commits into from
Jul 21, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion src/actors/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ pub struct CommandActor {
started_at: DateTime<Local>,
env: Vec<(String, String)>,
pipes: Vec<Pipe>,
entrypoint: Option<String>,
}

impl CommandActor {
Expand Down Expand Up @@ -164,6 +165,7 @@ impl CommandActor {
verbose,
env.into_iter().collect(),
task_pipes,
op.entrypoint.clone(),
)
.start();

Expand All @@ -187,6 +189,7 @@ impl CommandActor {
verbose: bool,
env: Vec<(String, String)>,
pipes: Vec<Pipe>,
entrypoint: Option<String>,
) -> Self {
Self {
op_name,
Expand All @@ -203,6 +206,7 @@ impl CommandActor {
started_at: Local::now(),
env,
pipes,
entrypoint,
}
}

Expand Down Expand Up @@ -260,7 +264,28 @@ impl CommandActor {
let exec = Exec::cmd("cmd").args(&["/c", args]);
zifeo marked this conversation as resolved.
Show resolved Hide resolved

#[cfg(not(target_os = "windows"))]
let exec = Exec::cmd("bash").args(&["-c", args]);
let exec = {
// Defaults to bash if no entrypoint is provided.
let mut entrypoint = match &self.entrypoint {
Some(e) => e.to_string(),
None => "bash -c".to_string(),
};
let mut nargs: Vec<&str> = vec![];

// This is needed because the shell can interpret "bash -c" as a single command rather than "bash" as a command then "-c" as an argument.
let t = &entrypoint.clone();
if entrypoint.contains(' ') {
zifeo marked this conversation as resolved.
Show resolved Hide resolved
let c = t.split(' ').collect::<Vec<&str>>();
let a = &c[0].clone();
entrypoint = a.to_string();
for i in &c[1..] {
nargs.push(*i);
}
nargs.push(&args);
}

Exec::cmd(entrypoint).args(&nargs)
};

let mut p = exec
.cwd(&self.cwd)
Expand Down
1 change: 1 addition & 0 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ impl<T: std::clone::Clone> Lift<T> {
pub struct Task {
pub workdir: Option<String>,
pub command: String,
pub entrypoint: Option<String>,

#[serde(default)]
pub watch: Lift<String>,
Expand Down
8 changes: 8 additions & 0 deletions whiz.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ dodo:
color:
command: python3 -c 'print(u"\u001b[31mHelloWorld\u001b[0m")'

color2:
command: 'print(u"\033[92mHelloWorld\033[0m")'
entrypoint: 'python3 -c'

what_shell:
command: echo $(which $0)
entrypoint: 'sh -c'

watch_parent:
workdir: src
command: ls
Expand Down