Skip to content

Commit 1b0f17b

Browse files
committed
tasks: rename run modes
1 parent 825a566 commit 1b0f17b

File tree

5 files changed

+49
-81
lines changed

5 files changed

+49
-81
lines changed

devenv-tasks/src/lib.rs

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -81,25 +81,25 @@ pub struct TaskConfig {
8181
inputs: Option<serde_json::Value>,
8282
}
8383

84-
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)]
85-
#[serde(rename_all = "snake_case")] // TODO: which case?
86-
pub enum TaskRunMode {
84+
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Deserialize, Serialize, clap::ValueEnum)]
85+
#[serde(rename_all = "snake_case")]
86+
pub enum RunMode {
8787
#[default]
88-
/// Run only the specified task
88+
/// Run only the specified task without dependencies
8989
Single,
90-
/// Run the specified task and all tasks after it
91-
WithAfter,
92-
/// Run the specified task and all tasks before it
93-
WithBefore,
94-
/// Run the specified task and all tasks before and after it (full dependency graph)
95-
WithBeforeAndAfter,
90+
/// Run the specified task and all tasks that depend on it (downstream tasks)
91+
After,
92+
/// Run all dependency tasks first, then the specified task (upstream tasks)
93+
Before,
94+
/// Run the complete dependency graph (upstream and downstream tasks)
95+
All,
9696
}
9797

9898
#[derive(Deserialize, Serialize)]
9999
pub struct Config {
100100
pub tasks: Vec<TaskConfig>,
101101
pub roots: Vec<String>,
102-
pub run_mode: TaskRunMode,
102+
pub run_mode: RunMode,
103103
}
104104

105105
#[derive(Serialize)]
@@ -401,7 +401,7 @@ struct Tasks {
401401
tasks_order: Vec<NodeIndex>,
402402
notify_finished: Arc<Notify>,
403403
notify_ui: Arc<Notify>,
404-
run_mode: TaskRunMode,
404+
run_mode: RunMode,
405405
}
406406

407407
impl Tasks {
@@ -504,11 +504,11 @@ impl Tasks {
504504

505505
// Find nodes to include based on run_mode
506506
match self.run_mode {
507-
TaskRunMode::Single => {
507+
RunMode::Single => {
508508
// Only include the root nodes themselves
509509
visited = self.roots.iter().cloned().collect();
510510
}
511-
TaskRunMode::WithAfter => {
511+
RunMode::After => {
512512
// Include root nodes and all tasks that come after (successor nodes)
513513
while let Some(node) = to_visit.pop() {
514514
if visited.insert(node) {
@@ -522,7 +522,7 @@ impl Tasks {
522522
}
523523
}
524524
}
525-
TaskRunMode::WithBefore => {
525+
RunMode::Before => {
526526
// Include root nodes and all tasks that come before (predecessor nodes)
527527
while let Some(node) = to_visit.pop() {
528528
if visited.insert(node) {
@@ -536,7 +536,7 @@ impl Tasks {
536536
}
537537
}
538538
}
539-
TaskRunMode::WithBeforeAndAfter => {
539+
RunMode::All => {
540540
// Include the complete connected subgraph (all dependencies in both directions)
541541
while let Some(node) = to_visit.pop() {
542542
if visited.insert(node) {
@@ -1098,7 +1098,7 @@ mod test {
10981098
assert_matches!(
10991099
Config::try_from(json!({
11001100
"roots": [],
1101-
"run_mode": "with_before_and_after",
1101+
"run_mode": "all",
11021102
"tasks": [{
11031103
"name": task.to_string()
11041104
}]
@@ -1119,7 +1119,7 @@ mod test {
11191119
assert_matches!(
11201120
Config::try_from(serde_json::json!({
11211121
"roots": [],
1122-
"run_mode": "with_before_and_after",
1122+
"run_mode": "all",
11231123
"tasks": [{
11241124
"name": task.to_string()
11251125
}]
@@ -1150,7 +1150,7 @@ mod test {
11501150
let tasks = Tasks::new(
11511151
Config::try_from(json!({
11521152
"roots": ["myapp:task_1", "myapp:task_4"],
1153-
"run_mode": "with_before_and_after",
1153+
"run_mode": "all",
11541154
"tasks": [
11551155
{
11561156
"name": "myapp:task_1",
@@ -1195,7 +1195,7 @@ mod test {
11951195
let result = Tasks::new(
11961196
Config::try_from(json!({
11971197
"roots": ["myapp:task_1"],
1198-
"run_mode": "with_before_and_after",
1198+
"run_mode": "all",
11991199
"tasks": [
12001200
{
12011201
"name": "myapp:task_1",
@@ -1243,7 +1243,7 @@ mod test {
12431243
Tasks::new(
12441244
Config::try_from(json!({
12451245
"roots": [root],
1246-
"run_mode": "with_before_and_after",
1246+
"run_mode": "all",
12471247
"tasks": [
12481248
{
12491249
"name": "myapp:task_1",
@@ -1286,7 +1286,7 @@ mod test {
12861286
let tasks = Tasks::new(
12871287
Config::try_from(json!({
12881288
"roots": ["myapp:task_1"],
1289-
"run_mode": "with_before_and_after",
1289+
"run_mode": "all",
12901290
"tasks": [
12911291
{
12921292
"name": "myapp:task_1",
@@ -1327,7 +1327,7 @@ mod test {
13271327
let result = Tasks::new(
13281328
Config::try_from(json!({
13291329
"roots": ["myapp:task_1"],
1330-
"run_mode": "with_before_and_after",
1330+
"run_mode": "all",
13311331
"tasks": [
13321332
{
13331333
"name": "myapp:task_1",
@@ -1396,7 +1396,7 @@ mod test {
13961396
let tasks = Tasks::new(
13971397
Config::try_from(json!({
13981398
"roots": ["myapp:task_1"],
1399-
"run_mode": "with_before_and_after",
1399+
"run_mode": "all",
14001400
"tasks": [
14011401
{
14021402
"name": "myapp:task_1",
@@ -1441,7 +1441,7 @@ mod test {
14411441
let tasks = Tasks::new(
14421442
Config::try_from(json!({
14431443
"roots": ["myapp:task_1"],
1444-
"run_mode": "with_before_and_after",
1444+
"run_mode": "all",
14451445
"tasks": [
14461446
{
14471447
"name": "myapp:task_1",
@@ -1486,7 +1486,7 @@ mod test {
14861486
let tasks = Tasks::new(
14871487
Config::try_from(json!({
14881488
"roots": ["myapp:task_1"],
1489-
"run_mode": "with_before_and_after",
1489+
"run_mode": "all",
14901490
"tasks": [
14911491
{
14921492
"name": "myapp:task_1",
@@ -1533,7 +1533,7 @@ mod test {
15331533
let tasks = Tasks::new(
15341534
Config::try_from(json!({
15351535
"roots": ["myapp:task_3"],
1536-
"run_mode": "with_before_and_after",
1536+
"run_mode": "all",
15371537
"tasks": [
15381538
{
15391539
"name": "myapp:task_1",
@@ -1579,7 +1579,7 @@ mod test {
15791579
let tasks = Tasks::new(
15801580
Config::try_from(json!({
15811581
"roots": ["myapp:task_2"],
1582-
"run_mode": "with_before_and_after",
1582+
"run_mode": "all",
15831583
"tasks": [
15841584
{
15851585
"name": "myapp:task_1",
@@ -1623,7 +1623,7 @@ mod test {
16231623
let tasks = Tasks::new(
16241624
Config::try_from(json!({
16251625
"roots": ["myapp:task_2"],
1626-
"run_mode": "with_before_and_after",
1626+
"run_mode": "all",
16271627
"tasks": [
16281628
{
16291629
"name": "myapp:task_1",
@@ -1679,7 +1679,7 @@ echo '{"key": "value3"}' > $DEVENV_TASK_OUTPUT_FILE
16791679
let tasks = Tasks::new(
16801680
Config::try_from(json!({
16811681
"roots": ["myapp:task_3"],
1682-
"run_mode": "with_before_and_after",
1682+
"run_mode": "all",
16831683
"tasks": [
16841684
{
16851685
"name": "myapp:task_1",
@@ -1738,7 +1738,7 @@ fi
17381738
let tasks = Tasks::new(
17391739
Config::try_from(json!({
17401740
"roots": ["myapp:task_1", "myapp:task_2"],
1741-
"run_mode": "with_before_and_after",
1741+
"run_mode": "all",
17421742
"tasks": [
17431743
{
17441744
"name": "myapp:task_1",

devenv-tasks/src/main.rs

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use clap::{Parser, Subcommand};
2-
use devenv_tasks::{Config, TaskConfig, TasksUi};
2+
use devenv_tasks::{Config, RunMode, TaskConfig, TasksUi};
33
use std::env;
44

55
#[derive(Parser)]
@@ -12,32 +12,13 @@ struct Args {
1212
command: Command,
1313
}
1414

15-
#[derive(clap::ValueEnum, Debug, Clone, Copy)]
16-
enum RunMode {
17-
Single,
18-
WithAfter,
19-
WithBefore,
20-
WithBeforeAndAfter,
21-
}
22-
23-
impl From<RunMode> for devenv_tasks::TaskRunMode {
24-
fn from(mode: RunMode) -> Self {
25-
match mode {
26-
RunMode::Single => devenv_tasks::TaskRunMode::Single,
27-
RunMode::WithAfter => devenv_tasks::TaskRunMode::WithAfter,
28-
RunMode::WithBefore => devenv_tasks::TaskRunMode::WithBefore,
29-
RunMode::WithBeforeAndAfter => devenv_tasks::TaskRunMode::WithBeforeAndAfter,
30-
}
31-
}
32-
}
33-
3415
#[derive(Subcommand)]
3516
enum Command {
3617
Run {
3718
#[clap()]
3819
roots: Vec<String>,
3920

40-
#[clap(long, value_enum, default_value_t = RunMode::Single)]
21+
#[clap(long, value_enum, default_value_t = RunMode::Single, help = "The execution mode for tasks (affects dependency resolution)")]
4122
mode: RunMode,
4223
},
4324
Export {
@@ -58,7 +39,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
5839
let config = Config {
5940
tasks,
6041
roots,
61-
run_mode: mode.into(),
42+
run_mode: mode,
6243
};
6344

6445
// Pass quiet flag to TasksUi (which will set the env var internally)

devenv/src/cli.rs

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::log::LogFormat;
22
use clap::{crate_version, Parser, Subcommand};
3+
use devenv_tasks::RunMode;
34
use std::path::PathBuf;
45
use tracing::error;
56

@@ -361,34 +362,16 @@ pub enum TasksCommand {
361362
Run {
362363
tasks: Vec<String>,
363364

364-
#[arg(short, long, help = "The mode to use when running tasks (FIX)")]
365+
#[arg(
366+
short,
367+
long,
368+
help = "The execution mode for tasks (affects dependency resolution)",
369+
value_enum
370+
)]
365371
mode: RunMode,
366372
},
367373
}
368374

369-
#[derive(clap::ValueEnum, Debug, Clone, Copy)]
370-
pub enum RunMode {
371-
/// Run only the specified task
372-
Single,
373-
/// Run the specified task and all tasks after it
374-
WithAfter,
375-
/// Run the specified task and all tasks before it
376-
WithBefore,
377-
/// Run the specified task and all tasks before and after it (full dependency graph)
378-
WithBeforeAndAfter,
379-
}
380-
381-
impl From<RunMode> for devenv_tasks::TaskRunMode {
382-
fn from(mode: RunMode) -> Self {
383-
match mode {
384-
RunMode::Single => devenv_tasks::TaskRunMode::Single,
385-
RunMode::WithAfter => devenv_tasks::TaskRunMode::WithAfter,
386-
RunMode::WithBefore => devenv_tasks::TaskRunMode::WithBefore,
387-
RunMode::WithBeforeAndAfter => devenv_tasks::TaskRunMode::WithBeforeAndAfter,
388-
}
389-
}
390-
}
391-
392375
#[derive(Subcommand, Clone)]
393376
#[clap(
394377
about = "Build, copy, or run a container. https://devenv.sh/containers/",

devenv/src/devenv.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,11 @@ impl Devenv {
615615
Ok(self.has_processes.unwrap())
616616
}
617617

618-
pub async fn tasks_run(&mut self, roots: Vec<String>, mode: cli::RunMode) -> Result<()> {
618+
pub async fn tasks_run(
619+
&mut self,
620+
roots: Vec<String>,
621+
run_mode: devenv_tasks::RunMode,
622+
) -> Result<()> {
619623
self.assemble(false).await?;
620624
if roots.is_empty() {
621625
bail!("No tasks specified.");
@@ -637,7 +641,7 @@ impl Devenv {
637641
let config = tasks::Config {
638642
roots,
639643
tasks,
640-
run_mode: mode.into(),
644+
run_mode,
641645
};
642646
debug!(
643647
"Tasks config: {}",

src/modules/tasks.nix

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,13 +154,13 @@ in
154154
};
155155
};
156156
enterShell = ''
157-
${config.task.package}/bin/devenv-tasks run devenv:enterShell --mode with_before_and_after
157+
${config.task.package}/bin/devenv-tasks run devenv:enterShell --mode all
158158
if [ -f "$DEVENV_DOTFILE/load-exports" ]; then
159159
source "$DEVENV_DOTFILE/load-exports"
160160
fi
161161
'';
162162
enterTest = ''
163-
${config.task.package}/bin/devenv-tasks run devenv:enterTest --mode with_before_and_after
163+
${config.task.package}/bin/devenv-tasks run devenv:enterTest --mode all
164164
'';
165165
};
166166
}

0 commit comments

Comments
 (0)