cli

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2020 License: Apache-2.0 Imports: 20 Imported by: 10

Documentation

Index

Constants

View Source
const (
	// EnvStrictDeprecations indicates that the CLI should follow a strict deprecation policy.
	// If this var is exported, the CLI will fail on obsolete features. If a feature is deprecated
	// in favor of something else, the CLI will instead rely on the new approach. When this env var
	// is not exported, the CLI displays warnings when encountering deprecated features.
	EnvStrictDeprecations = "DCOS_CLI_STRICT_DEPRECATIONS"

	// EnvDCOSDir can be used to specify a custom directory for the DC/OS CLI data, which defaults to "~/.dcos".
	EnvDCOSDir = "DCOS_DIR"
)

Environment variables for the DC/OS CLI.

Variables

This section is empty.

Functions

func NewTable

func NewTable(writer io.Writer, header []string) *tablewriter.Table

NewTable returns a simple table to output information.

Types

type Context

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

Context provides an implementation of api.Context. It relies on an Environment and is used to create various objects across the project and is being passed to every command as a constructor argument.

func NewContext

func NewContext(env *Environment) *Context

NewContext creates a new context from a given environment.

func (*Context) Args

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

Args returns the command-line arguments, starting with the program name.

func (*Context) Cluster

func (ctx *Context) Cluster() (*config.Cluster, error)

Cluster returns the current cluster.

func (*Context) Clusters

func (ctx *Context) Clusters() ([]*config.Cluster, error)

Clusters returns the clusters.

func (*Context) ConfigManager

func (ctx *Context) ConfigManager() (*config.Manager, error)

ConfigManager returns the ConfigManager for the context.

func (*Context) DCOSDir

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

DCOSDir returns the root directory for the DC/OS CLI. It defaults to `~/.dcos` and can be overridden by the `DCOS_DIR` env var.

func (*Context) Deprecated

func (ctx *Context) Deprecated(msg string) error

Deprecated warns that a feature is deprecated. It returns an error when DCOS_CLI_STRICT_DEPRECATIONS=1.

func (*Context) EnvLookup

func (ctx *Context) EnvLookup(key string) (string, bool)

EnvLookup lookups environment variables.

func (*Context) ErrOut

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

ErrOut returns the writer for CLI errors, logs, and informational messages.

func (*Context) Fs

func (ctx *Context) Fs() afero.Fs

Fs returns the filesystem.

func (*Context) HTTPClient

func (ctx *Context) HTTPClient(c *config.Cluster, opts ...httpclient.Option) (*httpclient.Client, error)

HTTPClient creates an httpclient.Client for a given cluster.

func (*Context) Input

func (ctx *Context) Input() io.Reader

Input returns the reader for CLI input.

func (*Context) Logger

func (ctx *Context) Logger() *logrus.Logger

Logger returns the CLI logger.

func (*Context) Login

func (ctx *Context) Login(flags *login.Flags, httpClient *httpclient.Client) (string, error)

Login initiates a login based on a set of flags and HTTP client. On success it returns an ACS token.

func (*Context) Opener

func (ctx *Context) Opener() open.Opener

Opener returns a new OS Opener.

func (*Context) Out

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

Out returns the writer for CLI output.

func (*Context) PluginManager

func (ctx *Context) PluginManager(cluster *config.Cluster) *plugin.Manager

PluginManager returns a plugin manager.

func (*Context) Prompt

func (ctx *Context) Prompt() *prompt.Prompt

Prompt is able to prompt for input, password or choices.

func (*Context) Setup

func (ctx *Context) Setup(flags *setup.Flags, clusterURL string, attach bool) (*config.Cluster, error)

Setup configures a given cluster based on its URL and setup flags.

type Environment

type Environment struct {

	// Args are the command-line arguments, starting by the program name.
	Args []string

	// Input is the reader for CLI input.
	Input io.Reader

	// Out is the writer for CLI output.
	Out io.Writer

	// ErrOut is the writer for CLI errors, logs, and informational messages.
	ErrOut io.Writer

	// EnvLookup lookups environment variables.
	EnvLookup func(key string) (string, bool)

	// Fs is an abstraction for the filesystem.
	Fs afero.Fs
}

Environment represents the CLI environment. It contains writers for stdout/stderr, functions for environment variables or user lookup, as well as a filesystem abstraction.

func NewOsEnvironment

func NewOsEnvironment() *Environment

NewOsEnvironment returns an environment backed by the os package.

type GlobalFlags

type GlobalFlags struct {
	Verbosity int
	LogLevel  string
	Debug     bool
	Version   bool
}

GlobalFlags represents the DC/OS CLI global flags.

func (*GlobalFlags) Parse

func (gf *GlobalFlags) Parse(args []string) []string

Parse parses the DC/OS CLI global flags, it accepts the following:

  • `-v`, `-vv`: defines the verbosity level.
  • `--log-level=[level]` (deprecated): sets the log-level.
  • `--debug` (deprecated): sets the log-level to "debug".
  • `--version`: displays the DC/OS CLI and cluster versions.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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