command

package
v0.0.0-...-4d97ccf Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2017 License: Apache-2.0 Imports: 9 Imported by: 1

Documentation

Overview

Package command provides the ability to execute commands.

Index

Constants

View Source
const (
	// CmdLs lists directory contents based on the current context.
	CmdLs = "ls"

	// CmdCd changes directory.
	CmdCd = "cd"

	// CmdGet downloads an object.
	CmdGet = "get"

	// CmdPut uploads an object.
	CmdPut = "put"

	// CmdPwd prints the present working directory.
	CmdPwd = "pwd"

	// CmdClear clears the current output.
	CmdClear = "clear"

	// CmdExit exits the program.
	CmdExit = "exit"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type CdCommand

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

CdCommand simulates 'cd' functionality.

func NewCd

func NewCd(s3 S3Client, con *context.Context, args []string) CdCommand

NewCd initializes and returns a CdCommand.

func (CdCommand) Execute

func (cd CdCommand) Execute(out Outputter) error

Execute performs a 'cd' command by updating the underlying context path.

func (CdCommand) IsLongRunning

func (cd CdCommand) IsLongRunning() bool

IsLongRunning returns true when an S3 API call is required prior to changing directory.

type ClearCommand

type ClearCommand struct{}

ClearCommand simulates 'clear' functionality.

func NewClear

func NewClear() ClearCommand

NewClear initializes and returns a CdCommand.

func (ClearCommand) Execute

func (clear ClearCommand) Execute(out Outputter) error

Execute performs a 'clear' command by clearing the current program output. Note: Only applicable when running via command line.

func (ClearCommand) IsLongRunning

func (ClearCommand) IsLongRunning() bool

IsLongRunning returns false because 'clear' can execute without delay.

type Executor

type Executor interface {
	// Execute runs the command.
	Execute(Outputter) error

	// IsLongRunning indicates if the command may require a waiting period (ie. remote commands).
	IsLongRunning() bool
}

Executor defines an interface for executable instructions.

type ExitCommand

type ExitCommand struct {
}

ExitCommand simulates 'exit' functionality.

func NewExit

func NewExit() ExitCommand

NewExit initializes and returns a CdCommand.

func (ExitCommand) Execute

func (exit ExitCommand) Execute(out Outputter) error

Execute performs an 'exit' command by quitting the program.

func (ExitCommand) IsLongRunning

func (ExitCommand) IsLongRunning() bool

IsLongRunning returns false because 'exit' can execute without delay.

type GetCommand

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

GetCommand downloads a remote file.

func NewGet

func NewGet(s3 S3Client, con *context.Context, args []string) GetCommand

NewGet initializes and returns a GetCommand.

func (GetCommand) Execute

func (get GetCommand) Execute(out Outputter) error

Execute performs a 'get' by downloading a remote file to a local destination.

func (GetCommand) IsLongRunning

func (GetCommand) IsLongRunning() bool

IsLongRunning returns true because a 'get' is always long running.

type LsCommand

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

LsCommand simulates 'ls' functionality.

func NewLs

func NewLs(s3 S3Client, con *context.Context) LsCommand

NewLs initializes and returns an LsCommand.

func (LsCommand) Execute

func (ls LsCommand) Execute(out Outputter) error

Execute performs a 'ls' command by printing the buckets/objects in the pwd based on the underlying context.

func (LsCommand) IsLongRunning

func (LsCommand) IsLongRunning() bool

IsLongRunning returns true because 'ls' requires a network operation.

type Outputter

type Outputter interface {
	Write(string)
}

Outputter defines a type that can receive command output in the form of strings.

type PutCommand

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

PutCommand uploads an object.

func NewPut

func NewPut(s3 S3Client, con *context.Context, args []string) PutCommand

NewPut initializes and returns a PutCommand.

func (PutCommand) Execute

func (p PutCommand) Execute(out Outputter) error

Execute performs a 'put' command by uploading a file to S3.

func (PutCommand) IsLongRunning

func (PutCommand) IsLongRunning() bool

IsLongRunning returns true because 'put' must always perform network requests.

type PwdCommand

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

PwdCommand simulates 'pwd' functionality.

func NewPwd

func NewPwd(con *context.Context) PwdCommand

NewPwd initializes and returns a PwdCommand.

func (PwdCommand) Execute

func (pwd PwdCommand) Execute(out Outputter) error

Execute performs a 'pwd' command by printing the current working path.

func (PwdCommand) IsLongRunning

func (PwdCommand) IsLongRunning() bool

IsLongRunning returns false because 'pwd' can execute without delay.

type S3Client

type S3Client interface {
	LsBuckets() ([]string, error)
	LsObjects(bucket, prefix string) ([]string, error)

	BucketExists(string) (bool, error)
	ObjectExists(string, string) (bool, error)
	PathExists(string, string) (bool, error)

	DownloadObject(string, string) (string, error)
	UploadObject(string, string, *os.File) (string, error)
}

S3Client defines an interface that communicates with Amazon S3.

Directories

Path Synopsis
Package context provides user state for a handler.
Package context provides user state for a handler.
Package util provides shared utility and convenience functions for commands.
Package util provides shared utility and convenience functions for commands.

Jump to

Keyboard shortcuts

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