cli

package
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: May 4, 2017 License: Apache-2.0 Imports: 20 Imported by: 48

Documentation

Index

Constants

View Source
const (
	//DefaultPort for server address
	DefaultPort = ":50101"
)
View Source
const (
	// Padding for tabwriter
	Padding = 3
)

Variables

View Source
var (
	// DarkTheme defines colors appropriate for a dark terminal
	DarkTheme = &Theme{
		Normal:  color.New(),
		Info:    color.New(color.FgHiBlack),
		Warn:    color.New(color.FgYellow),
		Error:   color.New(color.FgRed),
		Success: color.New(color.FgGreen),
	}

	// LightTheme defines colors appropriate for a light terminal
	LightTheme = &Theme{
		Normal:  color.New(),
		Info:    color.New(color.FgBlack),
		Warn:    color.New(color.FgYellow),
		Error:   color.New(color.FgRed),
		Success: color.New(color.FgGreen),
	}
)

Functions

func AtLeastArgs added in v0.9.1

func AtLeastArgs(min int) func(cmd *cobra.Command, args []string) error

AtLeastArgs returns an error if the min number of args are not passed

func ExactArgs

func ExactArgs(num int) func(cmd *cobra.Command, args []string) error

ExactArgs returns an error if the exact number of args are not passed

func Exit

func Exit(code int)

Exit ensures that any registered functions are executed before exiting with the specified status code.

func FlagErrorFunc

func FlagErrorFunc(cmd *cobra.Command, err error) error

FlagErrorFunc prints an error message which matches the format of the docker/docker/cli error messages

func GetToken

func GetToken() string

GetToken returns the stored token

func NewClientConn

func NewClientConn(addr string, token string) (*grpc.ClientConn, error)

NewClientConn is a helper function that wraps the steps involved in setting up a grpc client connection to the API.

func NoArgs

func NoArgs(cmd *cobra.Command, args []string) error

NoArgs checks that the command is not passed any parameters

func NoArgsCustom

func NoArgsCustom(errstr string) func(*cobra.Command, []string) error

NoArgsCustom returns a function which checks that the command is not passed any parameters

func OnExit

func OnExit(f func())

OnExit is used to register functions that should be executed upon exiting.

func RangeArgs added in v0.9.1

func RangeArgs(min int, max int) func(cmd *cobra.Command, args []string) error

RangeArgs returns an error if the min and max number of args are not passed

func ReadToken

func ReadToken() (string, error)

ReadToken reads the authentication token from file

func RemoveToken

func RemoveToken() error

RemoveToken deletes the authentication token file

func SaveToken

func SaveToken(metadata metadata.MD) error

SaveToken saves the authentication token to file

func SetupRootCommand

func SetupRootCommand(rootCmd *cobra.Command)

SetupRootCommand sets default usage, help, and error handling for the root command.

Types

type Configuration

type Configuration struct {
	Version string
	Build   string
	Server  string
	Verbose bool
	Theme   string
}

Configuration is for all configurable client settings

type Console

type Console struct {
	Logger
	// contains filtered or unexported fields
}

Console augments basic logging functions with a theme that can be applied for various standardized CLI output functions, such as Success and Error.

func NewConsole

func NewConsole(out *OutStream, verbose bool) *Console

NewConsole creates a CLI Console instance that writes to the provided stream.

func (*Console) Error

func (c *Console) Error(args ...interface{})

Error prints args using Theme.Error().

func (*Console) Errorf

func (c *Console) Errorf(format string, args ...interface{})

Errorf prints a formatted string using Theme.Error().

func (*Console) Errorln

func (c *Console) Errorln(args ...interface{})

Errorln prints args using Theme.Error() and appends a newline.

func (*Console) Fatal

func (c *Console) Fatal(args ...interface{})

Fatal prints args Theme.Error() and exits with code 1.

func (*Console) Fatalf

func (c *Console) Fatalf(format string, args ...interface{})

Fatalf prints a formatted string using Theme.Error() and exits with code 1

func (*Console) Fatalln

func (c *Console) Fatalln(args ...interface{})

Fatalln prints args using Theme.Error(),appends a newline and exits with code 1

func (*Console) GetInput

func (c *Console) GetInput(prompt string) (in string)

GetInput gets input from standard input and returns it

func (*Console) GetSilentInput

func (c *Console) GetSilentInput(prompt string) (in string)

GetSilentInput gets input from standard input, without displaying characters, and returns it

func (*Console) Info

func (c *Console) Info(args ...interface{})

Info prints args using Theme.Info().

func (*Console) Infof

func (c *Console) Infof(format string, args ...interface{})

Infof prints a formatted string using Theme.Info().

func (*Console) Infoln

func (c *Console) Infoln(args ...interface{})

Infoln prints args using Theme.Info() and appends a newline.

func (*Console) OutStream

func (c *Console) OutStream() *OutStream

OutStream returns the underlying OutStream that wraps stdout.

func (*Console) Print

func (c *Console) Print(args ...interface{})

Print prints args using Theme.Normal().

func (*Console) Printf

func (c *Console) Printf(format string, args ...interface{})

Printf prints a formatted string using Theme.Normal().

func (*Console) Println

func (c *Console) Println(args ...interface{})

Println prints args using Theme.Normal() and appends a newline.

func (*Console) SetTheme

func (c *Console) SetTheme(theme *Theme)

SetTheme sets the console theme.

func (*Console) SetThemeName

func (c *Console) SetThemeName(name string)

SetThemeName sets the console theme by name.

func (*Console) Success

func (c *Console) Success(args ...interface{})

Success prints args Theme.Success().

func (*Console) Successf

func (c *Console) Successf(format string, args ...interface{})

Successf prints a formatted string using Theme.Success()

func (*Console) Successln

func (c *Console) Successln(args ...interface{})

Successln prints args using Theme.Success() and appends a newline.

func (*Console) Theme

func (c *Console) Theme() *Theme

Theme returns the current theme.

func (*Console) Warn

func (c *Console) Warn(args ...interface{})

Warn prints args using Theme.Warn().

func (*Console) Warnf

func (c *Console) Warnf(format string, args ...interface{})

Warnf prints a formatted string using Theme.Warn().

func (*Console) Warnln

func (c *Console) Warnln(args ...interface{})

Warnln prints args using Theme.Warn() and appends a newline.

type Errors

type Errors []error

Errors is a list of errors. Useful in a loop if you don't want to return the error right away and you want to display after the loop, all the errors that happened during the loop.

func (Errors) Error

func (errList Errors) Error() string

type InStream

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

InStream is an input stream used by the DockerCli to read user input

func NewInStream

func NewInStream(in io.ReadCloser) *InStream

NewInStream returns a new InStream object from a ReadCloser

func (*InStream) CheckTty

func (i *InStream) CheckTty(attachStdin, ttyMode bool) error

CheckTty checks if we are trying to attach to a container tty from a non-tty client input stream, and if so, returns an error.

func (*InStream) Close

func (i *InStream) Close() error

Close implements the Closer interface

func (*InStream) FD

func (i *InStream) FD() uintptr

FD returns the file descriptor number for this stream

func (*InStream) IsTerminal

func (i *InStream) IsTerminal() bool

IsTerminal returns true if this stream is connected to a terminal

func (*InStream) Read

func (i *InStream) Read(p []byte) (int, error)

func (*InStream) RestoreTerminal

func (i *InStream) RestoreTerminal()

RestoreTerminal restores normal mode to the terminal

func (*InStream) SetRawTerminal

func (i *InStream) SetRawTerminal() (err error)

SetRawTerminal sets raw mode on the input terminal

type Interface

type Interface interface {
	Version() string
	Build() string

	Console() *Console
	In() *InStream
	Out() *OutStream
	Err() io.Writer
	ShowHelp(cmd *cobra.Command, args []string) error

	Server() string
	SetServer(server string)
	Connect() (*grpc.ClientConn, error)
	ClientConn() *grpc.ClientConn

	OnInitialize(initializers ...func())
}

Interface for the CLI's functionality.

func NewCLI

func NewCLI(in io.ReadCloser, out, err io.Writer, config *Configuration) Interface

NewCLI returns a new CLI instance.

type Logger

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

Logger is a simple logger for the Atomiq CLI that also implements grpclog.Logger

func NewLogger

func NewLogger(out *OutStream, verbose bool) *Logger

NewLogger creates a CLI Logger instance that writes to the provided stream.

func (Logger) Fatal

func (l Logger) Fatal(args ...interface{})

Fatal is equivalent to fmt.Print() followed by a call to os.Exit(1).

func (Logger) Fatalf

func (l Logger) Fatalf(format string, args ...interface{})

Fatalf is equivalent to fmt.Printf() followed by a call to os.Exit(1).

func (Logger) Fatalln

func (l Logger) Fatalln(args ...interface{})

Fatalln is equivalent to fmt.Println() followed by a call to os.Exit(1).

func (Logger) OutStream

func (l Logger) OutStream() *OutStream

OutStream return the underlying output stream

func (Logger) Print

func (l Logger) Print(args ...interface{})

Print is equivalent to fmt.Print() if verbose mode. Arguments are handled in the manner of fmt.Printf.

func (Logger) Printf

func (l Logger) Printf(format string, args ...interface{})

Printf is equivalent to fmt.Printf() if verbose mode.

func (Logger) Println

func (l Logger) Println(args ...interface{})

Println is equivalent to fmt.Println() if verbose mode.

func (Logger) Verbose

func (l Logger) Verbose() bool

Verbose returns whether the logger is verbose

type LoginCredentials

type LoginCredentials struct {
	Token string
}

LoginCredentials represents login credentials

func (*LoginCredentials) GetRequestMetadata

func (c *LoginCredentials) GetRequestMetadata(context.Context, ...string) (map[string]string, error)

GetRequestMetadata implements credentials.PerRPCCredentials

func (*LoginCredentials) RequireTransportSecurity

func (c *LoginCredentials) RequireTransportSecurity() bool

RequireTransportSecurity implements credentials.PerRPCCredentials

type OutStream

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

OutStream is an output stream used by the Cli to write normal program output.

func NewOutStream

func NewOutStream(out io.Writer) *OutStream

NewOutStream returns a new OutStream object from a Writer

func (*OutStream) FD

func (o *OutStream) FD() uintptr

FD returns the file descriptor number for this stream

func (*OutStream) GetTtySize

func (o *OutStream) GetTtySize() (uint, uint)

GetTtySize returns the height and width in characters of the tty

func (*OutStream) IsTerminal

func (o *OutStream) IsTerminal() bool

IsTerminal returns true if this stream is connected to a terminal

func (*OutStream) RestoreTerminal

func (o *OutStream) RestoreTerminal()

RestoreTerminal restores normal mode to the terminal

func (*OutStream) SetRawTerminal

func (o *OutStream) SetRawTerminal() (err error)

SetRawTerminal sets raw mode on the output terminal

func (*OutStream) Write

func (o *OutStream) Write(p []byte) (int, error)

type StatusError

type StatusError struct {
	Status     string
	StatusCode int
}

StatusError reports an unsuccessful exit by a command.

func (StatusError) Error

func (e StatusError) Error() string

type Theme

type Theme struct {
	Normal  *color.Color
	Info    *color.Color
	Warn    *color.Color
	Error   *color.Color
	Success *color.Color
}

Theme is struct for terminal color functions

Directories

Path Synopsis
command
org

Jump to

Keyboard shortcuts

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