Documentation
¶
Index ¶
- Variables
- func BuildInlineFormatMultiError() *multierror.Error
- type App
- func (a *App) Args() []string
- func (a *App) Context() context.Context
- func (a *App) GenerateCompletion(config CompletionConfig) error
- func (a *App) GetVersion() (VersionInfo, error)
- func (a *App) Run(ctx context.Context, args []string) error
- func (a *App) Stderr() io.Writer
- func (a *App) Stdin() io.Reader
- func (a *App) Stdout() io.Writer
- type AppOption
- func WithFlags(fn func(*flag.FlagSet)) AppOption
- func WithLogConfig(config LogConfig) AppOption
- func WithRequiredArguments(i int) AppOption
- func WithRunFunc(fn RunFunc) AppOption
- func WithStderr(serr io.Writer) AppOption
- func WithStdin(sin io.Reader) AppOption
- func WithStdout(sout io.Writer) AppOption
- func WithStreams(sin io.Reader, sout, serr io.Writer) AppOption
- func WithVersion(version string) AppOption
- type CompletionConfig
- type CompletionOption
- type LogConfig
- type LogOption
- type RunFunc
- type ShellType
- type VersionInfo
Constants ¶
This section is empty.
Variables ¶
var SetupLogging = func(config LogConfig) { var handler slog.Handler if config.Format == "json" { handler = slog.NewJSONHandler(config.Output, &slog.HandlerOptions{ Level: config.Level, }) } else { handler = slog.NewTextHandler(config.Output, &slog.HandlerOptions{ Level: config.Level, }) } logger := slog.New(handler) slog.SetDefault(logger) }
SetupLogging configures the global logger based on the provided config It's a variable to allow for testing
Functions ¶
func BuildInlineFormatMultiError ¶ added in v0.14.0
func BuildInlineFormatMultiError() *multierror.Error
Types ¶
type App ¶
type App struct {
// Debug enables debug logging
Debug bool
// ExitFunc is used for testing
ExitFunc func(int)
// contains filtered or unexported fields
}
App represents a command-line application with common functionality
func (*App) GenerateCompletion ¶ added in v0.11.0
func (a *App) GenerateCompletion(config CompletionConfig) error
GenerateCompletion generates shell completion for the app
func (*App) GetVersion ¶ added in v0.13.0
func (a *App) GetVersion() (VersionInfo, error)
type AppOption ¶
type AppOption func(*App)
AppOption is a function that configures an App
func WithLogConfig ¶
WithLogConfig sets a custom logging configuration
func WithRequiredArguments ¶ added in v0.17.0
WithRequiredArguments sets the minimum number of required arguments
func WithRunFunc ¶
WithRunFunc sets the main function to execute
func WithStderr ¶ added in v0.14.0
WithStderr configures stderr for the application
func WithStdout ¶ added in v0.14.0
WithStdout configures stdout for the application
func WithStreams ¶ added in v0.14.0
WithStreams configures all streams
func WithVersion ¶
WithVersion sets a custom version for the application
type CompletionConfig ¶ added in v0.11.0
type CompletionConfig struct {
// Shell is the type of shell to generate completion for
Shell ShellType
// Output is where to write the completion script
Output io.Writer
}
CompletionConfig holds configuration for shell completion
func DefaultCompletionConfig ¶ added in v0.11.0
func DefaultCompletionConfig() CompletionConfig
DefaultCompletionConfig returns the default completion configuration
func NewCompletionConfig ¶ added in v0.11.0
func NewCompletionConfig(opts ...CompletionOption) CompletionConfig
NewCompletionConfig creates a new completion configuration with options
type CompletionOption ¶ added in v0.11.0
type CompletionOption func(*CompletionConfig)
CompletionOption configures the completion generator
func WithCompletionOutput ¶ added in v0.11.0
func WithCompletionOutput(output io.Writer) CompletionOption
WithCompletionOutput sets the output for the completion script
func WithCompletionShell ¶ added in v0.11.0
func WithCompletionShell(shell ShellType) CompletionOption
WithCompletionShell sets the shell type for completion
type LogConfig ¶
type LogConfig struct {
// Level is the minimum log level to output
Level slog.Level
// Output is where logs will be written (defaults to stderr)
Output io.Writer
// Format determines the log format (text or json)
Format string
}
LogConfig holds configuration for setting up logging
func DefaultLogConfig ¶
func DefaultLogConfig() LogConfig
DefaultLogConfig returns a default logging configuration
func NewLogConfig ¶
NewLogConfig creates a new logging configuration with options
type LogOption ¶
type LogOption func(*LogConfig)
LogOption is a function that configures a LogConfig
func WithLogFormat ¶
WithLogFormat sets the log format (text or json)
func WithLogLevel ¶
WithLogLevel sets the minimum log level
func WithLogOutput ¶
WithLogOutput sets where logs will be written
type ShellType ¶ added in v0.11.0
type ShellType string
ShellType represents a supported shell for completion
type VersionInfo ¶
type VersionInfo struct {
Arch string
BuildTime string
Commit string
Dirty string
GoVersion string
Name string
OS string
Version string
GitTime time.Time
MainVersion string
}
VersionInfo holds version information for the application
func (VersionInfo) String ¶
func (v VersionInfo) String() (string, error)
String returns a formatted version string