diff options
| author | Peter Stone <thepeterstone@gmail.com> | 2026-03-05 17:41:52 +0000 |
|---|---|---|
| committer | Peter Stone <thepeterstone@gmail.com> | 2026-03-05 17:41:52 +0000 |
| commit | f7c6de4f99649dfa19c6b20b5a3fb344c4f8e82c (patch) | |
| tree | eee4a4a1e33f07194412f84fde17f7464b6430e2 /internal/cli/start.go | |
| parent | ddfb922584dd990481f44aad1a989e5bdf188823 (diff) | |
cli: add start command and version package
Adds `claudomator start <task-id>` to queue a task via the running API
server. Adds internal/version for embedding VCS commit hash in the
server banner.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to 'internal/cli/start.go')
| -rw-r--r-- | internal/cli/start.go | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/internal/cli/start.go b/internal/cli/start.go new file mode 100644 index 0000000..6ec09b2 --- /dev/null +++ b/internal/cli/start.go @@ -0,0 +1,44 @@ +package cli + +import ( + "encoding/json" + "fmt" + "net/http" + + "github.com/spf13/cobra" +) + +func newStartCmd() *cobra.Command { + var serverURL string + + cmd := &cobra.Command{ + Use: "start <task-id>", + Short: "Queue a task for execution via the running server", + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) error { + return startTask(serverURL, args[0]) + }, + } + + cmd.Flags().StringVar(&serverURL, "server", "http://localhost:8484", "claudomator server URL") + return cmd +} + +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 + if err != nil { + return fmt.Errorf("POST %s: %w", url, err) + } + defer resp.Body.Close() + + var body map[string]string + _ = json.NewDecoder(resp.Body).Decode(&body) + + if resp.StatusCode >= 300 { + return fmt.Errorf("server returned %d: %s", resp.StatusCode, body["error"]) + } + + fmt.Printf("Queued task %s\n", id) + return nil +} |
