Skip to content

Commit b7ba4fc

Browse files
authored
0.2.13 (#46)
* changes * do not use glob mod path * appease clippy
1 parent 71a2ca7 commit b7ba4fc

File tree

12 files changed

+351
-146
lines changed

12 files changed

+351
-146
lines changed

Cargo.lock

Lines changed: 13 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
authors = ["Ľubomír Kurčák <[email protected]>"]
33
name = "tend"
44
description = "Quickly spin up/down groups of command-line tasks with automated recovery"
5-
version = "0.2.12"
5+
version = "0.2.13"
66
edition = "2021"
77
license = "MIT OR Apache-2.0"
88
repository = "https://github.com/lubomirkurcak/tend"
@@ -18,7 +18,7 @@ keywords = ["cli", "task", "automation", "recovery", "tend"]
1818

1919
[dependencies]
2020
anyhow = "1.0.89"
21-
clap = { version = "4.5.18", features = ["derive"] }
21+
clap = { version = "4.5.20", features = ["derive"] }
2222
colored = "2.1.0"
2323
dirs-next = "2.0.0"
2424
folktime = "0.2.1"

src/args.rs

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,72 @@ pub enum Commands {
116116
#[arg(help = "Use -- to separate program arguments from job arguments.")]
117117
args: Vec<String>,
118118
},
119+
#[command(about = "Enable jobs")]
120+
Enable {
121+
#[arg(help = "Name of the job to enable", exclusive = true)]
122+
name: Option<String>,
123+
#[arg(
124+
short,
125+
long,
126+
help = "Enable all jobs",
127+
conflicts_with = "group",
128+
conflicts_with = "job"
129+
)]
130+
all: bool,
131+
#[arg(
132+
short,
133+
long,
134+
help = "Enable jobs from specific group(s)",
135+
num_args = 1..,
136+
conflicts_with = "all",
137+
use_value_delimiter = true
138+
)]
139+
group: Vec<String>,
140+
#[arg(
141+
short,
142+
long,
143+
help = "Enable specific job(s)",
144+
num_args = 1..,
145+
conflicts_with = "all",
146+
use_value_delimiter = true
147+
)]
148+
job: Vec<String>,
149+
#[arg(alias = "except", short, long, help = "Exclude specific job(s)", num_args = 1.., use_value_delimiter = true)]
150+
exclude: Vec<String>,
151+
},
152+
#[command(about = "Disable jobs")]
153+
Disable {
154+
#[arg(help = "Name of the job to disable", exclusive = true)]
155+
name: Option<String>,
156+
#[arg(
157+
short,
158+
long,
159+
help = "Disable all jobs",
160+
conflicts_with = "group",
161+
conflicts_with = "job"
162+
)]
163+
all: bool,
164+
#[arg(
165+
short,
166+
long,
167+
help = "Disable jobs from specific group(s)",
168+
num_args = 1..,
169+
conflicts_with = "all",
170+
use_value_delimiter = true
171+
)]
172+
group: Vec<String>,
173+
#[arg(
174+
short,
175+
long,
176+
help = "Disable specific job(s)",
177+
num_args = 1..,
178+
conflicts_with = "all",
179+
use_value_delimiter = true
180+
)]
181+
job: Vec<String>,
182+
#[arg(alias = "except", short, long, help = "Exclude specific job(s)", num_args = 1.., use_value_delimiter = true)]
183+
exclude: Vec<String>,
184+
},
119185
#[command(alias = "e", alias = "ed", about = "Edit a job")]
120186
Edit {
121187
#[arg(help = "Name of the job to edit")]

src/colors.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use colored::{ColoredString, Colorize};
33
pub trait Tend {
44
fn thick(&self) -> ColoredString;
55
fn job(&self) -> ColoredString;
6-
fn program(&self) -> ColoredString;
6+
// fn program(&self) -> ColoredString;
77
fn time_value(&self) -> ColoredString;
88
fn success(&self) -> ColoredString;
99
fn failure(&self) -> ColoredString;
@@ -18,9 +18,7 @@ impl Tend for str {
1818
self.bold().cyan()
1919
}
2020

21-
fn program(&self) -> ColoredString {
22-
self.bold().yellow()
23-
}
21+
// fn program(&self) -> ColoredString { self.bold().yellow() }
2422

2523
fn time_value(&self) -> ColoredString {
2624
self.bold().yellow()

src/job/event.rs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ use serde::{Deserialize, Serialize};
55
use super::Job;
66

77
#[derive(PartialEq, Eq)]
8-
pub enum ControlFlow {
8+
pub enum ControlFlow<'a> {
99
Nothing,
10-
RestartCommand,
11-
StopJob,
10+
RestartCommand(&'a str),
11+
StopJob(&'a str),
1212
}
1313

1414
#[derive(Default, Debug, Clone, Serialize, Deserialize, clap::ValueEnum, Copy, PartialEq, Eq)]
@@ -63,14 +63,16 @@ pub enum Action {
6363

6464
#[derive(Debug, Clone, Serialize, Deserialize)]
6565
pub struct Hook {
66+
pub name: String,
6667
pub event: Event,
6768
pub action: Action,
6869
}
6970

7071
impl Job {
71-
pub fn stdout_line_callback(&self, line: &str, verbose: bool) -> ControlFlow {
72-
for hook in self.event_hooks.values() {
72+
pub fn stdout_line_callback<'a>(&'a self, line: &str, verbose: bool) -> ControlFlow<'a> {
73+
for hook in &self.event_hooks {
7374
let Hook {
75+
name,
7476
event: Event::DetectSubstring { stream, contains },
7577
action,
7678
} = hook;
@@ -86,18 +88,19 @@ impl Job {
8688
}
8789

8890
return match action {
89-
Action::Restart => ControlFlow::RestartCommand,
90-
Action::Stop => ControlFlow::StopJob,
91+
Action::Restart => ControlFlow::RestartCommand(name),
92+
Action::Stop => ControlFlow::StopJob(name),
9193
};
9294
}
9395
}
9496

9597
ControlFlow::Nothing
9698
}
9799

98-
pub fn stderr_line_callback(&self, line: &str, verbose: bool) -> ControlFlow {
99-
for hook in self.event_hooks.values() {
100+
pub fn stderr_line_callback<'a>(&'a self, line: &str, verbose: bool) -> ControlFlow<'a> {
101+
for hook in &self.event_hooks {
100102
let Hook {
103+
name,
101104
event: Event::DetectSubstring { stream, contains },
102105
action,
103106
} = hook;
@@ -113,8 +116,8 @@ impl Job {
113116
}
114117

115118
return match action {
116-
Action::Restart => ControlFlow::RestartCommand,
117-
Action::Stop => ControlFlow::StopJob,
119+
Action::Restart => ControlFlow::RestartCommand(name),
120+
Action::Stop => ControlFlow::StopJob(name),
118121
};
119122
}
120123
}

src/job/filter.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,23 @@ pub enum Filter {
1212
}
1313

1414
impl Filter {
15+
pub fn matches_name(&self, job_name: &str) -> bool {
16+
match self {
17+
Self::All { exclude } => !exclude.iter().any(|x| x == job_name),
18+
Self::Subset {
19+
groups: _,
20+
jobs,
21+
exclude,
22+
} => {
23+
if exclude.iter().any(|x| x == job_name) {
24+
return false;
25+
}
26+
27+
jobs.iter().any(|x| x == job_name)
28+
}
29+
}
30+
}
31+
1532
pub fn matches(&self, job: &Job) -> bool {
1633
match self {
1734
Self::All { exclude } => !exclude.contains(&job.name),

0 commit comments

Comments
 (0)