cmd

package
v0.8.11 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 23, 2026 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var RootCmd = &cobra.Command{
	Use:           "kcp",
	Short:         "A CLI tool for kafka cluster planning and migration",
	Long:          "A comprehensive CLI tool for planning and executing kafka cluster migrations to confluent cloud. Docs: " + build_info.DocsURL(),
	SilenceErrors: true,
	PersistentPreRun: func(cmd *cobra.Command, args []string) {

		lumberjackLogger := &lumberjack.Logger{
			Filename: "kcp.log",
			MaxSize:  25,
			Compress: true,
		}

		fileHandler := NewPrettyHandler(lumberjackLogger, PrettyHandlerOptions{
			SlogOpts: slog.HandlerOptions{
				Level: slog.LevelDebug,
			},
		})

		consoleLevel := slog.LevelWarn
		if verbose {
			consoleLevel = slog.LevelDebug
		}
		consoleHandler := NewPrettyHandler(os.Stdout, PrettyHandlerOptions{
			SlogOpts: slog.HandlerOptions{
				Level: consoleLevel,
			},
			Console: true,
		})

		logger := slog.New(NewFanOutHandler(fileHandler, consoleHandler))
		slog.SetDefault(logger)

		logging.SetFile(slog.New(fileHandler))

		if build_info.IsDev() {
			fmt.Printf("\n%s\n%s\n%s\n%s\n%s\n\n",
				color.RedString("┌─────────────────────────────────────────────────────────────────────────────────────────────┐"),
				color.RedString("│ ⚠️  WARNING: This is a development build — not a defined release.                            │"),
				color.RedString("│ This build and any state files it generates should NOT be used for production or live use.  │"),
				color.RedString("│ Install a released binary: https://github.com/confluentinc/kcp/releases                     │"),
				color.RedString("└─────────────────────────────────────────────────────────────────────────────────────────────┘"))
		}

		fmt.Printf("%s %s %s %s\n",
			color.CyanString("Executing kcp with build"),
			color.GreenString("version=%s", build_info.Version),
			color.YellowString("commit=%s", build_info.Commit),
			color.BlueString("date=%s", build_info.Date))

		// Detailed, structured build provenance for support diagnostics. Logged at
		// Debug so it lands in kcp.log (file handler is Debug+) without doubling the
		// coloured banner above on the console (Debug is below the console default).
		//
		// vcs_modified is Go's `vcs.modified` build stamp — did the working tree have
		// uncommitted changes when the binary was built? It matters for support because
		// the commit hash alone doesn't fully describe a dirty build:
		//   "true"  — built from a dirty tree; commit + local edits, not reproducible.
		//   "false" — built from a clean checkout; commit hash fully describes the binary.
		//   ""      — no VCS stamp (built outside a git checkout, e.g. from a tarball).
		var vcsModified string
		if bi, ok := debug.ReadBuildInfo(); ok {
			for _, s := range bi.Settings {
				if s.Key == "vcs.modified" {
					vcsModified = s.Value
					break
				}
			}
		}

		slog.Debug("build provenance",
			"cmd", cmd.CommandPath(),
			"version", build_info.Version,
			"commit", build_info.Commit,
			"date", build_info.Date,
			"dev_build", build_info.IsDev(),
			"vcs_modified", vcsModified,
			"go", runtime.Version(),
			"os", runtime.GOOS,
			"arch", runtime.GOARCH,
		)

		if err := checkWritePermissions(); err != nil {
			fmt.Fprintf(os.Stderr, "%s\n", color.RedString("Error: %v", err))
			os.Exit(1)
		}
	},
}

Functions

This section is empty.

Types

type FanOutHandler added in v0.7.0

type FanOutHandler struct {
	// contains filtered or unexported fields
}

func NewFanOutHandler added in v0.7.0

func NewFanOutHandler(handlers ...slog.Handler) *FanOutHandler

func (*FanOutHandler) Enabled added in v0.7.0

func (h *FanOutHandler) Enabled(ctx context.Context, level slog.Level) bool

func (*FanOutHandler) Handle added in v0.7.0

func (h *FanOutHandler) Handle(ctx context.Context, r slog.Record) error

func (*FanOutHandler) WithAttrs added in v0.7.0

func (h *FanOutHandler) WithAttrs(attrs []slog.Attr) slog.Handler

func (*FanOutHandler) WithGroup added in v0.7.0

func (h *FanOutHandler) WithGroup(name string) slog.Handler

type PrettyHandler

type PrettyHandler struct {
	slog.Handler
	// contains filtered or unexported fields
}

func NewPrettyHandler

func NewPrettyHandler(
	out io.Writer,
	opts PrettyHandlerOptions,
) *PrettyHandler

func (*PrettyHandler) Handle

func (h *PrettyHandler) Handle(ctx context.Context, r slog.Record) error

type PrettyHandlerOptions

type PrettyHandlerOptions struct {
	SlogOpts slog.HandlerOptions

	// Console renders INFO records as clean, human-facing narrative (no
	// time/level prefix) and colours the level on WARN/ERROR. The file
	// handler leaves this false so kcp.log keeps the full structured form.
	Console bool
}

Directories

Path Synopsis
Command gen-docs regenerates the per-command markdown reference under docs/assets/command-reference/ from the Cobra command tree.
Command gen-docs regenerates the per-command markdown reference under docs/assets/command-reference/ from the Cobra command tree.
ui
api

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL