mirror of
https://github.com/psviderski/uncloud.git
synced 2026-11-10 20:54:17 +00:00
fix: handle output redirect and NO_COLOR for 'uc caddy config'
This commit is contained in:
+4
-11
@@ -3,8 +3,8 @@ package caddy
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
|
||||||
|
|
||||||
|
"charm.land/lipgloss/v2"
|
||||||
"github.com/alecthomas/chroma/v2/quick"
|
"github.com/alecthomas/chroma/v2/quick"
|
||||||
"github.com/psviderski/uncloud/internal/cli"
|
"github.com/psviderski/uncloud/internal/cli"
|
||||||
"github.com/psviderski/uncloud/internal/cli/completion"
|
"github.com/psviderski/uncloud/internal/cli/completion"
|
||||||
@@ -15,7 +15,6 @@ import (
|
|||||||
|
|
||||||
type configOptions struct {
|
type configOptions struct {
|
||||||
machine string
|
machine string
|
||||||
noColor bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewConfigCommand() *cobra.Command {
|
func NewConfigCommand() *cobra.Command {
|
||||||
@@ -33,8 +32,6 @@ func NewConfigCommand() *cobra.Command {
|
|||||||
|
|
||||||
cmd.Flags().StringVarP(&opts.machine, "machine", "m", "",
|
cmd.Flags().StringVarP(&opts.machine, "machine", "m", "",
|
||||||
"Name or ID of the machine to get the configuration from. (default is connected machine)")
|
"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)
|
completion.MachinesFlag(cmd)
|
||||||
|
|
||||||
@@ -54,13 +51,9 @@ func runConfig(ctx context.Context, uncli *cli.CLI, opts configOptions) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Print the Caddyfile with syntax highlighting.
|
// Print the Caddyfile with syntax highlighting.
|
||||||
if opts.noColor {
|
if err = quick.Highlight(lipgloss.Writer, config.Caddyfile, "caddy", "terminal256", "monokai"); err != nil {
|
||||||
fmt.Print(config.Caddyfile)
|
// If highlighting fails, fall back to plain output.
|
||||||
} else {
|
lipgloss.Print(config.Caddyfile)
|
||||||
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 config.LastReconciliationError != "" {
|
if config.LastReconciliationError != "" {
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ uc caddy config [flags]
|
|||||||
```
|
```
|
||||||
-h, --help help for config
|
-h, --help help for config
|
||||||
-m, --machine string Name or ID of the machine to get the configuration from. (default is connected machine)
|
-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
|
## Options inherited from parent commands
|
||||||
|
|||||||
Reference in New Issue
Block a user