diff options
| -rw-r--r-- | internal/askcli/command_info_add.go | 14 | ||||
| -rw-r--r-- | internal/askcli/command_list.go | 13 | ||||
| -rw-r--r-- | internal/askcli/command_urgency.go | 13 | ||||
| -rw-r--r-- | internal/askcli/dispatch.go | 16 | ||||
| -rw-r--r-- | internal/version.go | 2 |
5 files changed, 53 insertions, 5 deletions
diff --git a/internal/askcli/command_info_add.go b/internal/askcli/command_info_add.go index 2680163..025b104 100644 --- a/internal/askcli/command_info_add.go +++ b/internal/askcli/command_info_add.go @@ -3,6 +3,8 @@ package askcli import ( "bytes" "context" + "encoding/json" + "fmt" "io" "strings" ) @@ -27,7 +29,17 @@ func (d Dispatcher) handleInfo(ctx context.Context, args []string, stdout, stder io.WriteString(stderr, "error: task not found\n") return 1, nil } - io.WriteString(stdout, FormatTaskInfo(tasks[0])) + 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 { + io.WriteString(stdout, FormatTaskInfo(tasks[0])) + } return 0, nil } diff --git a/internal/askcli/command_list.go b/internal/askcli/command_list.go index 54eaafc..ef8c22f 100644 --- a/internal/askcli/command_list.go +++ b/internal/askcli/command_list.go @@ -3,6 +3,7 @@ package askcli import ( "bytes" "context" + "encoding/json" "fmt" "io" "sort" @@ -51,7 +52,17 @@ func (d Dispatcher) handleListWithFilters(ctx context.Context, initialFilters, e } return tasks[i].Urgency > tasks[j].Urgency }) - io.WriteString(stdout, FormatTaskList(tasks)) + 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 { + io.WriteString(stdout, FormatTaskList(tasks)) + } return 0, nil } diff --git a/internal/askcli/command_urgency.go b/internal/askcli/command_urgency.go index 9dd162e..a228f27 100644 --- a/internal/askcli/command_urgency.go +++ b/internal/askcli/command_urgency.go @@ -3,6 +3,7 @@ package askcli import ( "bytes" "context" + "encoding/json" "fmt" "io" "sort" @@ -22,6 +23,16 @@ func (d Dispatcher) handleUrgency(ctx context.Context, stdout, stderr io.Writer) sort.Slice(tasks, func(i, j int) bool { return tasks[i].Urgency > tasks[j].Urgency }) - io.WriteString(stdout, FormatTaskList(tasks)) + 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 { + io.WriteString(stdout, FormatTaskList(tasks)) + } return 0, nil } diff --git a/internal/askcli/dispatch.go b/internal/askcli/dispatch.go index 312a6cf..19e9b58 100644 --- a/internal/askcli/dispatch.go +++ b/internal/askcli/dispatch.go @@ -11,7 +11,8 @@ type Runner interface { } type Dispatcher struct { - runner Runner + runner Runner + jsonOutput bool } func NewDispatcher(runner Runner) *Dispatcher { @@ -23,6 +24,19 @@ func NewDispatcher(runner Runner) *Dispatcher { } func (d Dispatcher) Dispatch(ctx context.Context, args []string, stdin io.Reader, stdout, stderr io.Writer) (int, error) { + // Extract --json flag before dispatching. + var jsonOutput bool + var filtered []string + for _, a := range args { + if a == "--json" { + jsonOutput = true + } else { + filtered = append(filtered, a) + } + } + args = filtered + d.jsonOutput = jsonOutput + if len(args) == 0 { return d.handleList(ctx, []string{"list"}, stdout, stderr) } diff --git a/internal/version.go b/internal/version.go index 30b7ba7..737f4fa 100644 --- a/internal/version.go +++ b/internal/version.go @@ -1,4 +1,4 @@ // Package internal provides the Hexai semantic version identifier used by CLI and LSP binaries. package internal -const Version = "0.25.11" +const Version = "0.25.12" |
