Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ExecutionContext ¶
type ExecutionContext struct {
// AppName is the executable app name
// Keep it in lower case letters and use dashes for multi-word app names
AppName string
// ShortDescription is a short description of the app
ShortDescription string
// LongDescription is a long description of the app
LongDescription string
// Stdin is the input stream
Stdin io.Reader
// Stdout is the output stream
Stdout io.Writer
// Stderr is the error stream
Stderr io.Writer
// Command is the current command
Command *cobra.Command
// CommandArgs are the arguments passed to the command
CommandArgs []string
// Logger is the global logger
Logger *slog.Logger
// ErrorHandler
ErrorHandler errors.Handler
// Spinner is the global spinner object used to show progress across the cli
Spinner ui.Spinner
// IsTerminal indicates whether the current session is a terminal or not
IsTerminal bool
// Version is the CLI version
// Flag: --version
Version string
// PFlags are the persistent flag configuration
PFlags PFlags
// OutputFormat is the format used for outputting data
// Flags: --plain, --json, --yaml, --markdown, etc
OutputFormat OutputFormat
// for changing log level
LogLevel *slog.LevelVar
}
ExecutionContext holds configuration that can be used (and modified) across the application
func NewExecutionContext ¶
func NewExecutionContext(appName, shortDesc, version string, stdin io.Reader, stdout, stderr io.Writer) *ExecutionContext
NewExecutionContext creates a new ExecutionContext
func (*ExecutionContext) SetColor ¶
func (ec *ExecutionContext) SetColor(noColor bool)
SetColor sets weather color should be used in the output If the output is not a terminal, color is disabled If the --no-color flag is set, color is disabled If the --no-input flag is set, color is disabled
func (*ExecutionContext) SetLogLevel ¶
func (ec *ExecutionContext) SetLogLevel()
SetLogLevel sets the ec.Logger log level
type OutputFormat ¶
type OutputFormat string
const ( OutputFormatPlain OutputFormat = "plain" OutputFormatJSON OutputFormat = "json" OutputFormatYAML OutputFormat = "yaml" OutputFormatMarkdown OutputFormat = "markdown" )
func (OutputFormat) String ¶
func (o OutputFormat) String() string
type PFlags ¶ added in v0.8.3
type PFlags struct {
// LogFormat is the log format used for the logger
// The ForFormat flag is always enabled
// Flag: --log-format [plain|json]
LogFormat log.Format
// LogLevel is the log level used for the logger
// The LogLevel flag is always enabled
// Flag: --log-level [debug|info|warn|error]
LogLevel log.Level
// ForceEnabled is used to enable the Force flag
ForceEnabled bool
// Force is used to force actions
// Flags: --force, -f
Force bool
// DryRun is used to simulate actions
// Flags: --dry-run
DryRun bool
// DryRunEnabled is used to enable the DryRun flag
DryRunEnabled bool
// NoINput can be used to disable interactive mode
// Flags: --no-input
NoInput bool
// NoInputEnabled is used to enable the NoInput flag
NoInputEnabled bool
// NoColor is used to control whether color is used in output
// The NoColor flag is always enabled
// Flags: --no-color
NoColor bool
// Quiet is used to control whether output is suppressed
// Flags: --quiet, -q
Quiet bool
// QuietEnabled is used to enable the Quiet flag
QuietEnabled bool
// Debug is used for debugging
// Usually this implies verbose output
// The Debug flag is always enabled
// Flags: --debug, -d
Debug bool
// OutputFormatEnabled is used to enable the OutputFormat flag
PlainEnabled bool
JSONEnabled bool
YAMLEnabled bool
MarkdownEnabled bool
// NoHeaders is used to control whether headers are printed
// Flag: --no-headers
NoHeaders bool
// NoHeadersEnabled is used to enable the NoHeaders flag
NoHeadersEnabled bool
}
Click to show internal directories.
Click to hide internal directories.