cli

package
v0.25.0 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package cli provides utilities for happy command line interfaces.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrCommandInvalid = errors.New("invalid command definition")
	ErrCommandArgs    = errors.New("command arguments error")
	ErrCommandFlags   = errors.New("command flags error")
	ErrPanic          = errors.New("there was panic, check logs for more info")
)
View Source
var (
	FlagVersion     = varflag.BoolFunc("version", false, "print application version")
	FlagHelp        = varflag.BoolFunc("help", false, "display help or help for the command. [...command --help]", "h")
	FlagX           = varflag.BoolFunc("x", false, "the -x flag prints all the cli commands as they are executed.")
	FlagSystemDebug = varflag.BoolFunc("system-debug", false, "enable system debug log level (very verbose)")
	FlagDebug       = varflag.BoolFunc("debug", false, "enable debug log level")
	FlagVerbose     = varflag.BoolFunc("verbose", false, "enable verbose log level", "v")
)

Common CLI flags which are automatically attached to the CLI ubnless disabled ins settings. You still can manually add them to your CLI if you want to.

Functions

func AskForConfirmation

func AskForConfirmation(q string) bool

AskForConfirmation gets (y/Y)es or (n/N)o from cli input.

func AskForInput

func AskForInput(q string) string

func Exec added in v0.25.0

func Exec(sess *session.Context, cmd *exec.Cmd) (string, error)

Exec wraps ExecRaw to return output as string.

func ExecRaw added in v0.25.0

func ExecRaw(sess *session.Context, cmd *exec.Cmd) ([]byte, error)

ExecRaw wraps and executes provided command and returns its CombinedOutput. It ensures that -x flag is taken into account and Command is Session Context aware.

func Run added in v0.25.0

func Run(sess *session.Context, cmd *exec.Cmd) error

Run wraps and executes provided command and writes its Stdout and Stderr. It ensures that -x flag is taken into account and Command is Session Context aware.

Types

type Settings added in v0.24.0

type Settings struct {
	MainMinArgs        settings.Uint `default:"0" desc:"Minimum number of arguments for a application main"`
	MainMaxArgs        settings.Uint `default:"0" desc:"Maximum number of arguments for a application main"`
	WithoutConfigCmd   settings.Bool `default:"false" desc:"Do not include the config command in the CLI"`
	WithoutGlobalFlags settings.Bool `default:"false" desc:"Do not include the global flags automatically in the CLI"`
}

func (Settings) Blueprint added in v0.24.0

func (s Settings) Blueprint() (*settings.Blueprint, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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