summaryrefslogtreecommitdiff
path: root/internal/cli/start.go
diff options
context:
space:
mode:
authorPeter Stone <thepeterstone@gmail.com>2026-03-08 20:40:55 +0000
committerPeter Stone <thepeterstone@gmail.com>2026-03-08 20:40:55 +0000
commit1ce83b6b6a300f4389dd84c4477f3ca73a431524 (patch)
treebefe1444267d0f4f333b226f016a7767e354c2a2 /internal/cli/start.go
parentdb1ebb7a3f9310ca2cc483d65e9c0e578c2eb4ff (diff)
cli: newLogger helper, defaultServerURL, shared http client, report command
- Extract newLogger() to remove duplication across run/serve/start - Add defaultServerURL const ("http://localhost:8484") used by all client commands - Move http.Client into internal/cli/http.go with 30s timeout - Add 'report' command for printing execution summaries - Add test coverage for create and serve commands Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to 'internal/cli/start.go')
-rw-r--r--internal/cli/start.go12
1 files changed, 8 insertions, 4 deletions
diff --git a/internal/cli/start.go b/internal/cli/start.go
index 6ec09b2..9e66e00 100644
--- a/internal/cli/start.go
+++ b/internal/cli/start.go
@@ -3,7 +3,8 @@ package cli
import (
"encoding/json"
"fmt"
- "net/http"
+ "io"
+ "net/url"
"github.com/spf13/cobra"
)
@@ -25,15 +26,18 @@ func newStartCmd() *cobra.Command {
}
func startTask(serverURL, id string) error {
- url := fmt.Sprintf("%s/api/tasks/%s/run", serverURL, id)
- resp, err := http.Post(url, "application/json", nil) //nolint:noctx
+ url := fmt.Sprintf("%s/api/tasks/%s/run", serverURL, url.PathEscape(id))
+ resp, err := httpClient.Post(url, "application/json", nil) //nolint:noctx
if err != nil {
return fmt.Errorf("POST %s: %w", url, err)
}
defer resp.Body.Close()
+ raw, _ := io.ReadAll(resp.Body)
var body map[string]string
- _ = json.NewDecoder(resp.Body).Decode(&body)
+ if err := json.Unmarshal(raw, &body); err != nil {
+ return fmt.Errorf("server returned invalid JSON (status %d): %s", resp.StatusCode, string(raw))
+ }
if resp.StatusCode >= 300 {
return fmt.Errorf("server returned %d: %s", resp.StatusCode, body["error"])