cmd

package
v0.0.0-...-89def8d Latest Latest
Warning

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

Go to latest
Published: May 24, 2021 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Timeout is the default timeout used for most commands.
	Timeout = time.Minute * 10
	// PushTimeout is the command timeout used when pushing bucket changes.
	PushTimeout = time.Hour * 24
	// PullTimeout is the command timeout used when pulling bucket changes.
	PullTimeout = time.Hour * 24

	// Bold is a styler used to make the output text bold.
	Bold = promptui.Styler(promptui.FGBold)
)

Functions

func AddrFromStr

func AddrFromStr(str string) ma.Multiaddr

AddrFromStr returns a multiaddress from the string.

func BindFlags

func BindFlags(v *viper.Viper, root *cobra.Command, flags map[string]Flag) error

BindFlags binds the flags to the viper config values.

func End

func End(format string, args ...interface{})

func Err

func Err(err error, args ...interface{})

func ErrCheck

func ErrCheck(err error, args ...interface{})

func ExpandConfigVars

func ExpandConfigVars(v *viper.Viper, flags map[string]Flag)

ExpandConfigVars evaluates the viper config file's expressions.

func Fatal

func Fatal(err error, args ...interface{})

func FindConfigFile

func FindConfigFile(conf *Config, pth string) bool

FindConfigFile searches up the path for a config file. True is returned is a config file was found and successfully loaded.

func GetFlagOrEnvValue

func GetFlagOrEnvValue(c *cobra.Command, k, envPre string) (v string)

GetFlagOrEnvValue first load a value for the key from the command flags. If no value was found, the value for the corresponding env variable is returned.

func HandleInterrupt

func HandleInterrupt(stop func())

func InitConfig

func InitConfig(conf *Config) func()

InitConfig returns a function that can be used to search for and load a config file.

func InitConfigCmd

func InitConfigCmd(rootCmd *cobra.Command, v *viper.Viper, dir string)

InitConfigCmd adds a config generator command to the root command. The command will write the config file to dir.

func IsConnectionError

func IsConnectionError(err error) bool

IsConnectionError returns true if the error is related to a dropped connection.

func LogErr

func LogErr(err error, args ...interface{})

func Message

func Message(format string, args ...interface{})

func RenderJSON

func RenderJSON(data interface{})

func RenderTable

func RenderTable(header []string, data [][]string)

func SetupDefaultLoggingConfig

func SetupDefaultLoggingConfig(file string) error

func Success

func Success(format string, args ...interface{})

func Warn

func Warn(format string, args ...interface{})

func Watch

func Watch(ctx context.Context, watchFunc WatchFunc, reconnectInterval time.Duration) (<-chan WatchState, error)

Watch calls watchFunc until it returns an error. Normally, watchFunc would block while doing work that can fail, e.g., the local network goes offline. If watchFunc return an error, it will be called again at the given interval so long as the returned error is non-fatal. Returns a channel of watch connectivity states. Cancel context to stop watching.

func WriteConfig

func WriteConfig(c *cobra.Command, v *viper.Viper, name string)

WriteConfig writes the viper config based on the command.

func WriteConfigToHome

func WriteConfigToHome(config *Config)

WriteConfigToHome writes config to the home directory.

Types

type ConfConfig

type ConfConfig struct {
	Dir       string // Config directory base name
	Name      string // Name of the mailbox config file
	Type      string // Type is the type of config file (yaml/json)
	EnvPrefix string // A prefix that will be expected on env vars
}

ConfConfig is used to generate new messages configs.

func (ConfConfig) NewConfig

func (cc ConfConfig) NewConfig(pth string, flags map[string]Flag, global bool) (c *Config, fileExists bool, err error)

NewConfig uses values from ConfConfig to contruct a new config.

type Config

type Config struct {
	Viper  *viper.Viper
	File   string
	Dir    string
	Name   string
	Flags  map[string]Flag
	EnvPre string
	Global bool
}

Config describes a command config params and file info.

type ConnectionState

type ConnectionState int

ConnectionState indicates an online/offline state.

const (
	// Offline indicates the remote is currently not reachable.
	Offline ConnectionState = iota
	// Online indicates a connection with the remote has been established.
	Online
)

func (ConnectionState) String

func (cs ConnectionState) String() string

type Flag

type Flag struct {
	Key      string
	DefValue interface{}
}

Flag describes a command flag.

type WatchFunc

type WatchFunc func(context.Context) (<-chan WatchState, error)

WatchFunc is a function wrapper for a function used by Watch.

type WatchState

type WatchState struct {
	// State of the watch connection (online/offline).
	State ConnectionState
	// Err returned by the watch operation.
	Err error
	// Aborted indicates whether or not the associated error aborted the watch.
	// (Connectivity related errors do not abort the watch.)
	Aborted bool
}

WatchState is used to inform Watch callers about the connection state.

Directories

Path Synopsis
cli

Jump to

Keyboard shortcuts

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