util

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2020 License: GPL-3.0 Imports: 34 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// TableDateFormat is the date format used for table output
	TableDateFormat = "2006-01-02 15:04:05"
	// DateOnlyFormat is a date format only containing the date
	DateOnlyFormat = "2006-01-02"
	// UpdateRepo is the repository to check for updates on
	UpdateRepo = "netsoc/cli"
)

Variables

View Source
var (
	// ErrPasswordMismatch indicates that a user entered two different passwords
	ErrPasswordMismatch = errors.New("passwords didn't match")
)
View Source
var IsDebug bool

IsDebug determines if debugging is enabled

Functions

func APIError

func APIError(err error) error

APIError re-formats an OpenAPI-generated API client error

func AddOptFormat added in v0.1.0

func AddOptFormat(cmd *cobra.Command, p *string)

AddOptFormat adds the output format option to a command

func AddOptUser added in v0.2.0

func AddOptUser(cmd *cobra.Command, p *string)

AddOptUser adds the user option to a command

func CheckUpdate added in v0.1.0

func CheckUpdate() (string, error)

CheckUpdate checks to see if a new version is available

func Debugf

func Debugf(format string, v ...interface{})

Debugf prints log messages only if debugging is enabled

func GetTerminalSize added in v0.3.1

func GetTerminalSize(fd int) (int, int, error)

GetTerminalSize returns the dimensions of a TTY (lines x cols)

func IsInteractive added in v0.2.0

func IsInteractive() bool

IsInteractive returns true if the CLI is being run interactively

func PrintUsers added in v0.1.0

func PrintUsers(users []iam.User, outputType string, single bool) error

PrintUsers renders a list of users (with various output options)

func ReadPassword

func ReadPassword(confirm bool) (string, error)

ReadPassword reads a password from stdin

func ResizeListener added in v0.3.0

func ResizeListener(sizeChan chan ConsoleSize, stop chan struct{})

ResizeListener listens for changes in console size

func SimpleProgress added in v0.2.0

func SimpleProgress(message string, eta time.Duration) (func(), progress.Writer, *progress.Tracker)

SimpleProgress renders a simple progress

func WebspacedWebsocket added in v0.3.0

func WebspacedWebsocket(c *config.Config, user, endpoint string) (*websocket.Conn, error)

WebspacedWebsocket opens a websocket to webspaced

func YesNo added in v0.1.0

func YesNo(prompt string, yesDefault bool) (bool, error)

YesNo asks a yes/no question on the command line

Types

type CmdFactory

type CmdFactory struct {
	Config          func() (*config.Config, error)
	Claims          func() (*UserClaims, error)
	IAMClient       func() (*iam.APIClient, error)
	WebspacedClient func() (*webspaced.APIClient, error)
}

CmdFactory provides methods to obtain commonly used structures

func NewDefaultCmdFactory

func NewDefaultCmdFactory(configFlag, debugFlag *pflag.Flag) *CmdFactory

NewDefaultCmdFactory creates a new command factory

type ConsoleSize added in v0.3.0

type ConsoleSize struct {
	Width  int `json:"width"`
	Height int `json:"height"`
}

ConsoleSize represents the dimensions of the terminal

type EscapeReader added in v0.3.0

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

EscapeReader transparently reads an escape sequence (^]) from an io.Reader, assumes a TTY in raw mode (one byte at a time reads)

func NewEscapeReader added in v0.3.0

func NewEscapeReader(r io.Reader, c chan bool) *EscapeReader

NewEscapeReader creates a new escape reading proxy

func (*EscapeReader) Read added in v0.3.0

func (e *EscapeReader) Read(p []byte) (int, error)

type UserClaims

type UserClaims struct {
	jwt.StandardClaims
	IsAdmin bool `json:"is_admin"`
	Version uint `json:"version"`
}

UserClaims represents claims in an auth JWT

type WebsocketIO added in v0.3.0

type WebsocketIO struct {
	Conn  *websocket.Conn
	Mutex sync.Mutex
	// contains filtered or unexported fields
}

WebsocketIO is a wrapper implementing ReadWriteCloser on top of websocket

func NewWebsocketIO added in v0.3.0

func NewWebsocketIO(c *websocket.Conn, textHandler func(string, *WebsocketIO)) *WebsocketIO

NewWebsocketIO creates a new websocket ReadWriteCloser wrapper

func (*WebsocketIO) Close added in v0.3.0

func (w *WebsocketIO) Close() error

Close sends a control message indicating the stream is finished, but it does not actually close the socket.

func (*WebsocketIO) Read added in v0.3.0

func (w *WebsocketIO) Read(p []byte) (n int, err error)

func (*WebsocketIO) Write added in v0.3.0

func (w *WebsocketIO) Write(p []byte) (n int, err error)

Jump to

Keyboard shortcuts

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