cli

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Default

func Default(name string) (string, bool)

Default gets the value of a setting called default-<name>.

func RemoveDefault

func RemoveDefault(name string) error

RemoveDefault deletes a setting called default-<name>. If the setting does not exist, nothing happens.

func RemoveSetting

func RemoveSetting(name string) error

RemoveSetting deletes the specified setting. If the setting does not exist, nothing happens.

func SetDefault

func SetDefault(name string, value string) error

SetDefault sets a setting called default-<name> to the specified value.

func SetSetting

func SetSetting(name string, value string) error

SetSetting sets the specified setting to the specified value.

func Setting

func Setting(configname string) (string, bool)

Setting gets the value for the specified setting. If a value does not exist, an empty string is returned.

func Settings

func Settings() map[string]string

Settings returns the settings map.

func StringCompletions

func StringCompletions(possibilities []string, toComplete string) ([]string, cobra.ShellCompDirective)

StringCompletions filters a slice of strings to those members that start with the specified string.

func WrapError

func WrapError(exitcode int, err error) error

WrapError wraps a Go error into a cli Error.

func WrapErrorMessage

func WrapErrorMessage(exitcode int, message string) error

WrapErrorMessage wraps a string into a cli Error.

func WrapErrorMessagef

func WrapErrorMessagef(exitcode int, messageformat string, v ...interface{}) error

WrapErrorMessagef wraps a formatted string into a cli Error. Arguments are specified in the manner of fmt.Printf.

Types

type Command

type Command struct {
	Cmd          *cobra.Command
	SetFlagsFunc func(*cobra.Command)
	Subcommands  []*Command
}

Command represents a kutti CLI command. It wraps a Cobra command object.

func (*Command) Process

func (kc *Command) Process(parent *cobra.Command)

Process adds flags and subcommands recursively.

type Error

type Error struct {
	Err error

	Exitcode int
	// contains filtered or unexported fields
}

Error represents an error that can happen during kutti CLI execution. It can wrap a Go error or a simple message. It also has an exit code which will be returned to the OS if it bubbles to the top.

func UnwrapError

func UnwrapError(err error) (*Error, bool)

UnwrapError tries to typecast a Go error into a cli Error.

func (*Error) Error

func (c *Error) Error() string

type JSONRenderer

type JSONRenderer struct {
	// contains filtered or unexported fields
}

JSONRenderer generates prettified JSON.

func NewJSONRenderer

func NewJSONRenderer(indentspaces int) *JSONRenderer

NewJSONRenderer returns a new JSON Renderer, which will render prettified JSON indented by the specified number of spaces.

func (*JSONRenderer) Render

func (j *JSONRenderer) Render(out io.Writer, arg interface{})

Render writes prettified JSON to the specified writer. It uses json.MarshalIndent for formatting.

type TableColumn

type TableColumn struct {
	// Name should exactly match the name of an input field.
	Name string
	// Title can be left blank. The name will be used.
	Title string
	// DefaultCheck can be set to true to mark a row as default
	// based on the value of this column.
	DefaultCheck bool
	// Width specifies the column width in characters.
	Width int
	// FormatPrefix specifies any go template function that
	// should precede the value.
	FormatPrefix string
}

TableColumn represents a column of tabular output.

type TableRenderer

type TableRenderer struct {
	// contains filtered or unexported fields
}

TableRenderer generates tabular output given a set of TableColumns. It generates and executes a template to print values for the columns.

func NewMapTableRenderer

func NewMapTableRenderer(
	name string,
	columns []*TableColumn,
) *TableRenderer

NewMapTableRenderer returns a TableRenderer, and generates a template, for the special case of rendering a simple key/value map.

func NewTableRenderer

func NewTableRenderer(
	name string,
	columns []*TableColumn,
	defaultvalue string,
) *TableRenderer

NewTableRenderer returns a new TableRenderer, and generates a template to produce tabular output.

func (*TableRenderer) Render

func (f *TableRenderer) Render(out io.Writer, arg interface{})

Render writes table-formatted output to the specified writer. It uses the text/tabwriter package for formatting.

type TemplateRenderer

type TemplateRenderer struct {
	// contains filtered or unexported fields
}

TemplateRenderer renders a template.

func NewTemplateRenderer

func NewTemplateRenderer(name string, templatesource string) (*TemplateRenderer, error)

NewTemplateRenderer returns a new TemplateRender, or an error.

func (*TemplateRenderer) Render

func (t *TemplateRenderer) Render(out io.Writer, arg interface{})

Render executes this renderer's template on the specified writer.

Jump to

Keyboard shortcuts

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