summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-04-08 22:19:50 +0300
committerPaul Buetow <paul@buetow.org>2026-04-08 22:19:50 +0300
commitbbc50bef3c04d6b727d69600834510b8ae3cbe11 (patch)
treee1a84bc30c6bd9c3cda6cd518c5e96e9e096bb86
parent42226b12e7a172810bf785cef4cbb4fb41e2da3d (diff)
task 6: reorder task helpers before public API
-rw-r--r--internal/task/task.go72
1 files changed, 36 insertions, 36 deletions
diff --git a/internal/task/task.go b/internal/task/task.go
index 42fbb30..4e6d787 100644
--- a/internal/task/task.go
+++ b/internal/task/task.go
@@ -41,6 +41,42 @@ type Task struct {
Annotations []Annotation `json:"annotations"`
}
+func run(args ...string) error {
+ if dbg.writer != nil {
+ fmt.Fprintln(dbg.writer, "task "+strings.Join(args, " "))
+ }
+ cmd := exec.Command("task", args...)
+
+ // Capture stderr to provide better error messages
+ var stderr bytes.Buffer
+ cmd.Stderr = &stderr
+
+ if err := cmd.Run(); err != nil {
+ // Include stderr output in the error message
+ if stderr.Len() > 0 {
+ return fmt.Errorf("%v: %s", err, strings.TrimSpace(stderr.String()))
+ }
+ return err
+ }
+ return nil
+}
+
+// modifyTask runs a modify command with validation
+func modifyTask(id int, args ...string) error {
+ if id <= 0 {
+ return fmt.Errorf("invalid task ID: %d", id)
+ }
+ return run(append([]string{strconv.Itoa(id), "modify"}, args...)...)
+}
+
+// simpleTaskCommand runs a simple command on a task with validation
+func simpleTaskCommand(id int, command string) error {
+ if id <= 0 {
+ return fmt.Errorf("invalid task ID: %d", id)
+ }
+ return run(strconv.Itoa(id), command)
+}
+
// debugConfig groups the optional debug-logging state for the task package.
// Collecting related vars into a struct makes the mutable state explicit and
// allows the logger to be swapped or reset cleanly without touching unrelated
@@ -149,42 +185,6 @@ func Export(filters ...string) ([]Task, error) {
return tasks, nil
}
-func run(args ...string) error {
- if dbg.writer != nil {
- fmt.Fprintln(dbg.writer, "task "+strings.Join(args, " "))
- }
- cmd := exec.Command("task", args...)
-
- // Capture stderr to provide better error messages
- var stderr bytes.Buffer
- cmd.Stderr = &stderr
-
- if err := cmd.Run(); err != nil {
- // Include stderr output in the error message
- if stderr.Len() > 0 {
- return fmt.Errorf("%v: %s", err, strings.TrimSpace(stderr.String()))
- }
- return err
- }
- return nil
-}
-
-// modifyTask runs a modify command with validation
-func modifyTask(id int, args ...string) error {
- if id <= 0 {
- return fmt.Errorf("invalid task ID: %d", id)
- }
- return run(append([]string{strconv.Itoa(id), "modify"}, args...)...)
-}
-
-// simpleTaskCommand runs a simple command on a task with validation
-func simpleTaskCommand(id int, command string) error {
- if id <= 0 {
- return fmt.Errorf("invalid task ID: %d", id)
- }
- return run(strconv.Itoa(id), command)
-}
-
// SetStatus changes the status of the task with the given id.
func SetStatus(id int, status string) error {
return modifyTask(id, "status:"+status)