cli

package
v0.54.1 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2024 License: BSD-3-Clause Imports: 23 Imported by: 15

README

CDS - Command Line Interface

see https://ovh.github.io/cds/docs/components/cdsctl/

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Yellow       = color.New(color.FgYellow).SprintfFunc()
	Red          = color.New(color.FgRed).SprintfFunc()
	Blue         = color.New(color.FgBlue).SprintfFunc()
	Magenta      = color.New(color.FgMagenta).SprintfFunc()
	Green        = color.New(color.FgGreen).SprintfFunc()
	Cyan         = color.New(color.FgCyan).SprintfFunc()
	BuildingChar = Blue("↻")
	OKChar       = Green("✓")
	KOChar       = Red("✗")
	Arrow        = Cyan("➤")
)

Colors... colors everywhere

View Source
var ErrWrongUsage = &Error{Code: 1, Err: fmt.Errorf("Wrong usage")}

ErrWrongUsage is a common error

View Source
var ShellMode bool

ShellMode will os.Exit if false, display only exit code if true

View Source
var Verbose bool

If Verbose is set to true, ExitOnError will try to display more detail about the potential errors

Functions

func AskChoice

func AskChoice(s string, opts ...string) int

AskChoice for a choice in given options, returns the selected option index.

func AskConfirm

func AskConfirm(s string) bool

AskConfirm for confirmation on command line.

func AskPassword

func AskPassword(s string) string

AskPassword ask for a password string and returns it.

func AskSelect

func AskSelect(s string, opts ...string) []int

AskSelect for multiple choices in given options, returns indexes of selected options.

func AskValue

func AskValue(s string) string

AskValue ask for a string and returns it.

func CommandWithExtraAliases

func CommandWithExtraAliases(c *Command, run interface{})

CommandWithExtraAliases to add common extra alias

func CommandWithExtraFlags

func CommandWithExtraFlags(c *Command, run interface{})

CommandWithExtraFlags to add common extra flags

func CommandWithPreRun

func CommandWithPreRun(f func(c *Command, args *[]string) error) func(c *Command, run interface{})

CommandWithPreRun to add pre run function

func CommandWithoutExtraFlags

func CommandWithoutExtraFlags(c *Command, run interface{})

CommandWithoutExtraFlags to avoid add extra flags

func Ellipsis

func Ellipsis(s string, i int) string

Ellipsis return a trunckated string if i parameter is < of string length

func ExitOnError

func ExitOnError(err error, helpFunc ...func() error)

ExitOnError if the error is not nil; exit the process with printing help functions and the error

func NewCommand

func NewCommand(c Command, run RunFunc, subCommands SubCommands, mod ...CommandModifier) *cobra.Command

NewCommand creates a new cobra command with or without a RunFunc and eventually subCommands

func NewDeleteCommand

func NewDeleteCommand(c Command, run RunDeleteFunc, subCommands SubCommands, mod ...CommandModifier) *cobra.Command

NewDeleteCommand creates a new cobra command with a RunDeleteFunc and eventually subCommands

func NewError

func NewError(format string, args ...interface{}) error

func NewGetCommand

func NewGetCommand(c Command, run RunGetFunc, subCommands SubCommands, mod ...CommandModifier) *cobra.Command

NewGetCommand creates a new cobra command with a RunGetFunc and eventually subCommands

func NewListCommand

func NewListCommand(c Command, run RunListFunc, subCommands SubCommands, mod ...CommandModifier) *cobra.Command

NewListCommand creates a new cobra command with a RunListFunc and eventually subCommands

func OSExit

func OSExit(code int)

OSExit will os.Exit if ShellMode is false, display only exit code if true

func ParsePath

func ParsePath(path string) (string, string, error)

ParsePath returns group and itme name from given path.

func ReadLine

func ReadLine() string

ReadLine prompts input from the user delimited by a new line

func WrapError

func WrapError(err error, format string, args ...interface{}) error

Types

type Arg

type Arg struct {
	Name       string
	IsValid    func(string) bool
	AllowEmpty bool
}

Arg represent a command argument

type Command

type Command struct {
	Name         string
	Ctx          []Arg
	Args         []Arg
	OptionalArgs []Arg
	VariadicArgs Arg
	Short        string
	Long         string
	Example      string
	Flags        []Flag
	Aliases      []string
	Hidden       bool
	PreRun       func(c *Command, args *[]string) error
}

Command represents the way to instantiate a cobra.Command

type CommandModifier

type CommandModifier func(*Command, interface{})

CommandModifier is a function type to extend a command

type CustomMultiSelect

type CustomMultiSelect struct {
	survey.MultiSelect

	Message string
	Options []CustomMultiSelectOption
	// contains filtered or unexported fields
}

CustomMultiSelect is a custom multi select over survey multi select that allows to add extra info on items.

func NewCustomMultiSelect

func NewCustomMultiSelect(message string, opts ...CustomMultiSelectOption) *CustomMultiSelect

NewCustomMultiSelect custom survey multi select from options.

func (*CustomMultiSelect) Prompt

func (c *CustomMultiSelect) Prompt() (interface{}, error)

Prompt override to extract option values.

type CustomMultiSelectOption

type CustomMultiSelectOption struct {
	Value   string
	Info    string
	Default bool
}

CustomMultiSelectOption for CustomMultiSelect.

type Display

type Display string

Display helps you to display message on a terminal

func (*Display) Do

func (d *Display) Do(ctx context.Context)

Do runs a goroutine which update the display

func (*Display) Printf

func (d *Display) Printf(format string, args ...interface{})

Printf update the displayed message

type Error

type Error struct {
	Message string
	Code    int
	Err     error
}

Error implements error

func (*Error) Error

func (e *Error) Error() string

Error implements error

type Flag

type Flag struct {
	Name      string
	ShortHand string
	Usage     string
	Default   string
	Type      FlagType
	IsValid   func(string) bool
}

Flag represents a command flag.

type FlagType

type FlagType string

FlagType for cli flag.

const (
	FlagString FlagType = "string"
	FlagBool   FlagType = "bool"
	FlagSlice  FlagType = "slice"
	FlagArray  FlagType = "array"
)

Flags types

type ListResult

type ListResult []interface{}

ListResult is the result type for command function which returns list. Use AsListResult to compute this

func AsListResult

func AsListResult(i interface{}) ListResult

AsListResult compute any slice to ListResult

type RunDeleteFunc

type RunDeleteFunc func(Values) error

RunDeleteFunc is a run function for a command. It returns an error.

type RunFunc

type RunFunc func(Values) error

RunFunc is the most basic run function for a command. It returns only an error

type RunGetFunc

type RunGetFunc func(Values) (interface{}, error)

RunGetFunc is a run function for a command. It returns an object value (not a pointer) and an error.

type RunListFunc

type RunListFunc func(Values) (ListResult, error)

RunListFunc is a run function for a command. It returns an objects list and an error

type SubCommands

type SubCommands []*cobra.Command

SubCommands represents an array of cobra.Command

type Values

type Values map[string][]string

Values represents commands flags and args values accessible with their name

func (*Values) GetBool

func (v *Values) GetBool(s string) bool

GetBool returns a string.

func (*Values) GetInt64

func (v *Values) GetInt64(s string) (int64, error)

GetInt64 returns a int64.

func (*Values) GetString

func (v *Values) GetString(s string) string

GetString returns a string.

func (*Values) GetStringArray

func (v *Values) GetStringArray(s string) []string

GetStringArray returns a string array.

func (*Values) GetStringSlice

func (v *Values) GetStringSlice(s string) []string

GetStringSlice returns a string slice.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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