cmd

package
v0.2.24 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2026 License: MIT Imports: 27 Imported by: 0

Documentation

Overview

Package cmd provides CLI flag registration using a modular pattern.

To add a new flag without causing merge conflicts: 1. Create a new file (e.g., flags_myfeature.go) 2. Define your flag variable and default at the top 3. Create an init() function that calls RegisterFlag()

Example (flags_myfeature.go):

package cmd

var myFeatureEnabled bool

func init() {
	RegisterFlag(func(cmd *cobra.Command) {
		cmd.Flags().BoolVar(&myFeatureEnabled, "my-feature", false, "Enable my feature")
	})
}

Flag Defaults with Environment Variable Overrides

Flags whose defaults can be overridden by an environment variable use inline envutil.GetEnv* calls directly in the RegisterFlag block:

cmd.Flags().StringVar(&myDir, "my-dir", envutil.GetEnvString("MY_DIR_ENV", config.DefaultMyDir), "...")

This keeps the env-var name co-located with the flag declaration.

Exception: getDefaultDIFCMode() in flags_difc.go is kept as a named helper because it contains validation logic beyond a simple env lookup.

When adding a new flag with an environment variable override:

  1. Use envutil.GetEnv* directly in the RegisterFlag call.
  2. Document the environment variable in AGENTS.md and README.md.

Index

Constants

View Source
const (
	// DefaultListenIPv4 is the default interface used by the HTTP server.
	DefaultListenIPv4 = "127.0.0.1"
	// DefaultListenPort is the default port used by the HTTP server.
	DefaultListenPort = "3000"
)

Exported constants for use by other packages

Variables

This section is empty.

Functions

func Execute

func Execute()

Execute runs the root command

func RegisterFlag

func RegisterFlag(fn FlagRegistrar)

RegisterFlag adds a flag registrar to be called during init This allows each feature to register its own flags without modifying root.go

func SetVersion

func SetVersion(v string)

SetVersion sets the version string for the CLI

Types

type FlagRegistrar

type FlagRegistrar func(cmd *cobra.Command)

FlagRegistrar is a function that registers flags on a command

Jump to

Keyboard shortcuts

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