cmdr

package
v0.0.0-...-664cfc7 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2023 License: GPL-3.0 Imports: 11 Imported by: 0

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 (
	Info, Warning, Success, Fatal, Debug, Description, Error pterm.PrefixPrinter
	Spinner                                                  pterm.SpinnerPrinter
	ProgressBar                                              pterm.ProgressbarPrinter
)

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

func NewManCommand

func NewManCommand(title string) *cobra.Command

Types

type App

type App struct {
	Name        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, 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 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

func NewCommandCustom

func NewCommandCustom(cmd *cobra.Command) *Command

NewCustomCommand returns a Command created from the provided cobra.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

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

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

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

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

Jump to

Keyboard shortcuts

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