Skip to content

Commit

Permalink
background_task: Fix quoted commands and fix deprecation of implicit …
Browse files Browse the repository at this point in the history
…spreading and clarify docs (nushell#752)
  • Loading branch information
RGBCube committed Feb 5, 2024
1 parent 302fd84 commit 14e77c7
Showing 1 changed file with 21 additions and 18 deletions.
39 changes: 21 additions & 18 deletions modules/background_task/task.nu
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,24 @@ export def spawn [
$args = ($args | prepend ["--label" $label])
}

let source_code = (
let source_path = mktemp --tmpdir --suffix "-nu-task"

(
view source $command
| str trim --left --char "{"
| str trim --right --char "}"
)
| save --force $source_path

(pueue add --print-task-id $args $"nu --config '($nu.config-path)' --env-config '($nu.env-path)' --commands '($source_code)'")
(pueue add --print-task-id ...$args $"nu --config '($nu.config-path)' --env-config '($nu.env-path)' ($source_path)")
}

# Remove tasks from the queue.
# Running or paused tasks need to be killed first.
export def remove [
...ids: int # IDs of the tasks to remove from the status list.
] {
pueue remove $ids
pueue remove ...$ids
}

# Switches the queue position of two tasks.
Expand All @@ -80,7 +83,7 @@ export def switch [
export def stash [
...ids: int # IDs of the tasks to stash.
] {
pueue stash $ids
pueue stash ...$ids
}

# Queue stashed tasks for execution.
Expand All @@ -94,7 +97,7 @@ export def queue [
[]
}

pueue enqueue $args $ids
pueue enqueue ...$args ...$ids
}

# Resume operation of specific tasks or groups of tasks.
Expand All @@ -115,7 +118,7 @@ export def start [
$args = ($args | prepend "--all")
}

pueue start $args
pueue start ...$args
}

# Restart failed or successful task(s).
Expand Down Expand Up @@ -167,7 +170,7 @@ export def restart [
$args = ($args | prepend "--edit-label")
}

pueue restart $args $ids
pueue restart ...$args ...$ids
}

# Either pause a running tasks or a specific groups of tasks.
Expand All @@ -193,7 +196,7 @@ export def pause [
$args = ($args | prepend "--wait")
}

pueue pause $args $ids
pueue pause ...$args ...$ids
}

# Kill specific running tasks or whole task groups.
Expand All @@ -217,7 +220,7 @@ export def kill [
$args = ($args | prepend ["--signal" $signal])
}

pueue kill $args $ids
pueue kill ...$args ...$ids
}

# Send something to a task. Useful for sending confirmations such as "y\n".
Expand Down Expand Up @@ -251,7 +254,7 @@ export def edit [
$args = ($args | prepend "--label")
}

pueue edit $args $id
pueue edit ...$args $id
}

# Use this to add or remove groups.
Expand All @@ -272,7 +275,7 @@ export def "group add" [
[]
}

pueue group add $args $name
pueue group add ...$args $name
}

# Remove a group with a name.
Expand Down Expand Up @@ -302,7 +305,7 @@ export def status [
}
}

# Display the log output of finished tasks.
# Display the output of tasks.
#
# Only the last few lines will be shown by default for multiple tasks.
# If you want to follow the output, use `--tail/-t`.
Expand Down Expand Up @@ -336,15 +339,15 @@ export def log [
[]
}

pueue follow $ids
pueue follow ...$ids
} else {
let args = if $last != null {
["--lines" $last]
} else {
[]
}

process_raw (pueue log --full --json $args $ids)
process_raw (pueue log --full --json ...$args ...$ids)
| first
}
} else {
Expand All @@ -359,7 +362,7 @@ export def log [
[]
}

process_raw (pueue log --full --json $args $ids)
process_raw (pueue log --full --json ...$args ...$ids)
}
}

Expand Down Expand Up @@ -388,7 +391,7 @@ export def wait [
$args = ($args | prepend ["--status" $status])
}

pueue wait $args $ids
pueue wait ...$args ...$ids
}

# Remove tasks from the status list.
Expand All @@ -405,7 +408,7 @@ export def clean [
$args = ($args | prepend ["--group" $group])
}

pueue clean $args
pueue clean ...$args
}

# Shutdown pueue and thus this module.
Expand All @@ -427,5 +430,5 @@ export def set-parallel-limit [
[]
}

pueue parallel $args $max
pueue parallel ...$args $max
}

0 comments on commit 14e77c7

Please sign in to comment.