application

package
v0.5.5 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2025 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LogLevelTrace   LogLevel  = "trace"
	LogLevelDebug   LogLevel  = "debug"
	LogLevelInfo    LogLevel  = "info"
	LogLevelWarn    LogLevel  = "warn"
	LogLevelError   LogLevel  = "error"
	LogLevelFatal   LogLevel  = "fatal"
	LogOutputStdout LogOutput = "stdout"
	LogOutputStderr LogOutput = "stderr"
	LogOutputFile   LogOutput = "file"
	LogFormatText   LogFormat = "text"
	LogFormatJson   LogFormat = "json"
	LogFormatColor  LogFormat = "color"
)

Variables

View Source
var (
	DefaultShutdownSignals = []os.Signal{syscall.SIGINT, syscall.SIGTERM, syscall.SIGHUP, syscall.SIGQUIT}
	DefaultShutdownTimeout = time.Second * 5
)

Shutdown configuration

View Source
var PersistentFlagsDefault = PersistentFlags{
	AddJsonFlag:      false,
	AddQuietFlag:     false,
	AddNoColorFlag:   false,
	AddVerboseFlag:   true,
	AddVersionFlag:   true,
	DefaultLogOutput: LogOutputStderr,
	DefaultLogLevel:  LogLevelInfo,
	DefaultLogFormat: LogFormatText,
}

Functions

func GetLogLevelFromArgs

func GetLogLevelFromArgs(args []string, defaultLevel slog.Level) slog.Level

func HelpFuncE

func HelpFuncE(cmd *cobra.Command, args []string) error

func InitializeBannerOnSubCommands added in v0.3.0

func InitializeBannerOnSubCommands(cmd *cobra.Command)

func InitializeSubCommandPrinter added in v0.3.0

func InitializeSubCommandPrinter(cmd *cobra.Command)

func RunCatchFuncE

func RunCatchFuncE(cmd *cobra.Command, args []string) error

RunCatchFuncE is an empty catch function to allow overrides through persistentPreRunE

Types

type Application

type Application interface {
	ExecuteContext(ctx context.Context) error
}

func New

func New(builder Builder, quitter Quitter) (Application, error)

type Builder added in v0.4.0

type Builder struct {
	Name                     string
	Title                    string
	Banner                   string
	OverrideRunE             func(cmd *cobra.Command, args []string) error
	ConfigureRoot            func(cmd *cobra.Command)
	ParseArgsFromStdin       bool
	PersistentFlags          PersistentFlags
	PersistentPreRunE        []func(cmd *cobra.Command, args []string) error // collection of PreRunE functions
	PersistentPostRunE       []func(cmd *cobra.Command, args []string) error // collection of PostRunE functions
	SubCommands              []Commander
	SubCommandsBannerEnabled bool
	SubCommandInitializers   []func(cmd *cobra.Command)
	TraverseRunHooks         bool
	ValidArgs                []string
	EnableVersionCommand     bool
}

func (Builder) RegisterCommand added in v0.4.0

func (b Builder) RegisterCommand(cmd Commander)

func (Builder) RegisterCommands added in v0.4.0

func (b Builder) RegisterCommands(cmds []Commander)

func (Builder) RegisterPersistentPostRunE added in v0.4.0

func (b Builder) RegisterPersistentPostRunE(f func(cmd *cobra.Command, args []string) error)

func (Builder) RegisterPersistentPreRunE added in v0.4.0

func (b Builder) RegisterPersistentPreRunE(f func(cmd *cobra.Command, args []string) error)

func (Builder) Validate added in v0.4.0

func (b Builder) Validate() error

type Command

type Command struct {
	Command     *cobra.Command
	SubCommands []Commander
	Configure   func(c *cobra.Command)
}

func (Command) Initialize

func (c Command) Initialize(f []func(cmd *cobra.Command)) *cobra.Command

type Commander

type Commander interface {
	Initialize(f []func(c *cobra.Command)) *cobra.Command
}

type LogDestination added in v0.5.4

type LogDestination string

type LogFormat added in v0.5.3

type LogFormat string

type LogLevel added in v0.5.3

type LogLevel string

type LogOutput added in v0.5.3

type LogOutput string

type PersistentFlags added in v0.5.0

type PersistentFlags struct {
	AddJsonFlag      bool
	AddQuietFlag     bool
	AddNoColorFlag   bool
	AddVerboseFlag   bool
	AddVersionFlag   bool
	DefaultLogOutput LogOutput
	DefaultLogLevel  LogLevel
	DefaultLogFormat LogFormat
}

type Quitter added in v0.3.0

type Quitter interface {
	IsGraceful() bool
	HasSignals() bool
	ShutdownSignals() []os.Signal
	Timeout() time.Duration
}

func NewDefaultQuitter added in v0.3.0

func NewDefaultQuitter(timeout time.Duration) Quitter

func NewQuitter added in v0.3.0

func NewQuitter(signals []os.Signal, timeout time.Duration, graceful bool) Quitter

type Version

type Version struct {
	Full       string
	Branch     string
	Tag        string
	Commit     string
	CommitDate string
	BuildDate  string
	Major      string
	Minor      string
	Patch      string
	PreRelease string
}

func (Version) IsValid

func (v Version) IsValid() bool

Jump to

Keyboard shortcuts

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