Documentation
¶
Overview ¶
Package core provides shared utilities and types for CLI command handling.
Index ¶
- func ExitOnShow(show root.ShowFuncType, args ...string) bool
- func KCreateSubcommandPreRunE(cmd *cobra.Command, cfg Trackable, show root.ShowFuncType) func(_ *cobra.Command, _ []string) error
- func SetSubcommandDefaults(cmd *cobra.Command, local any, show root.ShowFuncType)
- func SetupLogger(level string) (*logger.Logger, error)
- type CommandPath
- type Context
- type Embedded
- type Handler
- type Input
- type Trackable
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExitOnShow ¶
func ExitOnShow(show root.ShowFuncType, args ...string) bool
ExitOnShow determines if the command should exit early when show function is active and no arguments are provided.
func KCreateSubcommandPreRunE ¶
func KCreateSubcommandPreRunE( cmd *cobra.Command, cfg Trackable, show root.ShowFuncType, ) func(_ *cobra.Command, _ []string) error
KCreateSubcommandPreRunE creates a PreRunE function for Cobra commands that handles configuration loading, environment variable processing, flag parsing, and validation.
func SetSubcommandDefaults ¶
func SetSubcommandDefaults(cmd *cobra.Command, local any, show root.ShowFuncType)
SetSubcommandDefaults configures default settings for subcommands including pre-run hooks and configuration handling.
Types ¶
type CommandPath ¶
type CommandPath []string
CommandPath represents a hierarchical command path as a slice of strings, used for building configuration sections and environment variable prefixes.
func BuildCommandPath ¶
func BuildCommandPath(cmd *cobra.Command) CommandPath
BuildCommandPath constructs a CommandPath from a Cobra command's full path.
func (CommandPath) Env ¶
func (c CommandPath) Env() iutils.Prefix
Env returns the environment variable prefix for the command path, using underscore notation and uppercase letters.
func (CommandPath) Section ¶
func (c CommandPath) Section() iutils.Prefix
Section returns the configuration section prefix for the command path, excluding the root command and using dot notation.
func (CommandPath) WithoutRoot ¶
func (c CommandPath) WithoutRoot() CommandPath
WithoutRoot returns the command path excluding the root command.
type Context ¶
type Context struct {
// Config holds a map of the parsed configuration file.
Config *koanfx.Koanf
// DotEnv holds the parsed .env files
DotEnv *env.Env
// Env holds the parsed environment variables.
Env *env.Env
}
Context holds the parsed configuration.
var GlobalContext Context
GlobalContext is a global variable, allowing the root parsed configuration to be accessed from anywhere in the application.
type Embedded ¶
type Embedded struct {
// Defaults to be set for each tool (not flags).
Defaults []byte
// Default list of tools that can be used to either view or dump out.
Tools []byte
// A template for the cleanup script.
Template []byte
}
Embedded holds the embedded files for the application.
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler manages configuration resolution, logging, and embedded resources for CLI operations.
func NewHandler ¶
NewHandler creates a new Handler instance with the provided configuration and embedded resources.
func (*Handler) Resolve ¶
Resolve processes the configuration hierarchy by loading defaults, applying inheritance, and merging platform-specific settings for all tools.
func (*Handler) SetupLogger ¶
SetupLogger creates and configures a logger with the specified log level.
type Input ¶
type Input struct {
// Global contains the global configuration.
Global *root.Config
// Embedded contains the embedded configuration.
Embedded *Embedded
// Cmd is the current command being executed.
Cmd *cobra.Command
// Args are the arguments passed to the command.
Args []string
}
Input is the input structure for the CLI commands.