cmdr

package
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 1, 2024 License: GPL-3.0 Imports: 16 Imported by: 10

Documentation

Overview

Package cmdr provides abstractions to simplify and consolidate use of cobra and viper for cli applications.

Index

Constants

This section is empty.

Variables

View Source
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
)
View Source
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 FlagValBool(name string) bool

func FlagValBoolDefault

func FlagValBoolDefault(name string, def bool) bool

func FlagValString

func FlagValString(name string) string

func FlagValStringDefault

func FlagValStringDefault(name string, def string) string

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

func NewApp(name string, version string, locales embed.FS) *App

NewApp creates a new command line application. It requires an embed.FS with a top level directory named 'locales'.

func (*App) CreateRootCommand

func (a *App) CreateRootCommand(c *Command)

func (*App) Run

func (a *App) Run() error

type BoolFlag

type BoolFlag struct {
	Value bool
	// contains filtered or unexported fields
}

func NewBoolFlag

func NewBoolFlag(name, shorthand, usage string, value bool) BoolFlag

type BulletListItem added in v0.3.2

type BulletListItem = pterm.BulletListItem

type Color added in v0.3.2

type Color = pterm.Color
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.

const (
	BgDarkGray Color = iota + 100
	BgLightRed
	BgLightGreen
	BgLightYellow
	BgLightBlue
	BgLightMagenta
	BgLightCyan
	BgLightWhite
	// BgGray is an alias of BgDarkGray.
	BgGray Color = 100
)

Extra background color 100 - 107.

const (
	Reset Color = iota
	Bold
	Fuzzy
	Italic
	Underscore
	Blink
	FastBlink
	Reverse
	Concealed
	Strikethrough
)

Option settings.

type Command

type Command struct {
	*cobra.Command
	// contains filtered or unexported fields
}

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

func NewCommandCustom(cmd *cobra.Command) *Command

NewCustomCommand returns a Command created from the provided cobra.Command

func NewCommandRun added in v0.3.1

func NewCommandRun(use, long, short string, run func(cmd *cobra.Command, args []string)) *Command

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 NewDocsCommand(a *App) *Command

func NewManCommand added in v0.2.0

func NewManCommand(a *App) *Command

func (*Command) AddCommand

func (c *Command) AddCommand(commands ...*Command)

AddCommand adds a command to the slice and to the underlying cobra command.

func (*Command) Children

func (c *Command) Children() []*Command

Children returns the children commands.

func (*Command) WithBoolFlag added in v0.2.0

func (c *Command) WithBoolFlag(f BoolFlag) *Command

WithBoolFlag adds a boolean flag to the command and registers the flag with environment variable injection

func (*Command) WithPersistentBoolFlag added in v0.2.0

func (c *Command) WithPersistentBoolFlag(f BoolFlag) *Command

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

func (c *Command) WithPersistentStringFlag(f BoolFlag) *Command

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

type Style added in v0.3.2

type Style = pterm.Style

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL