Skip to content

Modern Docker Management, Designed for Everyone

refactor: use charm logging instead of logrus for arcane-cli (#2518)

Kyle Mendell0430306daa63
diff --git a/cli/go.mod b/cli/go.mod
index 8c733d4a4..9c2128169 100644
--- a/cli/go.mod
+++ b/cli/go.mod
@@ -6,12 +6,13 @@ require (
charm.land/bubbles/v2 v2.1.0
charm.land/bubbletea/v2 v2.0.6
charm.land/lipgloss/v2 v2.0.3
+ github.com/charmbracelet/fang v0.4.4
+ github.com/charmbracelet/log v1.0.0
github.com/charmbracelet/x/term v0.2.2
github.com/fatih/color v1.19.0
github.com/getarcaneapp/arcane/types v1.18.1
github.com/go-viper/mapstructure/v2 v2.5.0
github.com/mattn/go-runewidth v0.0.23
- github.com/sirupsen/logrus v1.9.4
github.com/spf13/cobra v1.10.2
github.com/spf13/pflag v1.0.10
github.com/spf13/viper v1.21.0
@@ -21,11 +22,15 @@ require (
require (
github.com/Microsoft/go-winio v0.6.2 // indirect
github.com/atotto/clipboard v0.1.4 // indirect
+ github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/charmbracelet/colorprofile v0.4.3 // indirect
github.com/charmbracelet/harmonica v0.2.0 // indirect
+ github.com/charmbracelet/lipgloss v1.1.0 // indirect
github.com/charmbracelet/ultraviolet v0.0.0-20260416155717-489999b90468 // indirect
github.com/charmbracelet/x/ansi v0.11.7 // indirect
+ github.com/charmbracelet/x/cellbuf v0.0.15 // indirect
+ github.com/charmbracelet/x/exp/charmtone v0.0.0-20250603201427-c31516f43444 // indirect
github.com/charmbracelet/x/termios v0.1.1 // indirect
github.com/charmbracelet/x/windows v0.2.2 // indirect
github.com/clipperhouse/displaywidth v0.11.0 // indirect
@@ -38,6 +43,7 @@ require (
github.com/docker/go-units v0.5.0 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/fsnotify/fsnotify v1.10.1 // indirect
+ github.com/go-logfmt/logfmt v0.6.1 // indirect
github.com/go-logr/logr v1.4.3 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
@@ -49,12 +55,18 @@ require (
github.com/moby/moby/api v1.54.2 // indirect
github.com/moby/moby/client v0.4.1 // indirect
github.com/muesli/cancelreader v0.2.2 // indirect
+ github.com/muesli/mango v0.1.0 // indirect
+ github.com/muesli/mango-cobra v1.2.0 // indirect
+ github.com/muesli/mango-pflag v0.1.0 // indirect
+ github.com/muesli/roff v0.1.0 // indirect
+ github.com/muesli/termenv v0.16.0 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.1.1 // indirect
github.com/pelletier/go-toml/v2 v2.3.0 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/sagikazarmark/locafero v0.12.0 // indirect
github.com/sahilm/fuzzy v0.1.1 // indirect
+ github.com/sirupsen/logrus v1.9.4 // indirect
github.com/spf13/afero v1.15.0 // indirect
github.com/spf13/cast v1.10.0 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
diff --git a/cli/go.sum b/cli/go.sum
index 4ede7ef89..060892187 100644
--- a/cli/go.sum
+++ b/cli/go.sum
@@ -8,18 +8,30 @@ github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERo
github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU=
github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z4=
github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI=
+github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k=
+github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8=
github.com/aymanbagabas/go-udiff v0.4.1 h1:OEIrQ8maEeDBXQDoGCbbTTXYJMYRCRO1fnodZ12Gv5o=
github.com/aymanbagabas/go-udiff v0.4.1/go.mod h1:0L9PGwj20lrtmEMeyw4WKJ/TMyDtvAoK9bf2u/mNo3w=
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/charmbracelet/colorprofile v0.4.3 h1:QPa1IWkYI+AOB+fE+mg/5/4HRMZcaXex9t5KX76i20Q=
github.com/charmbracelet/colorprofile v0.4.3/go.mod h1:/zT4BhpD5aGFpqQQqw7a+VtHCzu+zrQtt1zhMt9mR4Q=
+github.com/charmbracelet/fang v0.4.4 h1:G4qKxF6or/eTPgmAolwPuRNyuci3hTUGGX1rj1YkHJY=
+github.com/charmbracelet/fang v0.4.4/go.mod h1:P5/DNb9DddQ0Z0dbc0P3ol4/ix5Po7Ofr2KMBfAqoCo=
github.com/charmbracelet/harmonica v0.2.0 h1:8NxJWRWg/bzKqqEaaeFNipOu77YR5t8aSwG4pgaUBiQ=
github.com/charmbracelet/harmonica v0.2.0/go.mod h1:KSri/1RMQOZLbw7AHqgcBycp8pgJnQMYYT8QZRqZ1Ao=
+github.com/charmbracelet/lipgloss v1.1.0 h1:vYXsiLHVkK7fp74RkV7b2kq9+zDLoEU4MZoFqR/noCY=
+github.com/charmbracelet/lipgloss v1.1.0/go.mod h1:/6Q8FR2o+kj8rz4Dq0zQc3vYf7X+B0binUUBwA0aL30=
+github.com/charmbracelet/log v1.0.0 h1:HVVVMmfOorfj3BA9i8X8UL69Hoz9lI0PYwXfJvOdRc4=
+github.com/charmbracelet/log v1.0.0/go.mod h1:uYgY3SmLpwJWxmlrPwXvzVYujxis1vAKRV/0VQB7yWA=
github.com/charmbracelet/ultraviolet v0.0.0-20260416155717-489999b90468 h1:Q9fO0y1Zo5KB/5Vu8JZoLGm1N3RzF9bNj3Ao3xoR+Ac=
github.com/charmbracelet/ultraviolet v0.0.0-20260416155717-489999b90468/go.mod h1:bAAz7dh/FTYfC+oiHavL4mX1tOIBZ0ZwYjSi3qE6ivM=
github.com/charmbracelet/x/ansi v0.11.7 h1:kzv1kJvjg2S3r9KHo8hDdHFQLEqn4RBCb39dAYC84jI=
github.com/charmbracelet/x/ansi v0.11.7/go.mod h1:9qGpnAVYz+8ACONkZBUWPtL7lulP9No6p1epAihUZwQ=
+github.com/charmbracelet/x/cellbuf v0.0.15 h1:ur3pZy0o6z/R7EylET877CBxaiE1Sp1GMxoFPAIztPI=
+github.com/charmbracelet/x/cellbuf v0.0.15/go.mod h1:J1YVbR7MUuEGIFPCaaZ96KDl5NoS0DAWkskup+mOY+Q=
+github.com/charmbracelet/x/exp/charmtone v0.0.0-20250603201427-c31516f43444 h1:IJDiTgVE56gkAGfq0lBEloWgkXMk4hl/bmuPoicI4R0=
+github.com/charmbracelet/x/exp/charmtone v0.0.0-20250603201427-c31516f43444/go.mod h1:T9jr8CzFpjhFVHjNjKwbAD7KwBNyFnj2pntAO7F2zw0=
github.com/charmbracelet/x/exp/golden v0.0.0-20250806222409-83e3a29d542f h1:pk6gmGpCE7F3FcjaOEKYriCvpmIN4+6OS/RD0vm4uIA=
github.com/charmbracelet/x/exp/golden v0.0.0-20250806222409-83e3a29d542f/go.mod h1:IfZAMTHB6XkZSeXUqriemErjAWCCzT0LwjKFYCZyw0I=
github.com/charmbracelet/x/term v0.2.2 h1:xVRT/S2ZcKdhhOuSP4t5cLi5o+JxklsoEObBSgfgZRk=
@@ -44,6 +56,7 @@ github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8Yc
github.com/distribution/reference v0.6.0 h1:0IXCQ5g4/QMHHkarYzh5l+u8T3t73zM5QvfrDyIgxBk=
github.com/distribution/reference v0.6.0/go.mod h1:BbU0aIcezP1/5jX/8MP0YiH4SdvB5Y4f/wlDRiLyi3E=
github.com/docker/go-connections v0.7.0 h1:6SsRfJddP22WMrCkj19x9WKjEDTB+ahsdiGYf0mN39c=
+github.com/docker/go-connections v0.7.0/go.mod h1:no1qkHdjq7kLMGUXYAduOhYPSJxxvgWBh7ogVvptn3Q=
github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4=
github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
github.com/fatih/color v1.19.0 h1:Zp3PiM21/9Ld6FzSKyL5c/BULoe/ONr9KlbYVOfG8+w=
@@ -53,8 +66,11 @@ github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSw
github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
github.com/fsnotify/fsnotify v1.10.1 h1:b0/UzAf9yR5rhf3RPm9gf3ehBPpf0oZKIjtpKrx59Ho=
+github.com/fsnotify/fsnotify v1.10.1/go.mod h1:TLheqan6HD6GBK6PrDWyDPBaEV8LspOxvPSjC+bVfgo=
github.com/getarcaneapp/arcane/types v1.18.1 h1:aDzCnfPL4C146qyUWr5NoMS1nQqKLKqYiumNImNII+U=
github.com/getarcaneapp/arcane/types v1.18.1/go.mod h1:eV/UlGVUw4AnpLjRltWLrY4YzVBa2UZaiTwGzGNDUoc=
+github.com/go-logfmt/logfmt v0.6.1 h1:4hvbpePJKnIzH1B+8OR/JPbTx37NktoI9LE2QZBBkvE=
+github.com/go-logfmt/logfmt v0.6.1/go.mod h1:EV2pOAQoZaT1ZXZbqDl5hrymndi4SY9ED9/z6CO0XAk=
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/logr v1.4.3 h1:CjnDlHq8ikf6E492q6eKboGOC0T8CDaOvkHCIg8idEI=
github.com/go-logr/logr v1.4.3/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
@@ -87,9 +103,21 @@ github.com/mattn/go-shellwords v1.0.12/go.mod h1:EZzvwXDESEeg03EKmM+RmDnNOPKG4lL
github.com/moby/docker-image-spec v1.3.1 h1:jMKff3w6PgbfSa69GfNg+zN/XLhfXJGnEx3Nl2EsFP0=
github.com/moby/docker-image-spec v1.3.1/go.mod h1:eKmb5VW8vQEh/BAr2yvVNvuiJuY6UIocYsFu/DxxRpo=
github.com/moby/moby/api v1.54.2 h1:wiat9QAhnDQjA7wk1kh/TqHz2I1uUA7M7t9SAl/JNXg=
+github.com/moby/moby/api v1.54.2/go.mod h1:+RQ6wluLwtYaTd1WnPLykIDPekkuyD/ROWQClE83pzs=
github.com/moby/moby/client v0.4.1 h1:DMQgisVoMkmMs7fp3ROSdiBnoAu8+vo3GggFl06M/wY=
+github.com/moby/moby/client v0.4.1/go.mod h1:z52C9O2POPOsnxZAy//WtKcQ32P+jT/NGeXu/7nfjGQ=
github.com/muesli/cancelreader v0.2.2 h1:3I4Kt4BQjOR54NavqnDogx/MIoWBFa0StPA8ELUXHmA=
github.com/muesli/cancelreader v0.2.2/go.mod h1:3XuTXfFS2VjM+HTLZY9Ak0l6eUKfijIfMUZ4EgX0QYo=
+github.com/muesli/mango v0.1.0 h1:DZQK45d2gGbql1arsYA4vfg4d7I9Hfx5rX/GCmzsAvI=
+github.com/muesli/mango v0.1.0/go.mod h1:5XFpbC8jY5UUv89YQciiXNlbi+iJgt29VDC5xbzrLL4=
+github.com/muesli/mango-cobra v1.2.0 h1:DQvjzAM0PMZr85Iv9LIMaYISpTOliMEg+uMFtNbYvWg=
+github.com/muesli/mango-cobra v1.2.0/go.mod h1:vMJL54QytZAJhCT13LPVDfkvCUJ5/4jNUKF/8NC2UjA=
+github.com/muesli/mango-pflag v0.1.0 h1:UADqbYgpUyRoBja3g6LUL+3LErjpsOwaC9ywvBWe7Sg=
+github.com/muesli/mango-pflag v0.1.0/go.mod h1:YEQomTxaCUp8PrbhFh10UfbhbQrM/xJ4i2PB8VTLLW0=
+github.com/muesli/roff v0.1.0 h1:YD0lalCotmYuF5HhZliKWlIx7IEhiXeSfq7hNjFqGF8=
+github.com/muesli/roff v0.1.0/go.mod h1:pjAHQM9hdUUwm/krAfrLGgJkXJ+YuhtsfZ42kieB2Ig=
+github.com/muesli/termenv v0.16.0 h1:S5AlUN9dENB57rsbnkPyfdGuWIlkmzJjbFf0Tf5FWUc=
+github.com/muesli/termenv v0.16.0/go.mod h1:ZRfOIKPFDYQoDFF4Olj7/QJbW60Ol/kL1pU3VfY/Cnk=
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
github.com/opencontainers/image-spec v1.1.1 h1:y0fUlFfIZhPF1W537XOLg0/fcx6zcHCJwooC2xJA040=
diff --git a/cli/internal/client/client.go b/cli/internal/client/client.go
index b7547d352..990868431 100644
--- a/cli/internal/client/client.go
+++ b/cli/internal/client/client.go
@@ -36,6 +36,7 @@ import (
"time"
"github.com/getarcaneapp/arcane/cli/internal/config"
+ "github.com/getarcaneapp/arcane/cli/internal/logger"
"github.com/getarcaneapp/arcane/cli/internal/runstate"
"github.com/getarcaneapp/arcane/cli/internal/types"
"github.com/getarcaneapp/arcane/types/auth"
@@ -266,10 +267,14 @@ func (c *Client) Request(ctx context.Context, method, path string, body any) (*h
c.applyAuth(req)
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Accept", "application/json")
+ start := time.Now()
+ logger.GetLogger().Debug("Sending request", "method", method, "url", fullURL, "env_id", c.envID, "streaming_body", true)
resp, err := c.httpClient.Do(req) //nolint:gosec // intentional request to configured Arcane server URL
if err != nil {
+ logger.GetLogger().Debug("Request failed", "method", method, "url", fullURL, "env_id", c.envID, "duration", time.Since(start).String(), "error", err)
return nil, fmt.Errorf("request failed: %w", err)
}
+ logger.GetLogger().Debug("Response received", "method", method, "url", fullURL, "env_id", c.envID, "status", resp.Status, "duration", time.Since(start).String())
return resp, nil
default:
jsonBody, err := json.Marshal(body)
@@ -305,10 +310,14 @@ func (c *Client) RequestRaw(ctx context.Context, method, path string, body io.Re
req.Header.Set(k, v)
}
+ start := time.Now()
+ logger.GetLogger().Debug("Sending raw request", "method", method, "url", fullURL, "env_id", c.envID)
resp, err := c.httpClient.Do(req) //nolint:gosec // intentional request to configured Arcane server URL
if err != nil {
+ logger.GetLogger().Debug("Raw request failed", "method", method, "url", fullURL, "env_id", c.envID, "duration", time.Since(start).String(), "error", err)
return nil, fmt.Errorf("request failed: %w", err)
}
+ logger.GetLogger().Debug("Raw response received", "method", method, "url", fullURL, "env_id", c.envID, "status", resp.Status, "duration", time.Since(start).String())
return resp, nil
}
@@ -351,9 +360,13 @@ func (c *Client) doRequest(ctx context.Context, method, fullURL string, bodyByte
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Accept", "application/json")
+ start := time.Now()
+ logger.GetLogger().Debug("Sending request", "method", method, "url", fullURL, "env_id", c.envID, "attempt", attempt, "max_attempts", attempts, "body_bytes", len(bodyBytes))
resp, err := c.httpClient.Do(req) //nolint:gosec // intentional request to configured Arcane server URL
if err != nil {
+ logger.GetLogger().Debug("Request failed", "method", method, "url", fullURL, "env_id", c.envID, "attempt", attempt, "duration", time.Since(start).String(), "error", err)
if attempt < attempts && c.shouldRetry(method, 0, err) {
+ logger.GetLogger().Debug("Retrying request after transport error", "method", method, "url", fullURL, "env_id", c.envID, "attempt", attempt, "max_attempts", attempts)
if backoffErr := c.waitRetry(ctx, attempt); backoffErr != nil {
return nil, backoffErr
}
@@ -361,8 +374,10 @@ func (c *Client) doRequest(ctx context.Context, method, fullURL string, bodyByte
}
return nil, fmt.Errorf("request failed: %w", err)
}
+ logger.GetLogger().Debug("Response received", "method", method, "url", fullURL, "env_id", c.envID, "attempt", attempt, "status", resp.Status, "duration", time.Since(start).String())
if resp.StatusCode == http.StatusUnauthorized && allowRefresh && c.jwtToken != "" && c.refreshToken != "" {
+ logger.GetLogger().Debug("Refreshing access token after unauthorized response", "method", method, "url", fullURL, "env_id", c.envID, "attempt", attempt)
_ = resp.Body.Close()
if err := c.refreshAccessToken(ctx); err != nil {
return nil, err
@@ -372,6 +387,7 @@ func (c *Client) doRequest(ctx context.Context, method, fullURL string, bodyByte
}
if attempt < attempts && c.shouldRetry(method, resp.StatusCode, nil) {
+ logger.GetLogger().Debug("Retrying request after retryable status", "method", method, "url", fullURL, "env_id", c.envID, "attempt", attempt, "max_attempts", attempts, "status", resp.Status)
_, _ = io.Copy(io.Discard, io.LimitReader(resp.Body, maxErrorBody))
_ = resp.Body.Close()
if backoffErr := c.waitRetry(ctx, attempt); backoffErr != nil {
@@ -463,6 +479,7 @@ func (c *Client) refreshAccessToken(ctx context.Context) error {
return fmt.Errorf("invalid base URL")
}
refreshURL := c.baseURLParsed.ResolveReference(&url.URL{Path: types.Endpoints.AuthRefresh()}).String()
+ logger.GetLogger().Debug("Sending token refresh request", "url", refreshURL)
req, err := http.NewRequestWithContext(ctx, http.MethodPost, refreshURL, bytes.NewReader(bodyBytes))
if err != nil {
@@ -471,11 +488,14 @@ func (c *Client) refreshAccessToken(ctx context.Context) error {
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Accept", "application/json")
+ start := time.Now()
resp, err := c.httpClient.Do(req) //nolint:gosec // intentional request to configured Arcane server URL
if err != nil {
+ logger.GetLogger().Debug("Token refresh request failed", "url", refreshURL, "duration", time.Since(start).String(), "error", err)
return fmt.Errorf("token refresh failed: %w", err)
}
defer func() { _ = resp.Body.Close() }()
+ logger.GetLogger().Debug("Token refresh response received", "url", refreshURL, "status", resp.Status, "duration", time.Since(start).String())
respBody, err := io.ReadAll(resp.Body)
if err != nil {
@@ -501,6 +521,7 @@ func (c *Client) refreshAccessToken(ctx context.Context) error {
c.jwtToken = result.Data.Token
c.refreshToken = newRefresh
+ logger.GetLogger().Debug("Access token refreshed successfully")
cfg, err := config.Load()
if err != nil {
diff --git a/cli/internal/logger/logger.go b/cli/internal/logger/logger.go
index 4823688c1..a7283b9d5 100644
--- a/cli/internal/logger/logger.go
+++ b/cli/internal/logger/logger.go
@@ -1,8 +1,8 @@
// Package logger provides logging configuration and access for the CLI.
//
-// This package wraps logrus to provide consistent logging across the CLI.
-// It supports configurable log levels and JSON output format for machine
-// parsing.
+// This package wraps charmbracelet/log to provide consistent logging across
+// the CLI. It supports configurable log levels and JSON output format for
+// machine parsing.
//
// # Setup
//
@@ -22,38 +22,33 @@ package logger
import (
"os"
- "github.com/sirupsen/logrus"
+ charmlog "github.com/charmbracelet/log"
)
// Setup configures the global logger with the specified level and format.
-// Valid log levels are: debug, info, warn, error, fatal, panic.
+// Valid log levels are: debug, info, warn, error, fatal.
// If an invalid level is provided, it defaults to info.
// When jsonFormat is true, logs are output as JSON for machine parsing.
func Setup(level string, jsonFormat bool) {
- // Set the log level
- lvl, err := logrus.ParseLevel(level)
+ lvl, err := charmlog.ParseLevel(level)
if err != nil {
- lvl = logrus.InfoLevel
+ lvl = charmlog.InfoLevel
}
- logrus.SetLevel(lvl)
- // Set the output to stdout
- logrus.SetOutput(os.Stdout)
+ log := charmlog.Default()
+ log.SetLevel(lvl)
+ log.SetOutput(os.Stdout)
+ log.SetReportTimestamp(true)
- // Set the formatter
if jsonFormat {
- logrus.SetFormatter(&logrus.JSONFormatter{})
+ log.SetFormatter(charmlog.JSONFormatter)
} else {
- logrus.SetFormatter(&logrus.TextFormatter{
- FullTimestamp: true,
- })
+ log.SetFormatter(charmlog.TextFormatter)
}
}
// GetLogger returns the global logger instance.
// The logger should be configured via Setup before use.
-// This returns the logrus standard logger which can be used for
-// Debug, Info, Warn, Error, Fatal, and Panic level logging.
-func GetLogger() *logrus.Logger {
- return logrus.StandardLogger()
+func GetLogger() *charmlog.Logger {
+ return charmlog.Default()
}
diff --git a/cli/pkg/root.go b/cli/pkg/root.go
index c41cf85cb..699233cf4 100644
--- a/cli/pkg/root.go
+++ b/cli/pkg/root.go
@@ -14,7 +14,7 @@
//
// The following flags are available on all commands:
//
-// --log-level string Log level (debug, info, warn, error, fatal, panic) (default "info")
+// --log-level string Log level (debug, info, warn, error, fatal) (default "info")
// --json Output in JSON format
// -v, --version Print version information
//
@@ -36,13 +36,11 @@ import (
"fmt"
"os"
"runtime"
- "sort"
"strings"
"time"
"charm.land/lipgloss/v2"
- "charm.land/lipgloss/v2/compat"
- "charm.land/lipgloss/v2/table"
+ "github.com/charmbracelet/fang"
"github.com/fatih/color"
"github.com/getarcaneapp/arcane/cli/internal/config"
"github.com/getarcaneapp/arcane/cli/internal/logger"
@@ -73,7 +71,6 @@ import (
"github.com/getarcaneapp/arcane/cli/pkg/version"
"github.com/getarcaneapp/arcane/cli/pkg/volumes"
"github.com/spf13/cobra"
- "github.com/spf13/pflag"
)
var (
@@ -89,36 +86,6 @@ var (
globalJSON bool
)
-var (
- helpPurple = compat.AdaptiveColor{
- Light: lipgloss.Color("#6d28d9"),
- Dark: lipgloss.Color("#a78bfa"),
- }
- helpTextPrimary = compat.AdaptiveColor{
- Light: lipgloss.Color("#1f2937"),
- Dark: lipgloss.Color("#e5e7eb"),
- }
- helpTextMuted = compat.AdaptiveColor{
- Light: lipgloss.Color("#64748b"),
- Dark: lipgloss.Color("#cbd5e1"),
- }
-
- helpTitleStyle = lipgloss.NewStyle().Bold(true).Foreground(helpPurple).Padding(0, 1)
- helpSubtitleStyle = lipgloss.NewStyle().Foreground(helpTextMuted).PaddingLeft(1)
- helpVersionStyle = lipgloss.NewStyle().Foreground(helpTextMuted).PaddingLeft(1)
- helpSectionStyle = lipgloss.NewStyle().Bold(true).Foreground(helpPurple).Padding(0, 1)
-
- helpCmdHeader = lipgloss.NewStyle().Bold(true).Foreground(helpPurple).Align(lipgloss.Center).Padding(0, 2)
- helpCmdCell = lipgloss.NewStyle().Padding(0, 2)
- helpCmdOdd = helpCmdCell.Foreground(helpTextPrimary)
- helpCmdEven = helpCmdCell.Foreground(helpTextMuted)
- helpCmdBorder = lipgloss.NewStyle().Foreground(helpPurple)
-
- helpTableWrap = lipgloss.NewStyle().Padding(0, 1)
- helpBodyStyle = lipgloss.NewStyle().Foreground(helpTextPrimary).PaddingLeft(2)
- helpFooterStyle = lipgloss.NewStyle().Foreground(helpTextMuted).Padding(1, 1, 0, 1)
-)
-
var rootCmd = &cobra.Command{
Use: "arcane-cli",
Long: "Arcane CLI - The official command line interface for Arcane",
@@ -197,7 +164,13 @@ var rootCmd = &cobra.Command{
}
func Execute() {
- if err := rootCmd.ExecuteContext(context.Background()); err != nil {
+ if err := fang.Execute(
+ context.Background(),
+ rootCmd,
+ fang.WithColorSchemeFunc(arcaneFangColorSchemeInternal),
+ fang.WithVersion(config.Version),
+ fang.WithCommit(config.Revision),
+ ); err != nil {
os.Exit(1)
}
}
@@ -208,12 +181,65 @@ func RootCommand() *cobra.Command {
return rootCmd
}
-func init() {
- rootCmd.SetHelpFunc(func(cmd *cobra.Command, args []string) {
- renderCommandHelp(cmd)
- })
+func arcaneFangColorSchemeInternal(c lipgloss.LightDarkFunc) fang.ColorScheme {
+ scheme := fang.DefaultColorScheme(c)
+ scheme.Base = c(lipgloss.Color("#1f2937"), lipgloss.Color("#e5e7eb"))
+ scheme.Title = c(lipgloss.Color("#6d28d9"), lipgloss.Color("#a78bfa"))
+ scheme.Description = scheme.Base
+ scheme.Codeblock = c(lipgloss.Color("#f5f3ff"), lipgloss.Color("#241b35"))
+ scheme.Program = scheme.Title
+ scheme.Command = c(lipgloss.Color("#7c3aed"), lipgloss.Color("#c4b5fd"))
+ scheme.DimmedArgument = c(lipgloss.Color("#64748b"), lipgloss.Color("#94a3b8"))
+ scheme.Comment = c(lipgloss.Color("#64748b"), lipgloss.Color("#cbd5e1"))
+ scheme.Flag = scheme.Title
+ scheme.FlagDefault = c(lipgloss.Color("#64748b"), lipgloss.Color("#cbd5e1"))
+ scheme.Argument = scheme.Base
+ scheme.Help = scheme.Base
+ scheme.Dash = scheme.Base
+ return scheme
+}
+
+func instrumentCommandTreeInternal(cmd *cobra.Command) {
+ for _, child := range cmd.Commands() {
+ instrumentCommandTreeInternal(child)
+ }
+
+ if cmd.RunE == nil && cmd.Run == nil {
+ return
+ }
+
+ if cmd.Annotations == nil {
+ cmd.Annotations = make(map[string]string)
+ }
+ if cmd.Annotations["arcane:logging-wrapped"] == "true" {
+ return
+ }
+ cmd.Annotations["arcane:logging-wrapped"] = "true"
+
+ action := strings.TrimSpace(cmd.Short)
+ if action == "" {
+ action = "Running command"
+ }
+
+ if cmd.RunE != nil {
+ originalRunE := cmd.RunE
+ cmd.RunE = func(command *cobra.Command, args []string) error {
+ logger.GetLogger().Debug(action, "command", command.CommandPath(), "arg_count", len(args))
+ return originalRunE(command, args)
+ }
+ }
- rootCmd.PersistentFlags().StringVar(&logLevel, "log-level", "info", "Log level (debug, info, warn, error, fatal, panic)")
+ if cmd.Run != nil {
+ originalRun := cmd.Run
+ cmd.Run = func(command *cobra.Command, args []string) {
+ logger.GetLogger().Debug(action, "command", command.CommandPath(), "arg_count", len(args))
+ originalRun(command, args)
+ }
+ }
+}
+
+func init() {
+ rootCmd.PersistentFlags().StringVar(&logLevel, "log-level", "info", "Log level (debug, info, warn, error, fatal)")
rootCmd.PersistentFlags().StringVarP(&configPath, "config", "c", "", "Path to config file (default ~/.config/arcanecli.yml)")
rootCmd.PersistentFlags().StringVar(&outputMode, "output", "text", "Output mode (text, json)")
rootCmd.PersistentFlags().StringVar(&envOverride, "env", "", "Override default environment ID for this invocation")
@@ -247,181 +273,6 @@ func init() {
rootCmd.AddCommand(selfupdate.Cmd)
rootCmd.AddCommand(admin.AdminCmd)
rootCmd.AddCommand(gitops.GitopsCmd)
-}
-
-func renderCommandHelp(cmd *cobra.Command) {
- title := cmd.CommandPath()
- if cmd == rootCmd {
- title = "Arcane CLI"
- }
- lipgloss.Println(helpTitleStyle.Render(title))
-
- summary := strings.TrimSpace(cmd.Long)
- if summary == "" {
- summary = strings.TrimSpace(cmd.Short)
- }
- if summary != "" {
- lipgloss.Println(helpSubtitleStyle.Render(summary))
- }
-
- if cmd == rootCmd {
- lipgloss.Println(helpVersionStyle.Render(fmt.Sprintf("Version %s (%s)", config.Version, config.Revision)))
- }
- lipgloss.Println()
-
- usageLine := cmd.UseLine()
- if usageLine != "" {
- lipgloss.Println(helpSectionStyle.Render("Usage"))
- lipgloss.Println(helpBodyStyle.Render(usageLine))
- lipgloss.Println()
- }
-
- if len(cmd.Aliases) > 0 {
- lipgloss.Println(helpSectionStyle.Render("Aliases"))
- lipgloss.Println(helpBodyStyle.Render(strings.Join(cmd.Aliases, ", ")))
- lipgloss.Println()
- }
-
- commandRows := collectCommandRows(cmd)
- if len(commandRows) > 0 {
- lipgloss.Println(helpSectionStyle.Render("Commands"))
- renderHelpTable([]string{"COMMAND", "DESCRIPTION"}, commandRows)
- lipgloss.Println()
- }
-
- localFlagRows := collectHelpFlagRowsInternal(cmd)
- if len(localFlagRows) > 0 {
- lipgloss.Println(helpSectionStyle.Render("Flags"))
- renderHelpTable([]string{"FLAG", "TYPE", "DEFAULT", "DESCRIPTION"}, localFlagRows)
- lipgloss.Println()
- }
-
- globalFlagRows := collectGlobalHelpFlagRowsInternal(cmd)
- if len(globalFlagRows) > 0 {
- lipgloss.Println(helpSectionStyle.Render("Global Flags"))
- renderHelpTable([]string{"FLAG", "TYPE", "DEFAULT", "DESCRIPTION"}, globalFlagRows)
- lipgloss.Println()
- }
-
- examples := strings.TrimSpace(cmd.Example)
- if examples != "" {
- lipgloss.Println(helpSectionStyle.Render("Examples"))
- for line := range strings.SplitSeq(examples, "\n") {
- trimmed := strings.TrimSpace(line)
- if trimmed == "" {
- lipgloss.Println()
- continue
- }
- lipgloss.Println(helpBodyStyle.Render(trimmed))
- }
- lipgloss.Println()
- }
-
- if cmd.HasAvailableSubCommands() {
- lipgloss.Println(helpFooterStyle.Render(fmt.Sprintf("Run '%s [command] --help' for command-specific help.", cmd.CommandPath())))
- }
-}
-
-func collectCommandRows(cmd *cobra.Command) [][]string {
- rows := make([][]string, 0, len(cmd.Commands()))
- for _, sub := range cmd.Commands() {
- if !sub.IsAvailableCommand() || sub.Hidden || sub.IsAdditionalHelpTopicCommand() {
- continue
- }
- rows = append(rows, []string{sub.Name(), sub.Short})
- }
-
- sort.Slice(rows, func(i, j int) bool {
- return rows[i][0] < rows[j][0]
- })
-
- return rows
-}
-
-func collectHelpFlagRowsInternal(cmd *cobra.Command) [][]string {
- if cmd == nil {
- return nil
- }
- if cmd == rootCmd {
- return collectFlagRowsExcludingInternal(cmd.LocalFlags(), cmd.PersistentFlags())
- }
- return collectFlagRows(cmd.NonInheritedFlags())
-}
-
-func collectGlobalHelpFlagRowsInternal(cmd *cobra.Command) [][]string {
- if cmd == nil {
- return nil
- }
- if cmd == rootCmd || cmd.Runnable() {
- return collectFlagRows(rootCmd.PersistentFlags())
- }
- return nil
-}
-
-func collectFlagRows(flags *pflag.FlagSet) [][]string {
- return collectFlagRowsExcludingInternal(flags, nil)
-}
-
-func collectFlagRowsExcludingInternal(flags, exclude *pflag.FlagSet) [][]string {
- if flags == nil {
- return nil
- }
-
- rows := make([][]string, 0)
- flags.VisitAll(func(f *pflag.Flag) {
- if f == nil || f.Hidden || f.Name == "help" {
- return
- }
- if exclude != nil && exclude.Lookup(f.Name) != nil {
- return
- }
-
- name := "--" + f.Name
- if f.Shorthand != "" && f.ShorthandDeprecated == "" {
- name = fmt.Sprintf("-%s, --%s", f.Shorthand, f.Name)
- }
-
- defaultValue := strings.TrimSpace(f.DefValue)
- if defaultValue == "" {
- defaultValue = "—"
- }
-
- flagType := "value"
- if f.Value != nil {
- if t := strings.TrimSpace(f.Value.Type()); t != "" {
- flagType = t
- }
- }
-
- rows = append(rows, []string{name, flagType, defaultValue, f.Usage})
- })
-
- sort.Slice(rows, func(i, j int) bool {
- return rows[i][0] < rows[j][0]
- })
-
- return rows
-}
-
-func renderHelpTable(headers []string, rows [][]string) {
- t := table.New().
- Border(lipgloss.NormalBorder()).
- BorderStyle(helpCmdBorder).
- StyleFunc(func(row, col int) lipgloss.Style {
- switch {
- case row == table.HeaderRow:
- return helpCmdHeader
- case row%2 == 0:
- return helpCmdEven
- default:
- return helpCmdOdd
- }
- }).
- Headers(headers...)
-
- if len(rows) > 0 {
- t = t.Rows(rows...)
- }
- lipgloss.Println(helpTableWrap.Render(fmt.Sprint(t)))
+ instrumentCommandTreeInternal(rootCmd)
}
diff --git a/cli/pkg/version/cmd.go b/cli/pkg/version/cmd.go
index b39345720..570b0ea5b 100644
--- a/cli/pkg/version/cmd.go
+++ b/cli/pkg/version/cmd.go
@@ -27,21 +27,21 @@ var VersionCmd = &cobra.Command{
return err
}
- logger.GetLogger().Debug("Sending request to ", clitypes.Endpoints.VersionEndpoint)
+ logger.GetLogger().Debug("Sending request", "endpoint", clitypes.Endpoints.VersionEndpoint)
resp, err := c.Get(cmd.Context(), clitypes.Endpoints.VersionEndpoint)
if err != nil {
return fmt.Errorf("failed to get version: %w", err)
}
defer func() { _ = resp.Body.Close() }()
- logger.GetLogger().Debugf("Response status: %s", resp.Status)
+ logger.GetLogger().Debug("Response received", "status", resp.Status)
body, err := io.ReadAll(resp.Body)
if err != nil {
return fmt.Errorf("failed to read response: %w", err)
}
- logger.GetLogger().Debugf("Raw response: %s", string(body))
+ logger.GetLogger().Debug("Raw response", "body", string(body))
var result version.Info
@@ -49,7 +49,7 @@ var VersionCmd = &cobra.Command{
return fmt.Errorf("failed to parse response: %w", err)
}
- logger.GetLogger().Debugf("Parsed version data: %+v", result)
+ logger.GetLogger().Debug("Parsed version data", "result", result)
if cmdutil.JSONOutputEnabled(cmd) {
resultBytes, err := json.MarshalIndent(result, "", " ")
diff --git a/go.work.sum b/go.work.sum
index 968a1fac2..52bbfee34 100644
--- a/go.work.sum
+++ b/go.work.sum
@@ -252,6 +252,8 @@ github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyY
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/certifi/gocertifi v0.0.0-20200922220541-2c3bb06c6054 h1:uH66TXeswKn5PW5zdZ39xEwfS9an067BirqA+P4QaLI=
github.com/charmbracelet/x/ansi v0.11.3/go.mod h1:yI7Zslym9tCJcedxz5+WBq+eUGMJT0bM06Fqy1/Y4dI=
+github.com/charmbracelet/x/cellbuf v0.0.15 h1:ur3pZy0o6z/R7EylET877CBxaiE1Sp1GMxoFPAIztPI=
+github.com/charmbracelet/x/cellbuf v0.0.15/go.mod h1:J1YVbR7MUuEGIFPCaaZ96KDl5NoS0DAWkskup+mOY+Q=
github.com/checkpoint-restore/checkpointctl v1.4.0 h1:3kRns56TArwiyHOMakaumUgSZZlB1hZBkjVgR6IeZ3E=
github.com/checkpoint-restore/checkpointctl v1.4.0/go.mod h1:ynQ52zQBazgcTZuxpwTFzRinIcAf0haDTC1X1LA/FKA=
github.com/checkpoint-restore/go-criu/v7 v7.2.0 h1:qGiWA4App1gGlEfIJ68WR9jbezV9J7yZdjzglezcqKo=