Documentation
¶
Overview ¶
Package cli provides the cli for go-orb.
Index ¶
- Constants
- func FlagValue[T any](f *Flag) (T, error)
- type App
- type AppConfigData
- type AppContext
- type Command
- type Flag
- type FlagOption
- type HardcodedConfig
- type ParserFunc
- type ServiceContext
- func (c *ServiceContext) App() *App
- func (c *ServiceContext) AppName() string
- func (c *ServiceContext) AppVersion() string
- func (c *ServiceContext) Context() context.Context
- func (c *ServiceContext) ExitAppGracefully(exitCode int)
- func (c *ServiceContext) Name() string
- func (c *ServiceContext) StopWaitGroup() *sync.WaitGroup
- func (c *ServiceContext) Version() string
- type ServiceContextWithConfig
Constants ¶
const MainActionName = "__main"
MainActionName is the name of the "main" action.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type App ¶
type App struct {
Name string
Version string
Usage string
Commands []*Command
Flags []*Flag
// NoMultiServiceConfig defines if the config is used with sections or without.
// If false, the config is used with sections.
// For example:
// “`yaml
// service1: # service1 section
// logger:
// level: INFO
// service2: # service2 section
// logger:
// level: INFO
// “`
//
// If true, the config is used without sections.
// For example:
// “`yaml
// logger:
// level: INFO
// “`
NoMultiServiceConfig bool
// NoAction defines if there will be no main action.
NoAction bool
// NoGlobalConfig defines if the global config flag should be added and parsed.
NoGlobalConfig bool
// HardcodedConfigs defines the hardcoded configs.
HardcodedConfigs []HardcodedConfig
// HardcodedConfigURLs defines the hardcoded config URLs.
HardcodedConfigURLs []string
// Internal
InternalAction func() error
}
App represents a CLI Application.
type AppConfigData ¶
AppConfigData is the config data type.
func ProvideAppConfigData ¶
func ProvideAppConfigData(appContext *AppContext) (AppConfigData, error)
ProvideAppConfigData provides config data from appContext and flags.
type AppContext ¶
type AppContext struct {
SelectedService string
SelectedCommand []string
Context context.Context
StopWaitGroup *sync.WaitGroup
// contains filtered or unexported fields
}
AppContext holds app state of the main application for multiple services.
func NewAppContext ¶
func NewAppContext(app *App) *AppContext
NewAppContext creates a new Application context.
func (*AppContext) ExitGracefully ¶
func (c *AppContext) ExitGracefully(exitCode int)
ExitGracefully exits the application gracefully.
func (*AppContext) Name ¶
func (c *AppContext) Name() string
Name returns the name of the application.
func (*AppContext) Version ¶
func (c *AppContext) Version() string
Version returns the version of the application.
type Command ¶
type Command struct {
Name string
Service string
Category string
Usage string
Flags []*Flag
Subcommands []*Command
NoAction bool
// Internal
InternalAction func() error
}
Command is a CLI Command for App.
type Flag ¶
type Flag struct {
Name string
EnvVars []string
Usage string
// The path in map(\[string\])+any
ConfigPaths [][]string
Default any
Value any
}
Flag is a Cli Flag and maybe environment variable.
func NewFlag ¶
func NewFlag[T any]( name string, defaultValue T, opts ...FlagOption, ) *Flag
NewFlag creates a new CLI flag.
func ProvideParsedFlagsFromArgs ¶
func ProvideParsedFlagsFromArgs(appContext *AppContext, parser ParserFunc, args []string) ([]*Flag, error)
ProvideParsedFlagsFromArgs provides parsed flags from the app context.
type FlagOption ¶
type FlagOption func(*Flag)
FlagOption is an option for NewFlag.
func FlagConfigPaths ¶
func FlagConfigPaths(n ...[]string) FlagOption
FlagConfigPaths appends the config paths for the flag.
func FlagEnvVars ¶
func FlagEnvVars(n ...string) FlagOption
FlagEnvVars set's environment variables for the flag.
type HardcodedConfig ¶
HardcodedConfig represents a hardcoded config with it's format. Format can be any of the importet codecs.
type ParserFunc ¶
type ParserFunc func(appContext *AppContext, args []string) ([]*Flag, error)
ParserFunc is a provider function type for parsing flags.
type ServiceContext ¶
type ServiceContext struct {
// contains filtered or unexported fields
}
ServiceContext holds the service state.
func NewServiceContext ¶
func NewServiceContext(appContext *AppContext, name string, version string) *ServiceContext
NewServiceContext creates a new Service context for the given service.
func ProvideSingleServiceContext ¶
func ProvideSingleServiceContext(appContext *AppContext) (*ServiceContext, error)
ProvideSingleServiceContext provides a single service context for the application.
func (*ServiceContext) AppName ¶
func (c *ServiceContext) AppName() string
AppName returns the name of the application.
func (*ServiceContext) AppVersion ¶
func (c *ServiceContext) AppVersion() string
AppVersion returns the version of the application.
func (*ServiceContext) Context ¶
func (c *ServiceContext) Context() context.Context
Context returns the context of the application.
func (*ServiceContext) ExitAppGracefully ¶
func (c *ServiceContext) ExitAppGracefully(exitCode int)
ExitAppGracefully exits the application gracefully.
func (*ServiceContext) Name ¶
func (c *ServiceContext) Name() string
Name returns the name of the service.
func (*ServiceContext) StopWaitGroup ¶
func (c *ServiceContext) StopWaitGroup() *sync.WaitGroup
StopWaitGroup returns the stop wait group of the application.
func (*ServiceContext) Version ¶
func (c *ServiceContext) Version() string
Version returns the version of the service.
type ServiceContextWithConfig ¶
type ServiceContextWithConfig struct {
*ServiceContext
// contains filtered or unexported fields
}
ServiceContextWithConfig is a ServiceContext with a config.
func NewServiceContextWithConfig ¶
func NewServiceContextWithConfig(appContext *AppContext, name string, version string, configData map[string]any) *ServiceContextWithConfig
NewServiceContextWithConfig creates a new Service context for the given service with config.
func ProvideServiceConfigData ¶
func ProvideServiceConfigData( serviceContext *ServiceContext, appConfigData AppConfigData, flags []*Flag, ) (*ServiceContextWithConfig, error)
ProvideServiceConfigData provides config data to serviceContext from flags.
func (*ServiceContextWithConfig) Config ¶
func (c *ServiceContextWithConfig) Config() map[string]any
Config returns the configuration of the service.