Documentation ¶
Overview ¶
Package cmdr provides abstractions to simplify and consolidate use of cobra and viper for cli applications.
Index ¶
- Variables
- func FlagValBool(name string) bool
- func FlagValBoolDefault(name string, def bool) bool
- func FlagValString(name string) string
- func FlagValStringDefault(name string, def string) string
- type App
- type BoolFlag
- type BulletListItem
- type Color
- type Command
- func NewCommand(use, long, short string, runE func(cmd *cobra.Command, args []string) error) *Command
- func NewCommandCustom(cmd *cobra.Command) *Command
- func NewCommandRun(use, long, short string, run func(cmd *cobra.Command, args []string)) *Command
- func NewCommandRunE(use, long, short string, runE func(cmd *cobra.Command, args []string) error) *Command
- func NewDocsCommand(a *App) *Command
- func NewManCommand(a *App) *Command
- func (c *Command) AddCommand(commands ...*Command)
- func (c *Command) Children() []*Command
- func (c *Command) WithBoolFlag(f BoolFlag) *Command
- func (c *Command) WithPersistentBoolFlag(f BoolFlag) *Command
- func (c *Command) WithPersistentStringFlag(f BoolFlag) *Command
- func (c *Command) WithStringFlag(f StringFlag) *Command
- type StringFlag
- type Style
Constants ¶
This section is empty.
Variables ¶
var ( Confirm pterm.InteractiveConfirmPrinter Prompt pterm.InteractiveTextInputPrinter )
var ( // Red is an alias for FgRed.Sprint. Red = FgRed.Sprint // Cyan is an alias for FgCyan.Sprint. Cyan = FgCyan.Sprint // Gray is an alias for FgGray.Sprint. Gray = FgGray.Sprint // Blue is an alias for FgBlue.Sprint. Blue = FgBlue.Sprint // Black is an alias for FgBlack.Sprint. Black = FgBlack.Sprint // Green is an alias for FgGreen.Sprint. Green = FgGreen.Sprint // White is an alias for FgWhite.Sprint. White = FgWhite.Sprint // Yellow is an alias for FgYellow.Sprint. Yellow = FgYellow.Sprint // Magenta is an alias for FgMagenta.Sprint. Magenta = FgMagenta.Sprint // Normal is an alias for FgDefault.Sprint. Normal = FgDefault.Sprint // LightRed is a shortcut for FgLightRed.Sprint. LightRed = FgLightRed.Sprint // LightCyan is a shortcut for FgLightCyan.Sprint. LightCyan = FgLightCyan.Sprint // LightBlue is a shortcut for FgLightBlue.Sprint. LightBlue = FgLightBlue.Sprint // LightGreen is a shortcut for FgLightGreen.Sprint. LightGreen = FgLightGreen.Sprint // LightWhite is a shortcut for FgLightWhite.Sprint. LightWhite = FgLightWhite.Sprint // LightYellow is a shortcut for FgLightYellow.Sprint. LightYellow = FgLightYellow.Sprint // LightMagenta is a shortcut for FgLightMagenta.Sprint. LightMagenta = FgLightMagenta.Sprint )
var (
Info, Warning, Success, Fatal, Debug, Description, Error pterm.PrefixPrinter
Spinner pterm.SpinnerPrinter
ProgressBar pterm.ProgressbarPrinter
BulletList pterm.BulletListPrinter
TerminalSize func() (int, int, error)
TerminalWidth, TerminalHeight func() int
NewStyle func(...Color) *Style
EnableColor, DisableColor func()
)
Functions ¶
func FlagValBool ¶
func FlagValBoolDefault ¶
func FlagValString ¶
func FlagValStringDefault ¶
Types ¶
type App ¶
type App struct { Name string Version string RootCommand *Command Logger *log.Logger *i18n.I18n // contains filtered or unexported fields }
The App struct represents the cli application with supporting functionality like internationalization and logging.
func NewApp ¶
NewApp creates a new command line application. It requires an embed.FS with a top level directory named 'locales'.
func (*App) CreateRootCommand ¶
type BoolFlag ¶
type BoolFlag struct { Value bool // contains filtered or unexported fields }
func NewBoolFlag ¶
type BulletListItem ¶ added in v0.3.2
type BulletListItem = pterm.BulletListItem
type Color ¶ added in v0.3.2
const ( FgBlack Color = iota + 30 FgRed FgGreen FgYellow FgBlue FgMagenta FgCyan FgWhite // FgDefault revert default FG. FgDefault Color = 39 )
Foreground colors. basic foreground colors 30 - 37.
const ( FgDarkGray Color = iota + 90 FgLightRed FgLightGreen FgLightYellow FgLightBlue FgLightMagenta FgLightCyan FgLightWhite // FgGray is an alias of FgDarkGray. FgGray Color = 90 )
Extra foreground color 90 - 97.
const ( BgBlack Color = iota + 40 BgRed BgGreen BgYellow // BgBrown like yellow BgBlue BgMagenta BgCyan BgWhite // BgDefault reverts to the default background. BgDefault Color = 49 )
Background colors. basic background colors 40 - 47.
type Command ¶
Command represents a cli command which may have flags, arguments, and children commands.
func NewCommand ¶
func NewCommand(use, long, short string, runE func(cmd *cobra.Command, args []string) error) *Command
NewCommand returns a new Command with the provided inputs. Alias for NewCommandRunE.
func NewCommandCustom ¶
NewCustomCommand returns a Command created from the provided cobra.Command
func NewCommandRun ¶ added in v0.3.1
NewCommandRun returns a new Command with the provided inputs. The run function is used for commands that do not return an error.
func NewCommandRunE ¶ added in v0.3.1
func NewCommandRunE(use, long, short string, runE func(cmd *cobra.Command, args []string) error) *Command
NewCommandRunE returns a new Command with the provided inputs. The runE function is used for commands that return an error.
func NewDocsCommand ¶ added in v0.4.0
func NewManCommand ¶ added in v0.2.0
func (*Command) AddCommand ¶
AddCommand adds a command to the slice and to the underlying cobra command.
func (*Command) WithBoolFlag ¶ added in v0.2.0
WithBoolFlag adds a boolean flag to the command and registers the flag with environment variable injection
func (*Command) WithPersistentBoolFlag ¶ added in v0.2.0
WithPersistentBoolFlag adds a persistent boolean flag to the command and registers the flag with environment variable injection
func (*Command) WithPersistentStringFlag ¶ added in v0.2.0
WithPersistentStringFlag adds a persistent string flag to the command and registers the command with the environment variable injection
func (*Command) WithStringFlag ¶ added in v0.2.0
func (c *Command) WithStringFlag(f StringFlag) *Command
WithStringFlag adds a string flag to the command and registers the command with the environment variable injection
type StringFlag ¶
type StringFlag struct { Value string // contains filtered or unexported fields }
func NewStringFlag ¶
func NewStringFlag(name, shorthand, usage, value string) StringFlag