app

package
v2.5.2-0...-ba37c77 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2019 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Action

func Action(providers ...ProviderFunc) func(c *cli.Context) error

Action is a convenience function for making cli.Command.Actions that sets up a Context, runs all the providers, cleans up afterward and returns errors from the actions if there is one

func BaseAppSetup

func BaseAppSetup(flags []cli.Flag, commands []cli.Command) (app *cli.App, err error)

BaseAppSetup sets up a cli.App for the given commands and config

func GenerateCommandsHelp

func GenerateCommandsHelp(cmds []cli.Command) string

GenerateCommandsHelp creates a list of commands along with their usages.

func GenerateSubcommandsUsage

func GenerateSubcommandsUsage(cmd cli.Command, prefix string) (commandsUsage []string)

GenerateSubcommandsUsage provides a list of usage information recursively for each subcommand, or just for this command if it has no subcommands.

func GlobalFlags

func GlobalFlags() (flags []cli.Flag)

GlobalFlags returns a new set of global flags for the client. This is where they are defined.

func OutputFlags

func OutputFlags(thing string, jsonType string) []cli.Flag

OutputFlags creates some cli.Flags for when you wanna use OutputInDesiredForm thing should be like "server", "servers", "group", "groups" jsonType should be "array" or "object"

func SetClientAndConfig

func SetClientAndConfig(app *cli.App, client lib.Client, config config.Manager)

SetClientAndConfig adds the client and config to the given app. it abstracts away setting the Metadata on the app. Mostly so that we get some type-checking. without it - it's just assigning to an interface{} which will always succeed, and which would near-inevitably result in hard-to-debug null pointer errors down the line.

func SetPrompter

func SetPrompter(app *cli.App, prompter util.Prompter)

SetPrompter sets the prompter for the given app. It does not normally need to be set (as this is done for you when calling SetClientAndConfig in cmd/bytemark.main() ) This is used by command tests such as TestDeleteGroup in cmd/bytemark/commands/delete/group_test.go to allow for mocking user input. See that test, or cmd/bytemark/app/auth/authenticator_test.go for example usage of a mock Prompter.

Types

type CliContextWrapper

type CliContextWrapper struct {
	*cli.Context
}

CliContextWrapper is a struct which embeds cli.Context and is used to ensure that the entirety of innerContext is implemented on it. This allows for making mocks of cli.Contexts. App() and Command() are the methods unique to innerContext that are not in cli.Context

func (CliContextWrapper) App

func (ctx CliContextWrapper) App() *cli.App

App returns the app for this Context

func (CliContextWrapper) Command

func (ctx CliContextWrapper) Command() cli.Command

Command returns the Command that was run to create this Context

type Context

type Context struct {
	Context        innerContext
	Account        *lib.Account
	Authed         bool
	Definitions    *lib.Definitions
	Disc           *brain.Disc
	Group          *brain.Group
	Privilege      brain.Privilege
	User           *brain.User
	VirtualMachine *brain.VirtualMachine
	// contains filtered or unexported fields
}

Context is a wrapper around urfave/cli.Context which provides easy access to the next unused argument and can have various bytemarky types attached to it in order to keep code DRY

func (*Context) App

func (ctx *Context) App() *cli.App

App returns the cli.App that this context is part of. Usually this will be the same as global.App, but it's nice to depend less on globals.

func (*Context) Args

func (ctx *Context) Args() []string

Args returns all the unused arguments

func (*Context) Bool

func (ctx *Context) Bool(flagname string) bool

Bool returns the value of the named flag as a bool

func (*Context) Client

func (ctx *Context) Client() lib.Client

Client returns the API client attached to the App this Context is for

func (*Context) Command

func (ctx *Context) Command() cli.Command

Command returns the cli.Command this context is for

func (*Context) Config

func (ctx *Context) Config() config.Manager

Config returns the config attached to the App this Context is for

func (*Context) Debug

func (ctx *Context) Debug(format string, values ...interface{})

Debug runs fmt.Fprintf on the args, outputting to the App's debugWriter. In tests, this is a TestWriter. Otherwise it's nil for now - but might be changed to the debug.log File in the future.

func (*Context) Debugf

func (ctx *Context) Debugf(format string, values ...interface{})

Debugf is the same as Debug, but does not append a \n to the format specified

func (*Context) ErrWriter

func (ctx *Context) ErrWriter() io.Writer

ErrWriter returns the app writer. just a convenience method for c.App().ErrWriter

func (*Context) Help

func (ctx *Context) Help(whatsyourproblem string) (err error)

Help creates a UsageDisplayedError that will output the issue and a message to consult the documentation

func (*Context) Int

func (ctx *Context) Int(flagname string) int

Int returns the value of the named flag as an int

func (*Context) Int64

func (ctx *Context) Int64(flagname string) int64

Int64 returns the value of the named flag as an int64

func (*Context) IsSet

func (ctx *Context) IsSet(flagName string) bool

IsSet returns true if the specified flag has been set.

func (*Context) IsTest

func (ctx *Context) IsTest() bool

IsTest returns whether this app is being run as part of a test It uses the "buf" on the App's Metadata - which is added by app_test.BaseTestSetup and used to capture output for later assertions

func (*Context) Log

func (ctx *Context) Log(format string, values ...interface{})

Log runs fmt.Fprintf on the args, outputting to the App's Writer

func (*Context) LogErr

func (ctx *Context) LogErr(format string, values ...interface{})

LogErr runs fmt.Fprintf on the args, outputting to the App's Writer

func (*Context) LogErrf

func (ctx *Context) LogErrf(format string, values ...interface{})

LogErrf is the same as LogErr, but does not append a \n to the format specified

func (*Context) Logf

func (ctx *Context) Logf(format string, values ...interface{})

Logf is the same as Log, but does not append a \n to the format specified

func (*Context) NextArg

func (ctx *Context) NextArg() (string, error)

NextArg returns the next unused argument, and marks it as used.

func (*Context) OutputFormat

func (ctx *Context) OutputFormat(defaultFormat ...output.Format) (output.Format, error)

OutputFormat attempts to figure out the output format needed, given the contents of the output-format config var, the json flag, and the table and table-fields flag. If there is an error reading the config, it is returned and human output is assumed.

func (*Context) OutputInDesiredForm

func (ctx *Context) OutputInDesiredForm(obj output.Outputtable, defaultFormat ...output.Format) error

OutputInDesiredForm outputs obj as a JSON object if --json is set, or as a table / table row if --table is set otherwise calls humanOutputFn (which should output it in a very human form - PrettyPrint or such defaultFormat is an optional string stating what the default format should be

func (*Context) Preprocess

func (ctx *Context) Preprocess() error

Preprocess runs the Preprocess methods on all flags that implement Preprocessor

func (*Context) Prompter

func (ctx *Context) Prompter() util.Prompter

Prompter returns the prompter which is used by this Context for prompting the user for input

func (*Context) Reset

func (ctx *Context) Reset()

Reset replaces the Context with a blank one (keeping the cli.Context)

func (*Context) String

func (ctx *Context) String(flagname string) string

String returns the value of the named flag as a string

func (*Context) StringSlice

func (ctx *Context) StringSlice(flagname string) []string

StringSlice returns the values of the named flag as a []string

func (*Context) Writer

func (ctx *Context) Writer() io.Writer

Writer returns the app writer. just a convenience method for c.App().Writer

type Preprocesser

type Preprocesser interface {
	Preprocess(ctx *Context) error
}

A Preprocesser is a flag.Flag that has a preprocess step that requires a Context

type ProviderFunc

type ProviderFunc func(*Context) error

ProviderFunc is the function type that can be passed to Action()

Directories

Path Synopsis
gen/slice_flags
slice_flags is a tool to instantly implement a flag.Value called <Something>SliceFlag, which contains a slice of <Something>Flags, an accessor called <Something>Slice, and a test to ensure that the SliceFlag parses and Preprocesses correctly if necessary.
slice_flags is a tool to instantly implement a flag.Value called <Something>SliceFlag, which contains a slice of <Something>Flags, an accessor called <Something>Slice, and a test to ensure that the SliceFlag parses and Preprocesses correctly if necessary.

Jump to

Keyboard shortcuts

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