cmdutils

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2020 License: Apache-2.0 Imports: 23 Imported by: 1

Documentation

Index

Constants

View Source
const IncompatibleFlags = "cannot be used at the same time"

Variables

View Source
var CheckNameArgError = defaultNameArgsError
View Source
var EXAMPLES = "EXAMPLES:"
View Source
var ExecErrorHandler = defaultExecErrorHandler
View Source
var OUTPUT = "OUTPUT:"
View Source
var PERMISSION = "REQUIRED PERMISSION:"
View Source
var PulsarCtlConfig = loadFromEnv()
View Source
var SCOPE = "SCOPE:"
View Source
var SPACES = "    "
View Source
var USEDFOR = "USED FOR:"

Functions

func AddVerbCmd

func AddVerbCmd(flagGrouping *FlagGrouping, parentResourceCmd *cobra.Command, newVerbCmd func(*VerbCmd))

AddVerbCmd create a registers a new command under the given resource command

func AddVerbCmds

func AddVerbCmds(flagGrouping *FlagGrouping, parentResourceCmd *cobra.Command, newVerbCmd ...func(cmd *VerbCmd))

func Exists added in v0.3.0

func Exists(path string) bool

func GetNameArg

func GetNameArg(args []string, errMsg string) (string, error)

GetNameArg tests to ensure there is only 1 name argument

func GetNameArgs

func GetNameArgs(args []string, check func(args []string) error) ([]string, error)

func NewBookieClient added in v0.2.0

func NewBookieClient() bookkeeper.Client

func NewPulsarClient

func NewPulsarClient() pulsar.Client

func NewPulsarClientWithAPIVersion

func NewPulsarClientWithAPIVersion(version common.APIVersion) pulsar.Client

func NewResourceCmd

func NewResourceCmd(use, short, long string, aliases ...string) *cobra.Command

NewVerbCmd defines a standard resource command

func PrintError

func PrintError(w io.Writer, err error)

func PrintJSON

func PrintJSON(w io.Writer, obj interface{})

func RunFuncWithTimeout

func RunFuncWithTimeout(task func([]string, interface{}) bool, condition bool, timeout time.Duration,
	args []string, obj interface{}) error

Types

type AuthInfo added in v0.3.0

type AuthInfo struct {
	LocationOfOrigin           string
	TLSTrustCertsFilePath      string `yaml:"tls_trust_certs_file_path"`
	TLSAllowInsecureConnection bool   `yaml:"tls_allow_insecure_connection"`
	Token                      string `yaml:"token"`
	TokenFile                  string `yaml:"tokenFile"`

	// OAuth2 configuration
	IssuerEndpoint string `yaml:"issuer_endpoint"`
	ClientID       string `yaml:"client_id"`
	Audience       string `yaml:"audience"`
	KeyFile        string `yaml:"key_file"`
}

type ClusterConfig

type ClusterConfig common.Config

the configuration of the cluster that pulsarctl connects to

func (*ClusterConfig) BookieClient added in v0.2.0

func (c *ClusterConfig) BookieClient() bookkeeper.Client

func (*ClusterConfig) Client

func (c *ClusterConfig) Client(version common.APIVersion) pulsar.Client

func (*ClusterConfig) DecodeContext added in v0.3.0

func (c *ClusterConfig) DecodeContext() *Config

func (*ClusterConfig) FlagSet

func (c *ClusterConfig) FlagSet() *pflag.FlagSet

type Config added in v0.3.0

type Config struct {
	AuthInfos      map[string]*AuthInfo `yaml:"auth-info"`
	Contexts       map[string]*Context  `yaml:"contexts"`
	CurrentContext string               `yaml:"current-context"`
}

func NewConfig added in v0.3.0

func NewConfig() *Config

type ConfigOverrides added in v0.3.0

type ConfigOverrides struct {
	AuthInfo       AuthInfo
	Context        Context
	CurrentContext string
	Timeout        string
}

type Context added in v0.3.0

type Context struct {
	BrokerServiceURL string `yaml:"admin-service-url"`
	BookieServiceURL string `yaml:"bookie-service-url"`
}

type Example added in v0.2.0

type Example struct {
	Desc    string
	Command string
}

type FlagGrouping

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

FlagGrouping holds a superset of all flagsets for all commands

func NewGrouping

func NewGrouping() *FlagGrouping

NewGrouping creates an instance of Grouping

func (*FlagGrouping) New

New creates a new group of flagsets for use with a subcommand

func (*FlagGrouping) Usage

func (g *FlagGrouping) Usage(cmd *cobra.Command) error

Usage is for use with (*cobra.Command).SetUsageFunc

type LongDescription added in v0.2.0

type LongDescription struct {
	CommandUsedFor    string
	CommandPermission string
	CommandExamples   []Example
	CommandOutput     []Output
	CommandScope      string
}

func (*LongDescription) ExampleToString added in v0.2.0

func (desc *LongDescription) ExampleToString() string

func (*LongDescription) ToString added in v0.2.0

func (desc *LongDescription) ToString() string

type NamedFlagSetGroup

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

NamedFlagSetGroup holds a single group of flagsets

func (*NamedFlagSetGroup) AddTo

func (n *NamedFlagSetGroup) AddTo(cmd *cobra.Command)

AddTo mixes all flagsets in the given group to another flagset

func (*NamedFlagSetGroup) InFlagSet

func (n *NamedFlagSetGroup) InFlagSet(name string, cb func(*pflag.FlagSet))

InFlagSet returns new or existing named FlagSet in a group

type Output added in v0.2.0

type Output struct {
	Desc string
	Out  string
}

type OutputConfig added in v0.3.0

type OutputConfig struct {
	// the output format (Table, Plain, Json, Yaml)
	Format string
}

OutputConfig represents an output configuration

func (*OutputConfig) AddTo added in v0.3.0

func (c *OutputConfig) AddTo(group *NamedFlagSetGroup)

AddTo registers the output flagset into a group

func (*OutputConfig) WriteOutput added in v0.3.0

func (c *OutputConfig) WriteOutput(w io.Writer, f OutputNegotiable) error

WriteOutput writes output based on the configured output format and on available content

type OutputContent added in v0.3.0

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

OutputContent adapts various Go types to output format(s)

func NewOutputContent added in v0.3.0

func NewOutputContent() *OutputContent

func (OutputContent) Negotiate added in v0.3.0

func (o OutputContent) Negotiate(format OutputFormat) OutputWritable

Negotiate produces an OutputWritable based on available content

func (*OutputContent) WithObject added in v0.3.0

func (o *OutputContent) WithObject(obj interface{}) *OutputContent

func (*OutputContent) WithObjectFunc added in v0.3.0

func (o *OutputContent) WithObjectFunc(f func() interface{}) *OutputContent

func (*OutputContent) WithText added in v0.3.0

func (o *OutputContent) WithText(format string, i ...interface{}) *OutputContent

WithText produces the given formatted string

func (*OutputContent) WithTextFunc added in v0.3.0

func (o *OutputContent) WithTextFunc(f func(w io.Writer) error) *OutputContent

type OutputFormat added in v0.3.0

type OutputFormat string

OutputFormat represents a user-configured output format

const (
	TextOutputFormat OutputFormat = "text"
	JSONOutputFormat OutputFormat = "json"
	YAMLOutputFormat OutputFormat = "yaml"
)

func (OutputFormat) String added in v0.3.0

func (fmt OutputFormat) String() string

type OutputNegotiable added in v0.3.0

type OutputNegotiable interface {
	// Negotiate produces an OutputWritable for the given output format, or nil if the format isn't supported
	Negotiate(format OutputFormat) OutputWritable
}

OutputNegotiable facilitates content negotiation

type OutputNegotiableFunc added in v0.3.0

type OutputNegotiableFunc func(format OutputFormat) OutputWritable

func (OutputNegotiableFunc) Negotiate added in v0.3.0

func (f OutputNegotiableFunc) Negotiate(format OutputFormat) OutputWritable

type OutputWritable added in v0.3.0

type OutputWritable interface {
	WriteTo(w io.Writer) error
}

OutputWritable indicates an object that is writable to a given io.Writer

type OutputWritableFunc added in v0.3.0

type OutputWritableFunc func(w io.Writer) error

OutputWritableFunc adapts a function as an OutputWritable

func (OutputWritableFunc) WriteTo added in v0.3.0

func (f OutputWritableFunc) WriteTo(w io.Writer) error

type VerbCmd

type VerbCmd struct {
	Command      *cobra.Command
	FlagSetGroup *NamedFlagSetGroup
	NameArg      string
	NameArgs     []string
	NameError    error // for testing
	OutputConfig *OutputConfig
}

VerbCmd holds attributes that most of the commands use

func (*VerbCmd) EnableOutputFlagSet added in v0.3.0

func (vc *VerbCmd) EnableOutputFlagSet()

EnableOutputFlagSet adds the output flagset to the command

func (*VerbCmd) SetDescription

func (vc *VerbCmd) SetDescription(use, short, long, example string, aliases ...string)

SetDescription sets usage along with short and long descriptions as well as aliases

func (*VerbCmd) SetRunFunc

func (vc *VerbCmd) SetRunFunc(cmd func() error)

SetRunFunc registers a command function

func (*VerbCmd) SetRunFuncWithMultiNameArgs

func (vc *VerbCmd) SetRunFuncWithMultiNameArgs(cmd func() error, checkArgs func(args []string) error)

func (*VerbCmd) SetRunFuncWithNameArg

func (vc *VerbCmd) SetRunFuncWithNameArg(cmd func() error, errMsg string)

SetRunFuncWithNameArg registers a command function with an optional name argument

Jump to

Keyboard shortcuts

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