fix: exit codes match spec (0, 1, 2, 127) and silence usage on runtime errors
Exit 2 for missing required arguments, exit 127 for agent not found. SilenceUsage on all commands to avoid dumping usage on runtime errors. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
+5
-4
@@ -11,10 +11,11 @@ import (
|
||||
)
|
||||
|
||||
var archiveCmd = &cobra.Command{
|
||||
Use: "archive <query>",
|
||||
Short: "Mark a workspace as archived",
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: runArchive,
|
||||
Use: "archive <query>",
|
||||
Short: "Mark a workspace as archived",
|
||||
Args: cobra.ExactArgs(1),
|
||||
SilenceUsage: true,
|
||||
RunE: runArchive,
|
||||
}
|
||||
|
||||
func init() {
|
||||
|
||||
+3
-2
@@ -11,8 +11,9 @@ import (
|
||||
var infoCmd = &cobra.Command{
|
||||
Use: "info <query>",
|
||||
Short: "Display metadata and path for a workspace",
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: runInfo,
|
||||
Args: cobra.ExactArgs(1),
|
||||
SilenceUsage: true,
|
||||
RunE: runInfo,
|
||||
}
|
||||
|
||||
var infoAll bool
|
||||
|
||||
+3
-2
@@ -14,8 +14,9 @@ import (
|
||||
var listCmd = &cobra.Command{
|
||||
Use: "list",
|
||||
Short: "Show recent workspaces in reverse-chronological order",
|
||||
Args: cobra.NoArgs,
|
||||
RunE: runList,
|
||||
Args: cobra.NoArgs,
|
||||
SilenceUsage: true,
|
||||
RunE: runList,
|
||||
}
|
||||
|
||||
var (
|
||||
|
||||
+3
-2
@@ -13,8 +13,9 @@ var newCmd = &cobra.Command{
|
||||
Use: "new [title]",
|
||||
Short: "Create a new task workspace and launch the agent",
|
||||
Long: "Create a new task workspace and launch the agent. If title is omitted, generates task-HHMMSS.",
|
||||
Args: cobra.MaximumNArgs(1),
|
||||
RunE: runNew,
|
||||
Args: cobra.MaximumNArgs(1),
|
||||
SilenceUsage: true,
|
||||
RunE: runNew,
|
||||
}
|
||||
|
||||
var (
|
||||
|
||||
+5
-4
@@ -12,10 +12,11 @@ import (
|
||||
)
|
||||
|
||||
var openCmd = &cobra.Command{
|
||||
Use: "open <query>",
|
||||
Short: "Open a workspace directory without launching the agent",
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: runOpen,
|
||||
Use: "open <query>",
|
||||
Short: "Open a workspace directory without launching the agent",
|
||||
Args: cobra.ExactArgs(1),
|
||||
SilenceUsage: true,
|
||||
RunE: runOpen,
|
||||
}
|
||||
|
||||
var openAll bool
|
||||
|
||||
+5
-4
@@ -12,10 +12,11 @@ import (
|
||||
)
|
||||
|
||||
var resumeCmd = &cobra.Command{
|
||||
Use: "resume <query>",
|
||||
Short: "Reopen an existing workspace and launch the agent",
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: runResume,
|
||||
Use: "resume <query>",
|
||||
Short: "Reopen an existing workspace and launch the agent",
|
||||
Args: cobra.ExactArgs(1),
|
||||
SilenceUsage: true,
|
||||
RunE: runResume,
|
||||
}
|
||||
|
||||
var (
|
||||
|
||||
@@ -2,12 +2,23 @@ package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/warrenronsiek/ctask/cmd"
|
||||
)
|
||||
|
||||
func main() {
|
||||
if err := cmd.Execute(); err != nil {
|
||||
msg := err.Error()
|
||||
// Exit code 127 for agent command not found (per spec)
|
||||
if strings.Contains(msg, "agent command not found") {
|
||||
os.Exit(127)
|
||||
}
|
||||
// Exit code 2 for missing required arguments (per spec)
|
||||
if strings.Contains(msg, "accepts") && strings.Contains(msg, "received 0") {
|
||||
os.Exit(2)
|
||||
}
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user