From c16e452439fcc5b820773aa658ea274e0edbb42b Mon Sep 17 00:00:00 2001 From: Pasha Sviderski Date: Mon, 19 Oct 2026 12:15:01 +1000 Subject: [PATCH] fix: handle output redirect and NO_COLOR for 'uc caddy config' --- cmd/uc/caddy/config.go | 15 ++++----------- website/docs/9-cli-reference/uc_caddy_config.md | 1 - 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/cmd/uc/caddy/config.go b/cmd/uc/caddy/config.go index 972573d1..87a291b7 100644 --- a/cmd/uc/caddy/config.go +++ b/cmd/uc/caddy/config.go @@ -3,8 +3,8 @@ package caddy import ( "context" "fmt" - "os" + "charm.land/lipgloss/v2" "github.com/alecthomas/chroma/v2/quick" "github.com/psviderski/uncloud/internal/cli" "github.com/psviderski/uncloud/internal/cli/completion" @@ -15,7 +15,6 @@ import ( type configOptions struct { machine string - noColor bool } func NewConfigCommand() *cobra.Command { @@ -33,8 +32,6 @@ func NewConfigCommand() *cobra.Command { cmd.Flags().StringVarP(&opts.machine, "machine", "m", "", "Name or ID of the machine to get the configuration from. (default is connected machine)") - cmd.Flags().BoolVar(&opts.noColor, "no-color", false, - "Disable syntax highlighting for the output.") completion.MachinesFlag(cmd) @@ -54,13 +51,9 @@ func runConfig(ctx context.Context, uncli *cli.CLI, opts configOptions) error { } // Print the Caddyfile with syntax highlighting. - if opts.noColor { - fmt.Print(config.Caddyfile) - } else { - if err = quick.Highlight(os.Stdout, config.Caddyfile, "caddy", "terminal256", "monokai"); err != nil { - // If highlighting fails, fall back to plain output. - fmt.Print(config.Caddyfile) - } + if err = quick.Highlight(lipgloss.Writer, config.Caddyfile, "caddy", "terminal256", "monokai"); err != nil { + // If highlighting fails, fall back to plain output. + lipgloss.Print(config.Caddyfile) } if config.LastReconciliationError != "" { diff --git a/website/docs/9-cli-reference/uc_caddy_config.md b/website/docs/9-cli-reference/uc_caddy_config.md index 4a787675..1f6e4142 100644 --- a/website/docs/9-cli-reference/uc_caddy_config.md +++ b/website/docs/9-cli-reference/uc_caddy_config.md @@ -15,7 +15,6 @@ uc caddy config [flags] ``` -h, --help help for config -m, --machine string Name or ID of the machine to get the configuration from. (default is connected machine) - --no-color Disable syntax highlighting for the output. ``` ## Options inherited from parent commands