Skip to content

Commit cd4d0f9

Browse files
artparclaude
andcommitted
Print active context on every command
Shows context name, endpoint, and auth status on stderr so users always know which server they're querying. Explicit --endpoint flag now correctly overrides saved context. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 340c6d4 commit cd4d0f9

1 file changed

Lines changed: 16 additions & 5 deletions

File tree

cmd/app.go

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package cmd
22

33
import (
4+
"fmt"
5+
"os"
6+
47
"github.com/daptin/daptin-cli/client"
58
"github.com/daptin/daptin-cli/config"
69
"github.com/daptin/daptin-cli/render"
@@ -22,21 +25,29 @@ func NewApp(cfg *config.Config, version string) *cli.App {
2225
Usage: "CLI client for Daptin API server",
2326
Version: version,
2427
Before: func(c *cli.Context) error {
25-
// Resolve endpoint: config context > flag > default
2628
endpoint := c.String("endpoint")
2729
authToken := ""
28-
if cfg.CurrentContext != "" {
30+
contextName := endpoint
31+
32+
// Explicit --endpoint flag wins over saved context
33+
if c.IsSet("endpoint") {
34+
contextName = endpoint
35+
} else if cfg.CurrentContext != "" {
2936
if host, err := cfg.ActiveHost(); err == nil {
3037
endpoint = host.Endpoint
3138
authToken = host.Token
39+
contextName = host.Name
3240
}
3341
}
34-
if ep := c.String("endpoint"); ep != "http://localhost:6336" {
35-
endpoint = ep
36-
}
3742

3843
appCtx.Client = client.New(endpoint, authToken, c.Bool("debug"))
3944

45+
authed := ""
46+
if authToken != "" {
47+
authed = ", authenticated"
48+
}
49+
fmt.Fprintf(os.Stderr, "Using %s (%s%s)\n", contextName, endpoint, authed)
50+
4051
switch c.String("output") {
4152
case "json":
4253
appCtx.Renderer = render.NewJsonRenderer()

0 commit comments

Comments
 (0)