cmd

package
v1.0.14 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2020 License: MIT Imports: 25 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
	// ArchiveWatchTimeout is the command timeout used when watching archive status messages.
	ArchiveWatchTimeout = time.Hour * 12

	// 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 ErrCheck added in v1.0.13

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 added in v1.0.13

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 added in v1.0.13

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 GetThreadType added in v1.0.4

func GetThreadType(isDB bool) string

GetThreadType returns a string representation of the type of a thread.

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 added in v1.0.4

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 added in v1.0.14

func IsConnectionError(err error) bool

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

func Message

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

func RenderTable

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

func Success

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

func Warn added in v1.0.2

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

func Watch added in v1.0.14

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 added in v1.0.4

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

WriteConfig writes the viper config with name.

Types

type Clients added in v1.0.4

type Clients struct {
	Buckets *bc.Client
	Threads *tc.Client
	Hub     *hc.Client
	Users   *uc.Client
}

Clients wraps all the possible hubd/buckd clients.

func NewClients added in v1.0.4

func NewClients(target string, isHub bool) *Clients

NewClients returns a new clients object pointing to the target address. If isHub is true, the hub's admin and user clients are also created.

func (*Clients) Close added in v1.0.4

func (c *Clients) Close()

Close closes all the clients.

func (*Clients) ListThreads added in v1.0.4

func (c *Clients) ListThreads(ctx context.Context, dbsOnly bool) []Thread

ListThreads returns a list of threads for the context. In a hub context, this will only list threads that the context has access to. dbsOnly filters threads that do not belong to a database.

func (*Clients) SelectThread added in v1.0.4

func (c *Clients) SelectThread(ctx context.Context, label, successMsg string, dbsOnly bool) Thread

SelectThread presents the caller with a choice of threads.

type ConfConfig added in v1.0.14

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 added in v1.0.14

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 added in v1.0.4

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 added in v1.0.14

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 added in v1.0.14

func (cs ConnectionState) String() string

type Flag

type Flag struct {
	Key      string
	DefValue interface{}
}

Flaf describes a command flag.

type Thread added in v1.0.4

type Thread struct {
	ID    thread.ID `json:"id"`
	Label string    `json:"label"`
	Name  string    `json:"name"`
	Type  string    `json:"type"`
}

Thread wraps details about a thread.

type WatchFunc added in v1.0.14

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

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

type WatchState added in v1.0.14

type WatchState struct {
	// State of the watch connection (online/offline).
	State ConnectionState
	// Error 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
hub
cli

Jump to

Keyboard shortcuts

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