subcmd

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RunCommand

func RunCommand(
	cmd *cobra.Command,
	runner Runner,
	shared *SharedFlags,
	appVersion, commitHash, buildTime string,
) error

Types

type Runner

type Runner interface {
	// FlagSets returns flag sets specific to this subcommand.
	// They are registered as regular Flags (not PersistentFlags).
	FlagSets() []*pflag.FlagSet

	// PostRegistration is called after all flags are registered on the cobra command.
	PostRegistration(cmd *cobra.Command)

	// SetHelpUsage sets custom help and usage functions on the command.
	SetHelpUsage(cmd *cobra.Command, shared *SharedFlagSets)

	// NewServiceConfig creates the service configuration from parsed flags.
	NewServiceConfig(ctx context.Context, shared *SharedFlags) (ServiceConfig, error)

	// RunService creates and runs the domain service.
	RunService(ctx context.Context, cfg ServiceConfig, logger *slog.Logger) error
}

Runner defines the contract each subcommand must implement.

type ServiceConfig

type ServiceConfig interface {
	GetApp() *models.App
	Validate() error
}

ServiceConfig must be implemented by every subcommand's config type so the builder can extract App settings for logger initialization.

type SharedFlagSets

type SharedFlagSets struct {
	App          *pflag.FlagSet
	Aerospike    *pflag.FlagSet
	ClientPolicy *pflag.FlagSet
	Compression  *pflag.FlagSet
	Encryption   *pflag.FlagSet
	SecretAgent  *pflag.FlagSet
	Aws          *pflag.FlagSet
	Gcp          *pflag.FlagSet
	Azure        *pflag.FlagSet
}

SharedFlagSets holds pflag.FlagSet objects created from SharedFlags. Subcommands use these to build their custom help functions.

func NewSharedFlagSets

func NewSharedFlagSets(shared *SharedFlags) SharedFlagSets

type SharedFlags

type SharedFlags struct {
	Root         *flags.Root
	App          *flags.App
	Aerospike    *asFlags.AerospikeFlags
	ClientPolicy *flags.ClientPolicy
	Compression  *flags.Compression
	Encryption   *flags.Encryption
	SecretAgent  *flags.SecretAgent
	Aws          *flags.AwsS3
	Gcp          *flags.GcpStorage
	Azure        *flags.AzureBlob
}

SharedFlags holds all flag objects shared across subcommands.

func BuildCommand

func BuildCommand(
	name, short, long string,
	flagsRoot *flags.Root,
	appVersion, commitHash, buildTime string,
	op flags.Operation,
	runner Runner,
) (*cobra.Command, *SharedFlags)

BuildCommand constructs a cobra.Command with shared flag registration and a standard run lifecycle: version check -> logger init -> service execution.

Jump to

Keyboard shortcuts

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