cmdlib

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2019 License: Apache-2.0 Imports: 17 Imported by: 8

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrorInvalidArgs = fmt.Errorf("invalid args. try -h for syntax")

ErrorInvalidArgs - error returned when args are invalid

Functions

func AddFormatter

func AddFormatter(t reflect.Type, f Formatter)

AddFormatter adds format function to the registry

func MarshalJSON

func MarshalJSON(v interface{}) string

MarshalJSON serializes given type to json.

Types

type App

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

App provides interface for rest

func NewApp

func NewApp() *App

NewApp creates new command registry

func (*App) Register

func (r *App) Register(parentCmd string, command cli.Command, fn HandlerFn)

Register new command

func (*App) Run

func (r *App) Run(args []string) error

Run the program

type Column

type Column struct {
	// Name of the column
	Name string

	// JsonPath to get the column
	Path string

	// Getter - Custom getter function
	Getter func(interface{}) interface{}
}

Column represents column of a resource.

type CustomFormatter

type CustomFormatter func(v interface{}, fo FormatOptions) Output

CustomFormatter function

type FormatOptions

type FormatOptions struct {
	Type FormatType

	// NoHeader - skip printing header for tabular, csv format
	NoHeader bool
}

FormatOptions - options for formatting

type FormatType

type FormatType int

FormatType represents type of format

const (
	// FormatTypeDefault - Default format. Uses tabular for single items, and short for collections.
	FormatTypeDefault FormatType = iota

	// FormatTypeTabular - tabular
	FormatTypeTabular FormatType = iota

	// FormatTypeShort - Tabular but sub items are not printed
	FormatTypeShort FormatType = iota

	// FormatTypeList - List of key value pairs (same items as table)
	FormatTypeList FormatType = iota

	// FormatTypeFullJSON - Full JSON
	FormatTypeFullJSON
)

func (*FormatType) Scan

func (t *FormatType) Scan(str string)

Scan from string

type Formatter

type Formatter struct {
	// List of columns
	Columns []Column

	// CustomFn - custom format fn. Used if specified.
	CustomFn CustomFormatter

	// SubItems of the resource
	SubItems []SubItem
}

Formatter represents settings for formatting a type.

type HandlerFn

type HandlerFn func(ctx context.Context, o *Options) error

HandlerFn - signature of handler

type Logger

type Logger interface {
	// Infof - print info.
	Infof(format string, args ...interface{})

	// Warningf - print warning.
	Warningf(format string, args ...interface{})

	// Errorf - print error.
	Errorf(format string, args ...interface{})
}

Logger - Logging interface.

func NewLogger

func NewLogger() Logger

NewLogger returns new logger.

type Options

type Options struct {
	Host       string
	Username   string
	Password   string
	CreatedBy  string
	APIKey     string
	APISecret  string
	PrintDebug bool
	Args       []string

	Log Logger

	FO *FormatOptions
	// contains filtered or unexported fields
}

Options for command line

func (*Options) Client

func (o *Options) Client() *kbclient.KillBill

Client returns killbill client

func (*Options) DevClient

func (o *Options) DevClient() *debug.Client

DevClient returns dev client

func (*Options) Format

func (o *Options) Format(v interface{}, f Formatter) []string

Format formats given resource and returns as list of lines

func (*Options) Output

func (o *Options) Output(format string, args ...interface{})

Output writes the output

func (*Options) OutputWithFormatter

func (o *Options) OutputWithFormatter(v interface{}, f Formatter)

OutputWithFormatter - print with custom formatter

func (*Options) Outputln

func (o *Options) Outputln(format string, args ...interface{})

Outputln writes the output and prints new line at the end

func (*Options) Print

func (o *Options) Print(v interface{})

Print writes formatted output of given resource

type Output

type Output struct {
	// Title of the output if any.
	Title string

	// Column names of this output
	Columns []string

	// Rows of this output
	Rows []OutputRow
}

Output for a command

func NewOutput

func NewOutput(f Formatter) Output

NewOutput creates new output

func (*Output) Merge

func (out *Output) Merge(no Output)

Merge merges given output into the current one.

type OutputRow

type OutputRow struct {
	// Values for this output
	Values []string

	// Child items
	Children []Output
}

OutputRow - A single output row

type SubItem

type SubItem struct {
	// Name of the collection
	Name string

	// FieldName of the struct that has the sub collection
	FieldName string

	// Formatter overrides the default formatter for this item
	Formatter *Formatter
}

SubItem represents sub collection

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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