summaryrefslogtreecommitdiff
path: root/internal/askcli/command_write.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-03-22 19:47:52 +0200
committerPaul Buetow <paul@buetow.org>2026-03-22 19:47:52 +0200
commit23e9ab91c1e18f889eac4c0c5d5fd9daaeff7f0d (patch)
tree02966f7d2ff099f8d3d0cf4c33478b367e98ae53 /internal/askcli/command_write.go
parent97cb0462aad67bf1e9558b340f5ef2f5a72eb662 (diff)
Implement write subcommands: annotate, start, stop, done, priority, tag, modify, denotate
Diffstat (limited to 'internal/askcli/command_write.go')
-rw-r--r--internal/askcli/command_write.go165
1 files changed, 165 insertions, 0 deletions
diff --git a/internal/askcli/command_write.go b/internal/askcli/command_write.go
new file mode 100644
index 0000000..b39b64a
--- /dev/null
+++ b/internal/askcli/command_write.go
@@ -0,0 +1,165 @@
+package askcli
+
+import (
+ "bytes"
+ "context"
+ "io"
+ "strings"
+)
+
+func (d Dispatcher) handleDenotate(ctx context.Context, args []string, stdout, stderr io.Writer) (int, error) {
+ if len(args) < 3 {
+ io.WriteString(stderr, "error: ask denotate requires a UUID and text argument\n")
+ return 1, nil
+ }
+ uuid := args[1]
+ if IsNumericID(uuid) {
+ io.WriteString(stderr, RejectNumericID())
+ return 1, nil
+ }
+ text := args[2]
+ var outBuf bytes.Buffer
+ code, err := d.runner.Run(ctx, []string{"denotate", uuid, text}, nil, &outBuf, io.Discard)
+ if code != 0 {
+ return code, err
+ }
+ io.WriteString(stdout, FormatSuccess(uuid))
+ return 0, nil
+}
+
+func (d Dispatcher) handleModify(ctx context.Context, args []string, stdout, stderr io.Writer) (int, error) {
+ if len(args) < 3 {
+ io.WriteString(stderr, "error: ask modify requires a UUID and modification args\n")
+ return 1, nil
+ }
+ uuid := args[1]
+ if IsNumericID(uuid) {
+ io.WriteString(stderr, RejectNumericID())
+ return 1, nil
+ }
+ modArgs := args[2:]
+ var outBuf bytes.Buffer
+ code, err := d.runner.Run(ctx, append([]string{"modify", uuid}, modArgs...), nil, &outBuf, io.Discard)
+ if code != 0 {
+ return code, err
+ }
+ io.WriteString(stdout, FormatSuccess(uuid))
+ return 0, nil
+}
+
+func (d Dispatcher) handleAnnotate(ctx context.Context, args []string, stdout, stderr io.Writer) (int, error) {
+ if len(args) < 3 {
+ io.WriteString(stderr, "error: ask annotate requires a UUID and note argument\n")
+ return 1, nil
+ }
+ uuid := args[1]
+ if IsNumericID(uuid) {
+ io.WriteString(stderr, RejectNumericID())
+ return 1, nil
+ }
+ note := strings.Join(args[2:], " ")
+ var outBuf bytes.Buffer
+ code, err := d.runner.Run(ctx, []string{"annotate", uuid, note}, nil, &outBuf, io.Discard)
+ if code != 0 {
+ return code, err
+ }
+ io.WriteString(stdout, FormatSuccess(uuid))
+ return 0, nil
+}
+
+func (d Dispatcher) handleStart(ctx context.Context, args []string, stdout, stderr io.Writer) (int, error) {
+ if len(args) < 2 {
+ io.WriteString(stderr, "error: ask start requires a UUID argument\n")
+ return 1, nil
+ }
+ uuid := args[1]
+ if IsNumericID(uuid) {
+ io.WriteString(stderr, RejectNumericID())
+ return 1, nil
+ }
+ var outBuf bytes.Buffer
+ code, err := d.runner.Run(ctx, []string{"start", uuid}, nil, &outBuf, io.Discard)
+ if code != 0 {
+ return code, err
+ }
+ io.WriteString(stdout, FormatSuccess(uuid))
+ return 0, nil
+}
+
+func (d Dispatcher) handleStop(ctx context.Context, args []string, stdout, stderr io.Writer) (int, error) {
+ if len(args) < 2 {
+ io.WriteString(stderr, "error: ask stop requires a UUID argument\n")
+ return 1, nil
+ }
+ uuid := args[1]
+ if IsNumericID(uuid) {
+ io.WriteString(stderr, RejectNumericID())
+ return 1, nil
+ }
+ var outBuf bytes.Buffer
+ code, err := d.runner.Run(ctx, []string{"stop", uuid}, nil, &outBuf, io.Discard)
+ if code != 0 {
+ return code, err
+ }
+ io.WriteString(stdout, FormatSuccess(uuid))
+ return 0, nil
+}
+
+func (d Dispatcher) handleDone(ctx context.Context, args []string, stdout, stderr io.Writer) (int, error) {
+ if len(args) < 2 {
+ io.WriteString(stderr, "error: ask done requires a UUID argument\n")
+ return 1, nil
+ }
+ uuid := args[1]
+ if IsNumericID(uuid) {
+ io.WriteString(stderr, RejectNumericID())
+ return 1, nil
+ }
+ var outBuf bytes.Buffer
+ code, err := d.runner.Run(ctx, []string{"done", uuid}, nil, &outBuf, io.Discard)
+ if code != 0 {
+ return code, err
+ }
+ io.WriteString(stdout, FormatSuccess(uuid))
+ return 0, nil
+}
+
+func (d Dispatcher) handlePriority(ctx context.Context, args []string, stdout, stderr io.Writer) (int, error) {
+ if len(args) < 3 {
+ io.WriteString(stderr, "error: ask priority requires a UUID and priority (H/M/L)\n")
+ return 1, nil
+ }
+ uuid := args[1]
+ if IsNumericID(uuid) {
+ io.WriteString(stderr, RejectNumericID())
+ return 1, nil
+ }
+ priority := args[2]
+ var outBuf bytes.Buffer
+ code, err := d.runner.Run(ctx, []string{"priority", uuid, priority}, nil, &outBuf, io.Discard)
+ if code != 0 {
+ return code, err
+ }
+ io.WriteString(stdout, FormatSuccess(uuid))
+ return 0, nil
+}
+
+func (d Dispatcher) handleTag(ctx context.Context, args []string, stdout, stderr io.Writer) (int, error) {
+ if len(args) < 3 {
+ io.WriteString(stderr, "error: ask tag requires a UUID and +/-tag\n")
+ return 1, nil
+ }
+ uuid := args[1]
+ if IsNumericID(uuid) {
+ io.WriteString(stderr, RejectNumericID())
+ return 1, nil
+ }
+ tag := args[2]
+ var outBuf bytes.Buffer
+ code, err := d.runner.Run(ctx, []string{"tag", uuid, tag}, nil, &outBuf, io.Discard)
+ if code != 0 {
+ return code, err
+ }
+ io.WriteString(stdout, FormatSuccess(uuid))
+ return 0, nil
+}