summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-03-27 11:18:44 +0200
committerPaul Buetow <paul@buetow.org>2026-03-27 11:18:44 +0200
commitfabc390ff20c217326746140d65c6e7022b66dd8 (patch)
tree217afa091e4b50edf2fe326e76638581dc822ef5
parentaa7f5bcf38129f79bb08c4e1f396647807fe8fef (diff)
Split askcli info and add commands
-rw-r--r--internal/askcli/command_add.go (renamed from internal/askcli/command_info_add.go)75
-rw-r--r--internal/askcli/command_info.go84
2 files changed, 84 insertions, 75 deletions
diff --git a/internal/askcli/command_info_add.go b/internal/askcli/command_add.go
index 3bb57fb..cda0637 100644
--- a/internal/askcli/command_info_add.go
+++ b/internal/askcli/command_add.go
@@ -3,86 +3,11 @@ package askcli
import (
"bytes"
"context"
- "encoding/json"
"fmt"
"io"
"strings"
)
-func (d *Dispatcher) handleInfo(ctx context.Context, args []string, stdout, stderr io.Writer) (int, error) {
- tasks, code, err := d.infoTasks(ctx, args, stderr)
- if err != nil {
- writeInfoError(stderr, err)
- return code, nil
- }
- if d.jsonOutput {
- data, err := json.Marshal(tasks)
- if err != nil {
- fmt.Fprintf(stderr, "error: failed to marshal JSON: %v\n", err)
- return 1, nil
- }
- stdout.Write(data)
- io.WriteString(stdout, "\n")
- } else {
- allUUIDs := append([]string{tasks[0].UUID}, tasks[0].Depends...)
- aliases, err := ensureTaskAliasesForUUIDs(allUUIDs)
- if err != nil {
- fmt.Fprintf(stderr, "error: failed to load task aliases: %v\n", err)
- return 1, nil
- }
- io.WriteString(stdout, FormatTaskInfo(tasks[0], displayTaskAlias(tasks[0].UUID, aliases), aliases))
- }
- return 0, nil
-}
-
-func (d *Dispatcher) infoTasks(ctx context.Context, args []string, stderr io.Writer) ([]TaskExport, int, error) {
- if len(args) >= 2 {
- _, tasks, code, err := d.resolveTaskSelector(ctx, args[1], stderr)
- return tasks, code, err
- }
- return d.startedInfoTasks(ctx, stderr)
-}
-
-func (d *Dispatcher) startedInfoTasks(ctx context.Context, stderr io.Writer) ([]TaskExport, int, error) {
- tasks, code, err := d.exportTasks(ctx, []string{"started", "export"}, stderr)
- if err != nil {
- return nil, code, err
- }
- switch len(tasks) {
- case 0:
- return nil, 1, fmt.Errorf("no started task found")
- case 1:
- return tasks, 0, nil
- default:
- return nil, 1, fmt.Errorf("multiple started tasks found; pass an ID or UUID explicitly")
- }
-}
-
-func (d *Dispatcher) exportTasks(ctx context.Context, args []string, stderr io.Writer) ([]TaskExport, int, error) {
- var outBuf bytes.Buffer
- code, err := d.runner.Run(ctx, args, nil, &outBuf, stderr)
- if code != 0 {
- return nil, code, err
- }
- tasks, err := ParseTaskExport(&outBuf)
- if err != nil {
- return nil, 1, err
- }
- if len(tasks) == 0 && len(args) > 0 && strings.HasPrefix(args[0], "uuid:") {
- return nil, 1, fmt.Errorf("task not found")
- }
- return tasks, 0, nil
-}
-
-func writeInfoError(stderr io.Writer, err error) {
- msg := err.Error()
- if strings.HasPrefix(msg, "error:") {
- io.WriteString(stderr, msg+"\n")
- return
- }
- fmt.Fprintf(stderr, "error: %v\n", err)
-}
-
func (d *Dispatcher) handleAdd(ctx context.Context, args []string, stdout, stderr io.Writer) (int, error) {
if len(args) < 2 {
io.WriteString(stderr, "error: ask add requires a description\n")
diff --git a/internal/askcli/command_info.go b/internal/askcli/command_info.go
new file mode 100644
index 0000000..37fb49b
--- /dev/null
+++ b/internal/askcli/command_info.go
@@ -0,0 +1,84 @@
+package askcli
+
+import (
+ "bytes"
+ "context"
+ "encoding/json"
+ "fmt"
+ "io"
+ "strings"
+)
+
+func (d *Dispatcher) handleInfo(ctx context.Context, args []string, stdout, stderr io.Writer) (int, error) {
+ tasks, code, err := d.infoTasks(ctx, args, stderr)
+ if err != nil {
+ writeInfoError(stderr, err)
+ return code, nil
+ }
+ if d.jsonOutput {
+ data, err := json.Marshal(tasks)
+ if err != nil {
+ fmt.Fprintf(stderr, "error: failed to marshal JSON: %v\n", err)
+ return 1, nil
+ }
+ stdout.Write(data)
+ io.WriteString(stdout, "\n")
+ } else {
+ allUUIDs := append([]string{tasks[0].UUID}, tasks[0].Depends...)
+ aliases, err := ensureTaskAliasesForUUIDs(allUUIDs)
+ if err != nil {
+ fmt.Fprintf(stderr, "error: failed to load task aliases: %v\n", err)
+ return 1, nil
+ }
+ io.WriteString(stdout, FormatTaskInfo(tasks[0], displayTaskAlias(tasks[0].UUID, aliases), aliases))
+ }
+ return 0, nil
+}
+
+func (d *Dispatcher) infoTasks(ctx context.Context, args []string, stderr io.Writer) ([]TaskExport, int, error) {
+ if len(args) >= 2 {
+ _, tasks, code, err := d.resolveTaskSelector(ctx, args[1], stderr)
+ return tasks, code, err
+ }
+ return d.startedInfoTasks(ctx, stderr)
+}
+
+func (d *Dispatcher) startedInfoTasks(ctx context.Context, stderr io.Writer) ([]TaskExport, int, error) {
+ tasks, code, err := d.exportTasks(ctx, []string{"started", "export"}, stderr)
+ if err != nil {
+ return nil, code, err
+ }
+ switch len(tasks) {
+ case 0:
+ return nil, 1, fmt.Errorf("no started task found")
+ case 1:
+ return tasks, 0, nil
+ default:
+ return nil, 1, fmt.Errorf("multiple started tasks found; pass an ID or UUID explicitly")
+ }
+}
+
+func (d *Dispatcher) exportTasks(ctx context.Context, args []string, stderr io.Writer) ([]TaskExport, int, error) {
+ var outBuf bytes.Buffer
+ code, err := d.runner.Run(ctx, args, nil, &outBuf, stderr)
+ if code != 0 {
+ return nil, code, err
+ }
+ tasks, err := ParseTaskExport(&outBuf)
+ if err != nil {
+ return nil, 1, err
+ }
+ if len(tasks) == 0 && len(args) > 0 && strings.HasPrefix(args[0], "uuid:") {
+ return nil, 1, fmt.Errorf("task not found")
+ }
+ return tasks, 0, nil
+}
+
+func writeInfoError(stderr io.Writer, err error) {
+ msg := err.Error()
+ if strings.HasPrefix(msg, "error:") {
+ io.WriteString(stderr, msg+"\n")
+ return
+ }
+ fmt.Fprintf(stderr, "error: %v\n", err)
+}