Documentation
¶
Overview ¶
Package fang provides styling for cobra commands.
Index ¶
- func DefaultErrorHandler(w io.Writer, styles Styles, err error)
- func Execute(ctx context.Context, root *cobra.Command, options ...Option) error
- func InlineErrorHandler(w io.Writer, styles Styles, err error)
- type Codeblock
- type ColorScheme
- type ColorSchemeFunc
- type ErrorHandler
- type Option
- func WithAliases() Option
- func WithColorSchemeFunc(cs ColorSchemeFunc) Option
- func WithCommit(commit string) Option
- func WithErrorHandler(handler ErrorHandler) Option
- func WithFlagTypes() Option
- func WithGlobalFlags() Option
- func WithNotifySignal(signals ...os.Signal) Option
- func WithTheme(theme ColorScheme) Optiondeprecated
- func WithVersion(version string) Option
- func WithWrappedExamples() Option
- func WithoutBox() Option
- func WithoutCompletions() Option
- func WithoutFill() Option
- func WithoutManpage() Option
- func WithoutVersion() Option
- type Program
- type Styles
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultErrorHandler ¶
DefaultErrorHandler is the default ErrorHandler implementation.
func InlineErrorHandler ¶ added in v2.4.0
InlineErrorHandler is an ErrorHandler that renders the error on a single line, with the ERROR badge and the message side by side:
ERROR Something went wrong
Long messages soft-wrap, with wrapped lines aligned under the message column. Unlike DefaultErrorHandler, it does not append a trailing period and does not show a "Try --help for usage." hint.
Types ¶
type Codeblock ¶
type Codeblock struct {
Base lipgloss.Style
Program Program
Text lipgloss.Style
Comment lipgloss.Style
}
Codeblock styles.
type ColorScheme ¶
type ColorScheme struct {
Base color.Color
Title color.Color
Description color.Color
Codeblock color.Color
Program color.Color
DimmedArgument color.Color
Comment color.Color
Flag color.Color
FlagDefault color.Color
Command color.Color
QuotedString color.Color
Argument color.Color
Help color.Color
Dash color.Color
ErrorHeader [2]color.Color // 0=fg 1=bg
ErrorDetails color.Color
}
ColorScheme describes a colorscheme.
func AnsiColorScheme ¶
func AnsiColorScheme(c lipgloss.LightDarkFunc) ColorScheme
AnsiColorScheme is a ANSI colorscheme.
func DefaultColorScheme ¶
func DefaultColorScheme(c lipgloss.LightDarkFunc) ColorScheme
DefaultColorScheme is the default colorscheme.
func DefaultTheme
deprecated
func DefaultTheme(isDark bool) ColorScheme
DefaultTheme is the default colorscheme.
Deprecated: use DefaultColorScheme instead.
type ColorSchemeFunc ¶
type ColorSchemeFunc = func(lipgloss.LightDarkFunc) ColorScheme
ColorSchemeFunc gets a lipgloss.LightDarkFunc and returns a ColorScheme.
type ErrorHandler ¶
ErrorHandler handles an error, printing them to the given io.Writer.
type Option ¶
type Option func(*settings)
Option changes fang settings.
func WithAliases ¶ added in v2.3.0
func WithAliases() Option
WithAliases renders an "aliases" section in the help output, listing the command's aliases, when it has any. The section appears right after the usage block.
func WithColorSchemeFunc ¶
func WithColorSchemeFunc(cs ColorSchemeFunc) Option
WithColorSchemeFunc sets a function that return colorscheme.
func WithErrorHandler ¶
func WithErrorHandler(handler ErrorHandler) Option
WithErrorHandler sets the error handler.
func WithFlagTypes ¶
func WithFlagTypes() Option
WithFlagTypes enables flag types in the help output.
func WithGlobalFlags ¶ added in v2.2.0
func WithGlobalFlags() Option
WithGlobalFlags renders persistent flags inherited from parent commands in a separate "global flags" section, instead of mixing them in with the command's own flags. This mirrors Cobra's built-in "Global Flags" split.
func WithNotifySignal ¶
WithNotifySignal sets the signals that should interrupt the execution of the program.
func WithTheme
deprecated
func WithTheme(theme ColorScheme) Option
WithTheme sets the colorscheme.
Deprecated: use WithColorSchemeFunc instead.
func WithWrappedExamples ¶
func WithWrappedExamples() Option
WithWrappedExamples soft-wraps long example lines to the width of the examples block instead of truncating them with an ellipsis.
func WithoutBox ¶ added in v2.5.0
func WithoutBox() Option
WithoutBox removes the box around the usage and examples sections entirely: no background fill and no border, leaving plain indented text. Takes precedence over WithoutFill.
func WithoutFill ¶ added in v2.5.0
func WithoutFill() Option
WithoutFill removes the background fill from the usage and examples blocks, drawing a rounded border around each instead. The sections remain boxed, just outlined rather than filled.
func WithoutVersion ¶
func WithoutVersion() Option
WithoutVersion skips the `-v`/`--version` functionality.
