cli

package
v0.0.0-...-a355528 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2017 License: Apache-2.0 Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// EnvInfrakitHost is the environment variable to set to point to specific backends.
	// The value is used as key into the $INFRAKIT_HOME/hosts file.
	EnvInfrakitHost = "INFRAKIT_HOST"
	// EnvHostsFile is the location of the hosts file
	EnvHostsFile = "INFRAKIT_HOSTS_FILE"
)
View Source
const (
	// CliDirEnvVar is the environment variable that points to where the cli config folders are.
	CliDirEnvVar = "INFRAKIT_CLI_DIR"
)

Variables

View Source
var (
	// Version is the build release identifier.
	Version = "Unspecified"

	// Revision is the build source control revision.
	Revision = "Unspecified"
)
View Source
var DefaultLogLevel = len(logrus.AllLevels) - 2

DefaultLogLevel is the default log level value.

Functions

func EnsurePersistentPreRunE

func EnsurePersistentPreRunE(c *cobra.Command) error

EnsurePersistentPreRunE works around a limit of COBRA where only the persistent runE is executed at the parent of the leaf node.

func Flags

func Flags(o *logutil.Options) *pflag.FlagSet

Flags returns the set of logging flags

func HostsFile

func HostsFile() string

HostsFile returns the hosts file used for looking up hosts

func LoadAll

func LoadAll(services *Services) ([]*cobra.Command, error)

LoadAll loads all the dynamic, plugin commands based on what's registered and discovered.

func Missing

func Missing(t string, v interface{}) bool

Missing returns true if the value v is missing of the type t

func MustNotNil

func MustNotNil(object interface{}, message string, ctx ...string)

MustNotNil checks the object, if nil , exits and logs message

func PluginManager

func PluginManager(plugins func() discovery.Plugins,
	services *Services, configURL string) (*manager.Manager, error)

PluginManager returns the plugin manager for running plugins locally.

func Prompt

func Prompt(in io.Reader, prompt, ftype string, optional ...interface{}) (interface{}, error)

Prompt handles prompting the user using the given prompt message, type string and optional values.

func Register

func Register(spi spi.InterfaceSpec, builders []CmdBuilder)

Register registers a command from the CmdBuilders

func RegisterInfo

func RegisterInfo(key string, data map[string]interface{})

RegisterInfo allows any packages that use this register additional information to be displayed by the command. For example, a swarm flavor could register the docker api version. This allows us to selectively incorporate only required dependencies based on package registration (in their init()) without explicitly pulling unused dependencies.

func Remotes

func Remotes() ([]*url.URL, error)

Remotes returns a list of remote URLs to connect to

func SetLogLevel

func SetLogLevel(level int)

SetLogLevel adjusts the logrus level.

func UpTree

func UpTree(c *cobra.Command, do func(*cobra.Command, []string) error) error

UpTree traverses up the command tree and starts executing the do function in the order from top of the command tree to the bottom. Cobra commands executes only one level of PersistentPreRunE in reverse order. This breaks our model of setting log levels at the very top and have the log level set throughout the entire hierarchy of command execution.

func VersionCommand

func VersionCommand() *cobra.Command

VersionCommand creates a cobra Command that prints build version information.

Types

type CmdBuilder

type CmdBuilder func(name string, services *Services) *cobra.Command

CmdBuilder is a factory function that creates a command

type Context

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

Context is the context for the running module

func NewContext

func NewContext(plugins func() discovery.Plugins, cmd *cobra.Command, src string, input io.Reader,
	options template.Options) *Context

NewContext creates a context

func (*Context) BuildFlags

func (c *Context) BuildFlags() (err error)

BuildFlags from parsing the body which is a template

func (*Context) Execute

func (c *Context) Execute() (err error)

Execute runs the command

func (*Context) Funcs

func (c *Context) Funcs() []template.Function

Funcs returns the template functions

type FromJSONFunc

type FromJSONFunc func(json []byte) (out []byte, err error)

FromJSONFunc converts json formatted input to output buffer

type HostList

type HostList string

HostList is a comma-delimited list of protocol://host:port

type Hosts

type Hosts map[string]Remote

Hosts is the schema of the hosts file

func LoadHosts

func LoadHosts() (Hosts, error)

LoadHosts loads the hosts file

func (Hosts) Save

func (h Hosts) Save() error

Save saves the hosts

type Modules

type Modules interface {

	// List returns a list of preconfigured commands
	List() ([]*cobra.Command, error)
}

Modules provides access to CLI module discovery

type OutputFunc

type OutputFunc func(w io.Writer, v interface{}, defaultView func(io.Writer, interface{}) error) (err error)

OutputFunc is a function that writes some data to the output writer

func Output

func Output() (*pflag.FlagSet, OutputFunc)

Output returns the flagset and the func for printing output

type ProcessTemplateFunc

type ProcessTemplateFunc func(url string, ctx ...interface{}) (rendered string, err error)

ProcessTemplateFunc is the function that processes the template at url and returns view or error.

type Remote

type Remote struct {
	Endpoints HostList
	SSH       string // The bastion host
	User      string
}

Remote is a remote infrakit endpoint

type Services

type Services struct {

	// Plugins provide a lookup for plugins
	Plugins func() discovery.Plugins

	// ProcessTemplateFlags are common flags associated with the base services.  They should be added to subcommands
	// if the subcommands make use of the services provided here.
	ProcessTemplateFlags *pflag.FlagSet

	// ProcessTemplate is the function that processes the template at url and returns view or error.
	ProcessTemplate ProcessTemplateFunc

	// ToJSON converts the input buffer to json format
	ToJSON ToJSONFunc

	// FromJSON converts json formatted input to output buffer
	FromJSON FromJSONFunc

	// OutputFlags are flags that control output format
	OutputFlags *pflag.FlagSet

	// Output is the function that does output
	Output OutputFunc
}

Services is a common set of utiities that are available to each command. For example, plugin lookup, metadata lookup, template engine

func NewServices

func NewServices(plugins func() discovery.Plugins) *Services

NewServices creates an instance of common services for all commands

func (*Services) ReadFromStdinIfElse

func (s *Services) ReadFromStdinIfElse(condition func() bool,
	otherwise func() (string, error),
	toJSON ToJSONFunc) (rendered string, err error)

ReadFromStdinIfElse checks condition and reads from stdin if true; otherwise it executes other.

func (*Services) ReadFromStdinOrURL

func (s *Services) ReadFromStdinOrURL(arg string) (rendered string, err error)

ReadFromStdinOrURL reads input given from the argument. If this arg is URL then the content is fetched and rendered as a template. If the arg is '-', it reads from stdin.

type ToJSONFunc

type ToJSONFunc func(in []byte) (json []byte, err error)

ToJSONFunc converts the input buffer to json format

Jump to

Keyboard shortcuts

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