Skip to content

Commit 8720f45

Browse files
GenerQAQclaude
andauthored
fix(cli): remove duplicate error output and suppress usage on runtime errors (#466)
- Add SilenceUsage to root command so runtime errors don't print usage info - Remove manual error print in main() that duplicated Cobra's automatic output - Make whoami print "not logged in" as info instead of returning it as error - Fix dash ping double-printing error details then a separate "Error: ping failed" Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 7cb93ec commit 8720f45

3 files changed

Lines changed: 14 additions & 8 deletions

File tree

src/client/acontext-cli/cmd/dash_ping.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,19 @@ func init() {
1616
RunE: func(cmd *cobra.Command, args []string) error {
1717
// 1. Verify that we have a local key for the resolved project
1818
if dashProject == "" {
19-
return fmt.Errorf("no project selected\n\nTo fix this, run:\n acontext dash projects select")
19+
fmt.Println(tui.RenderWarning("No project selected"))
20+
fmt.Println("\nTo fix this, run:\n acontext dash projects select")
21+
return nil
2022
}
2123

2224
ks, err := auth.LoadKeyStore()
2325
if err != nil {
2426
return fmt.Errorf("failed to load credentials: %w", err)
2527
}
2628
if ks.Keys[dashProject] == "" {
27-
return fmt.Errorf("no API key found in credentials.json for project %s\n\nTo fix this, run:\n acontext dash projects select --project %s --api-key <sk-ac-...>\n\nThe API key can be found on the Acontext Dashboard:\n https://dash.acontext.io", dashProject, dashProject)
29+
fmt.Println(tui.RenderWarning(fmt.Sprintf("No API key found in credentials.json for project %s", dashProject)))
30+
fmt.Printf("\nTo fix this, run:\n acontext dash projects select --project %s --api-key <sk-ac-...>\n\nThe API key can be found on the Acontext Dashboard:\n https://dash.acontext.io\n", dashProject)
31+
return nil
2832
}
2933

3034
// 2. Check API connectivity
@@ -36,7 +40,7 @@ func init() {
3640
if err := client.Ping(cmd.Context()); err != nil {
3741
fmt.Printf("Ping failed for project %s: %v\n", dashProject, err)
3842
fmt.Printf("Fix with: acontext dash projects select --project %s --api-key <sk-ac-...>\n", dashProject)
39-
return fmt.Errorf("ping failed")
43+
return nil
4044
}
4145

4246
fmt.Println(tui.RenderSuccess(fmt.Sprintf("Project %s is reachable. Setup complete.", dashProject)))

src/client/acontext-cli/cmd/login.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,8 @@ func runLogout(cmd *cobra.Command, args []string) error {
197197
func runWhoami(cmd *cobra.Command, args []string) error {
198198
af, err := auth.MustLoad()
199199
if err != nil {
200-
return err
200+
fmt.Println("Not logged in — run 'acontext login' first")
201+
return nil
201202
}
202203

203204
// Validate token with Supabase and refresh if needed
@@ -206,7 +207,8 @@ func runWhoami(cmd *cobra.Command, args []string) error {
206207
// If session was auto-cleared (e.g. another device consumed the refresh token),
207208
// show "not logged in" instead of the underlying error.
208209
if !auth.IsLoggedIn() {
209-
return fmt.Errorf("not logged in — run 'acontext login' first")
210+
fmt.Println("Not logged in — run 'acontext login' first")
211+
return nil
210212
}
211213
return err
212214
}

src/client/acontext-cli/main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ func main() {
3636
}
3737

3838
if cmdErr := rootCmd.Execute(); cmdErr != nil {
39-
fmt.Fprintf(os.Stderr, "Error: %v\n", cmdErr)
4039
executedCmd, _, _ := rootCmd.Find(os.Args[1:])
4140
if executedCmd == nil {
4241
executedCmd = rootCmd
@@ -111,8 +110,9 @@ func buildCommandPath(cmd *cobra.Command) string {
111110
}
112111

113112
var rootCmd = &cobra.Command{
114-
Use: "acontext",
115-
Short: "Acontext CLI - Agent Skills as a Memory Layer",
113+
Use: "acontext",
114+
SilenceUsage: true,
115+
Short: "Acontext CLI - Agent Skills as a Memory Layer",
116116
Long: `Acontext CLI is a command-line tool for quickly creating Acontext projects.
117117
118118
It helps you:

0 commit comments

Comments
 (0)