Documentation ¶
Index ¶
- Constants
- Variables
- func EnsurePersistentPreRunE(c *cobra.Command) error
- func Flags(o *logutil.Options) *pflag.FlagSet
- func HostsFile() string
- func LoadAll(services *Services) ([]*cobra.Command, error)
- func Missing(t string, v interface{}) bool
- func MustNotNil(object interface{}, message string, ctx ...string)
- func PluginManager(plugins func() discovery.Plugins, services *Services, configURL string) (*manager.Manager, error)
- func Prompt(in io.Reader, prompt, ftype string, optional ...interface{}) (interface{}, error)
- func Register(spi spi.InterfaceSpec, builders []CmdBuilder)
- func RegisterInfo(key string, data map[string]interface{})
- func Remotes() ([]*url.URL, error)
- func SetLogLevel(level int)
- func UpTree(c *cobra.Command, do func(*cobra.Command, []string) error) error
- func VersionCommand() *cobra.Command
- type CmdBuilder
- type Context
- type FromJSONFunc
- type HostList
- type Hosts
- type Modules
- type OutputFunc
- type ProcessTemplateFunc
- type Remote
- type Services
- type ToJSONFunc
Constants ¶
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" )
const (
// CliDirEnvVar is the environment variable that points to where the cli config folders are.
CliDirEnvVar = "INFRAKIT_CLI_DIR"
)
Variables ¶
var ( // Version is the build release identifier. Version = "Unspecified" // Revision is the build source control revision. Revision = "Unspecified" )
var DefaultLogLevel = len(logrus.AllLevels) - 2
DefaultLogLevel is the default log level value.
Functions ¶
func EnsurePersistentPreRunE ¶
EnsurePersistentPreRunE works around a limit of COBRA where only the persistent runE is executed at the parent of the leaf node.
func LoadAll ¶
LoadAll loads all the dynamic, plugin commands based on what's registered and discovered.
func MustNotNil ¶
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 ¶
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 ¶
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 UpTree ¶
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 ¶
VersionCommand creates a cobra Command that prints build version information.
Types ¶
type CmdBuilder ¶
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 ¶
BuildFlags from parsing the body which is a template
type FromJSONFunc ¶
FromJSONFunc converts json formatted input to output buffer
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 ¶
ProcessTemplateFunc is the function that processes the template at url and returns view or error.
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 ¶
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.
type ToJSONFunc ¶
ToJSONFunc converts the input buffer to json format