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

Add option to only return task_id on add #152

Merged
merged 1 commit into from
Dec 19, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions client/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ pub enum SubCommand {
/// As soon as one of the dependencies fails, this task will fail as well.
#[clap(name = "after", short, long)]
dependencies: Vec<usize>,

/// Only return the task id instead of a text.
/// This is useful when scripting and working with dependencies.
#[clap(short, long)]
print_task_id: bool,
},
/// Remove tasks from the list.
/// Running or paused tasks need to be killed first.
Expand Down
2 changes: 2 additions & 0 deletions client/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ impl Client {
group,
delay_until,
dependencies,
print_task_id,
} => {
let cwd_pathbuf = current_dir()?;
let cwd = cwd_pathbuf
Expand All @@ -292,6 +293,7 @@ impl Client {
group: group.clone(),
enqueue_at: *delay_until,
dependencies: dependencies.to_vec(),
print_task_id: *print_task_id,
}))
}
SubCommand::Remove { task_ids } => {
Expand Down
1 change: 1 addition & 0 deletions client/commands/restart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ pub async fn restart(
group: task.group.clone(),
enqueue_at: None,
dependencies: Vec::new(),
print_task_id: false,
});

// Send the cloned task to the daemon and abort on any failure messages.
Expand Down
4 changes: 3 additions & 1 deletion daemon/instructions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ fn add_task(message: AddMessage, sender: &Sender<Message>, state: &SharedState)
.expect(SENDER_ERR);
}
// Create the customized response for the client.
let message = if let Some(enqueue_at) = message.enqueue_at {
let message = if message.print_task_id {
task_id.to_string()
} else if let Some(enqueue_at) = message.enqueue_at {
format!(
"New task added (id {}). It will be enqueued at {}",
task_id,
Expand Down
1 change: 1 addition & 0 deletions shared/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ pub struct AddMessage {
pub group: Option<String>,
pub enqueue_at: Option<DateTime<Local>>,
pub dependencies: Vec<usize>,
pub print_task_id: bool,
}

#[derive(Clone, Debug, Deserialize, Serialize)]
Expand Down