mirror of
https://github.com/psviderski/uncloud.git
synced 2026-08-26 11:03:34 +00:00
* chore: fix landing logo shadow * feat: implement service logs command with colored output and strict ordering * revert Makefile * fix after rebase * move logs command under services with root shortcut * simplify server options for streaming logs and CLI flags * refactor ContainerLogs grpc server * update --tail flag * minor docker.proto * refactor client ServiceLogs and ContainerLogs * move ProxyMachinesContext from api to client pkg * minor refactor proto Stream * add api/logs * implement LogMerger * fix LogMerger to correctly use semaphore * increate inflish entries to 100 per stream * send heartbeats * refactor ContainerLogs to synchronise Send of entries and heartbeats to the steram * minor logmerege * remove ContainerName form ServiceLogEntryMetadata * refactor ContainerLogs into docker.Service * detect stalled container logs streams * update logmerger tests * fix comment in test * refactor LogMerger with options * uc logs: format one or multiple services * make LogMerger emit heartbeats, emit entries <= watermark, rewrite tests * update uc logs with new LogMerger * go mod tidy * fix after merge --------- Co-authored-by: Evgenii Orlov <evgenii.orlov@semrush.com>
71 lines
1.8 KiB
Go
71 lines
1.8 KiB
Go
package caddy
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"os"
|
|
|
|
"github.com/alecthomas/chroma/v2/quick"
|
|
"github.com/psviderski/uncloud/internal/cli"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
type configOptions struct {
|
|
machine string
|
|
noColor bool
|
|
}
|
|
|
|
func NewConfigCommand() *cobra.Command {
|
|
opts := configOptions{}
|
|
|
|
cmd := &cobra.Command{
|
|
Use: "config",
|
|
Short: "Show the current Caddy configuration (Caddyfile).",
|
|
Long: "Display the current Caddy configuration (Caddyfile) from the connected machine or a specified one.",
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
uncli := cmd.Context().Value("cli").(*cli.CLI)
|
|
return runConfig(cmd.Context(), uncli, opts)
|
|
},
|
|
}
|
|
|
|
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.")
|
|
|
|
return cmd
|
|
}
|
|
|
|
func runConfig(ctx context.Context, uncli *cli.CLI, opts configOptions) error {
|
|
clusterClient, err := uncli.ConnectCluster(ctx)
|
|
if err != nil {
|
|
return fmt.Errorf("connect to cluster: %w", err)
|
|
}
|
|
defer clusterClient.Close()
|
|
|
|
if opts.machine != "" {
|
|
// If a specific machine is requested, use it to get the Caddy configuration.
|
|
ctx, _, err = clusterClient.ProxyMachinesContext(ctx, []string{opts.machine})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
config, err := clusterClient.Caddy.GetConfig(ctx, nil)
|
|
if err != nil {
|
|
return fmt.Errorf("get Caddy config: %w", err)
|
|
}
|
|
|
|
// 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)
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|