Movatterモバイル変換


[0]ホーム

URL:


Alert GO-2024-3228: Coder vulnerable to post-auth URL redirection to untrusted site ('Open Redirect') in github.com/coder/coder
Notice  The highest tagged major version isv2.

clibase

package
v0.27.3Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2023 License:AGPL-3.0Imports:22Imported by:0

Details

Repository

github.com/coder/coder

Links

Documentation

Overview

Package clibase offers an all-in-one solution for a highly configurable CLIapplication. Within Coder, we use it for all of our subcommands, whichdemands more functionality than cobra/viber offers.

The Command interface is loosely based on the chi middleware pattern andhttp.Handler/HandlerFunc.

Index

Constants

This section is empty.

Variables

View Source
var DiscardValue discardValue

DiscardValue does nothing but implements the pflag.Value interface.It's useful in cases where you want to accept an option, but access theunderlying value directly instead of through the Option methods.

Functions

This section is empty.

Types

typeAnnotations

type Annotations map[string]string

Annotations is an arbitrary key-mapping used to extend the Option and Command types.Its methods won't panic if the map is nil.

func (Annotations)Get

func (aAnnotations) Get(keystring) (string,bool)

Get retrieves a key from the map, returning false if the key is not foundor the map is nil.

func (Annotations)IsSet

func (aAnnotations) IsSet(keystring)bool

IsSet returns true if the key is set in the annotations map.

func (Annotations)Mark

func (aAnnotations) Mark(keystring, valuestring)Annotations

Mark sets a value on the annotations map, creating oneif it doesn't exist. Mark does not mutate the original andreturns a copy. It is suitable for chaining.

typeBool

type Boolbool

funcBoolOfadded inv0.20.0

func BoolOf(b *bool) *Bool

func (*Bool)NoOptDefValue

func (*Bool) NoOptDefValue()string

func (*Bool)Set

func (b *Bool) Set(sstring)error

func (Bool)String

func (bBool) String()string

func (Bool)Type

func (Bool) Type()string

func (Bool)Value

func (bBool) Value()bool

typeCmd

type Cmd struct {// Parent is the direct parent of the command.Parent *Cmd// Children is a list of direct descendants.Children []*Cmd// Use is provided in form "command [flags] [args...]".Usestring// Aliases is a list of alternative names for the command.Aliases []string// Short is a one-line description of the command.Shortstring// Hidden determines whether the command should be hidden from help.Hiddenbool// RawArgs determines whether the command should receive unparsed arguments.// No flags are parsed when set, and the command is responsible for parsing// its own flags.RawArgsbool// Long is a detailed description of the command,// presented on its help page. It may contain examples.LongstringOptionsOptionSetAnnotationsAnnotations// Middleware is called before the Handler.// Use Chain() to combine multiple middlewares.MiddlewareMiddlewareFuncHandlerHandlerFuncHelpHandlerHandlerFunc}

Cmd describes an executable command.

func (*Cmd)AddSubcommandsadded inv0.21.0

func (c *Cmd) AddSubcommands(cmds ...*Cmd)

AddSubcommands adds the given subcommands, setting theirParent field automatically.

func (*Cmd)FullName

func (c *Cmd) FullName()string

FullName returns the full invocation name of the command,as seen on the command line.

func (*Cmd)FullOptionsadded inv0.23.6

func (c *Cmd) FullOptions()OptionSet

FullOptions returns the options of the command and its parents.

func (*Cmd)FullUsage

func (c *Cmd) FullUsage()string

FullName returns usage of the command, precededby the usage of its parents.

func (*Cmd)Invokeadded inv0.20.0

func (c *Cmd) Invoke(args ...string) *Invocation

Invoke creates a new invocation of the command, withstdio discarded.

The returned invocation is not live until Run() is called.

func (*Cmd)Name

func (c *Cmd) Name()string

Name returns the first word in the Use string.

func (*Cmd)PrepareAlladded inv0.21.0

func (c *Cmd) PrepareAll()error

PrepareAll performs initialization and linting on the command and all its children.

func (*Cmd)Walkadded inv0.20.0

func (c *Cmd) Walk(fn func(*Cmd))

Walk calls fn for the command and all its children.

typeDuration

type Durationtime.Duration

funcDurationOfadded inv0.20.0

func DurationOf(d *time.Duration) *Duration

func (*Duration)MarshalYAMLadded inv0.22.1

func (d *Duration) MarshalYAML() (interface{},error)

func (*Duration)Set

func (d *Duration) Set(vstring)error

func (*Duration)String

func (d *Duration) String()string

func (Duration)Type

func (Duration) Type()string

func (*Duration)UnmarshalYAMLadded inv0.22.1

func (d *Duration) UnmarshalYAML(n *yaml.Node)error

func (*Duration)Value

func (d *Duration) Value()time.Duration

typeEnumadded inv0.21.0

type Enum struct {Choices []stringValue   *string}

funcEnumOfadded inv0.21.0

func EnumOf(v *string, choices ...string) *Enum

func (*Enum)Setadded inv0.21.0

func (e *Enum) Set(vstring)error

func (*Enum)Stringadded inv0.21.0

func (e *Enum) String()string

func (*Enum)Typeadded inv0.21.0

func (e *Enum) Type()string

typeEnvVar

type EnvVar struct {NamestringValuestring}

Var represents a single environment variable of formNAME=VALUE.

typeEnvironadded inv0.20.0

type Environ []EnvVar

funcParseEnvironadded inv0.20.0

func ParseEnviron(environ []string, prefixstring)Environ

ParseEnviron returns all environment variables starting withprefix without said prefix.

func (Environ)Getadded inv0.21.0

func (eEnviron) Get(namestring)string

func (Environ)Lookupadded inv0.20.0

func (eEnviron) Lookup(namestring) (string,bool)

func (*Environ)Setadded inv0.20.0

func (e *Environ) Set(name, valuestring)

func (Environ)ToOSadded inv0.20.0

func (eEnviron) ToOS() []string

typeGroup

type Group struct {Parent      *Group `json:"parent,omitempty"`Namestring `json:"name,omitempty"`YAMLstring `json:"yaml,omitempty"`Descriptionstring `json:"description,omitempty"`}

Group describes a hierarchy of groups that an option or command belongs to.

func (*Group)Ancestry

func (g *Group) Ancestry() []Group

Ancestry returns the group and all of its parents, in order.

func (*Group)FullName

func (g *Group) FullName()string

typeHandlerFuncadded inv0.20.0

type HandlerFunc func(i *Invocation)error

HandlerFunc handles an Invocation of a command.

typeHostPort

type HostPort struct {HoststringPortstring}

HostPort is a host:port pair.

func (*HostPort)MarshalJSON

func (hp *HostPort) MarshalJSON() ([]byte,error)

func (*HostPort)MarshalYAMLadded inv0.22.1

func (hp *HostPort) MarshalYAML() (interface{},error)

func (*HostPort)Set

func (hp *HostPort) Set(vstring)error

func (*HostPort)String

func (hp *HostPort) String()string

func (*HostPort)Type

func (*HostPort) Type()string

func (*HostPort)UnmarshalJSON

func (hp *HostPort) UnmarshalJSON(b []byte)error

func (*HostPort)UnmarshalYAMLadded inv0.22.1

func (hp *HostPort) UnmarshalYAML(n *yaml.Node)error

typeInt64

type Int64int64

funcInt64Ofadded inv0.20.0

func Int64Of(i *int64) *Int64

func (*Int64)Set

func (i *Int64) Set(sstring)error

func (Int64)String

func (iInt64) String()string

func (Int64)Type

func (Int64) Type()string

func (Int64)Value

func (iInt64) Value()int64

typeInvocationadded inv0.20.0

type Invocation struct {Command *CmdArgs []string// Environ is a list of environment variables. Use EnvsWithPrefix to parse// os.Environ.EnvironEnvironStdoutio.WriterStderrio.WriterStdinio.Reader// contains filtered or unexported fields}

Invocation represents an instance of a command being executed.

func (*Invocation)Contextadded inv0.20.0

func (inv *Invocation) Context()context.Context

func (*Invocation)ParsedFlagsadded inv0.20.0

func (inv *Invocation) ParsedFlags() *pflag.FlagSet

func (*Invocation)Runadded inv0.20.0

func (inv *Invocation) Run() (errerror)

Run executes the command.If two command share a flag name, the first command wins.

func (*Invocation)WithContextadded inv0.20.0

func (inv *Invocation) WithContext(ctxcontext.Context) *Invocation

WithContext returns a copy of the Invocation with the given context.

func (*Invocation)WithOSadded inv0.20.0

func (inv *Invocation) WithOS() *Invocation

WithOS returns the invocation as a main package, filling in the invocation's unsetfields with OS defaults.

typeMiddlewareFuncadded inv0.20.0

type MiddlewareFunc func(nextHandlerFunc)HandlerFunc

MiddlewareFunc returns the next handler in the chain,or nil if there are no more.

funcChainadded inv0.20.0

Chain returns a Handler that first calls middleware in order.

funcRequireNArgsadded inv0.20.0

func RequireNArgs(wantint)MiddlewareFunc

funcRequireRangeArgsadded inv0.20.0

func RequireRangeArgs(start, endint)MiddlewareFunc

RequireRangeArgs returns a Middleware that requires the number of argumentsto be between start and end (inclusive). If end is -1, then the number ofarguments must be at least start.

typeNoOptDefValuer

type NoOptDefValuer interface {NoOptDefValue()string}

NoOptDefValuer describes behavior when nooption is passed into the flag.

This is useful for boolean or otherwise binary flags.

typeOption

type Option struct {Namestring `json:"name,omitempty"`Descriptionstring `json:"description,omitempty"`// Required means this value must be set by some means. It requires// `ValueSource != ValueSourceNone`// If `Default` is set, then `Required` is ignored.Requiredbool `json:"required,omitempty"`// Flag is the long name of the flag used to configure this option. If unset,// flag configuring is disabled.Flagstring `json:"flag,omitempty"`// FlagShorthand is the one-character shorthand for the flag. If unset, no// shorthand is used.FlagShorthandstring `json:"flag_shorthand,omitempty"`// Env is the environment variable used to configure this option. If unset,// environment configuring is disabled.Envstring `json:"env,omitempty"`// YAML is the YAML key used to configure this option. If unset, YAML// configuring is disabled.YAMLstring `json:"yaml,omitempty"`// Default is parsed into Value if set.Defaultstring `json:"default,omitempty"`// Value includes the types listed in values.go.Valuepflag.Value `json:"value,omitempty"`// Annotations enable extensions to clibase higher up in the stack. It's useful for// help formatting and documentation generation.AnnotationsAnnotations `json:"annotations,omitempty"`// Group is a group hierarchy that helps organize this option in help, configs// and other documentation.Group *Group `json:"group,omitempty"`// UseInstead is a list of options that should be used instead of this one.// The field is used to generate a deprecation warning.UseInstead []Option `json:"use_instead,omitempty"`Hiddenbool `json:"hidden,omitempty"`ValueSourceValueSource `json:"value_source,omitempty"`}

Option is a configuration option for a CLI application.

func (Option)YAMLPathadded inv0.22.1

func (oOption) YAMLPath()string

typeOptionSet

type OptionSet []Option

OptionSet is a group of options that can be applied to a command.

func (*OptionSet)Add

func (s *OptionSet) Add(opts ...Option)

Add adds the given Options to the OptionSet.

func (*OptionSet)ByNameadded inv0.22.1

func (s *OptionSet) ByName(namestring) *Option

ByName returns the Option with the given name, or nil if no such optionexists.

func (OptionSet)Filteradded inv0.23.0

func (sOptionSet) Filter(filter func(optOption)bool)OptionSet

Filter will only return options that match the given filter. (return true)

func (*OptionSet)FlagSet

func (s *OptionSet) FlagSet() *pflag.FlagSet

FlagSet returns a pflag.FlagSet for the OptionSet.

func (*OptionSet)MarshalYAMLadded inv0.22.1

func (s *OptionSet) MarshalYAML() (any,error)

MarshalYAML converts the option set to a YAML node, that can beconverted into bytes via yaml.Marshal.

The node is returned to enable post-processing higher up inthe stack.

It is isomorphic with FromYAML.

func (*OptionSet)ParseEnv

func (s *OptionSet) ParseEnv(vs []EnvVar)error

ParseEnv parses the given environment variables into the OptionSet.Use EnvsWithPrefix to filter out prefixes.

func (*OptionSet)SetDefaults

func (s *OptionSet) SetDefaults()error

SetDefaults sets the default values for each Option, skipping valuesthat already have a value source.

func (*OptionSet)UnmarshalYAMLadded inv0.22.1

func (s *OptionSet) UnmarshalYAML(rootNode *yaml.Node)error

UnmarshalYAML converts the given YAML node into the option set.It is isomorphic with ToYAML.

typeRunCommandErroradded inv0.21.0

type RunCommandError struct {Cmd *CmdErrerror}

func (*RunCommandError)Erroradded inv0.21.0

func (e *RunCommandError) Error()string

func (*RunCommandError)Unwrapadded inv0.21.0

func (e *RunCommandError) Unwrap()error

typeString

type Stringstring

funcStringOfadded inv0.20.0

func StringOf(s *string) *String

func (*String)NoOptDefValue

func (*String) NoOptDefValue()string

func (*String)Set

func (s *String) Set(vstring)error

func (String)String

func (sString) String()string

func (String)Type

func (String) Type()string

func (String)Value

func (sString) Value()string

typeStringArrayadded inv0.21.0

type StringArray []string

StringArray is a slice of strings that implements pflag.Value and pflag.SliceValue.

funcStringArrayOfadded inv0.21.0

func StringArrayOf(ss *[]string) *StringArray

func (*StringArray)Appendadded inv0.21.0

func (s *StringArray) Append(vstring)error

func (*StringArray)GetSliceadded inv0.21.0

func (s *StringArray) GetSlice() []string

func (*StringArray)Replaceadded inv0.21.0

func (s *StringArray) Replace(vals []string)error

func (*StringArray)Setadded inv0.21.0

func (s *StringArray) Set(vstring)error

func (StringArray)Stringadded inv0.21.0

func (sStringArray) String()string

func (StringArray)Typeadded inv0.21.0

func (StringArray) Type()string

func (StringArray)Valueadded inv0.21.0

func (sStringArray) Value() []string

typeStruct

type Struct[Tany] struct {Value T}

Struct is a special value type that encodes an arbitrary struct.It implements the flag.Value interface, but in general these values shouldonly be accepted via config for ergonomics.

The string encoding type is YAML.

func (*Struct[T])MarshalJSON

func (s *Struct[T]) MarshalJSON() ([]byte,error)

func (*Struct[T])MarshalYAML

func (s *Struct[T]) MarshalYAML() (interface{},error)

func (*Struct[T])Set

func (s *Struct[T]) Set(vstring)error

func (*Struct[T])String

func (s *Struct[T]) String()string

func (*Struct[T])Type

func (s *Struct[T]) Type()string

func (*Struct[T])UnmarshalJSON

func (s *Struct[T]) UnmarshalJSON(b []byte)error

func (*Struct[T])UnmarshalYAML

func (s *Struct[T]) UnmarshalYAML(n *yaml.Node)error

typeURL

type URLurl.URL

funcURLOfadded inv0.20.0

func URLOf(u *url.URL) *URL

func (*URL)MarshalJSON

func (u *URL) MarshalJSON() ([]byte,error)

func (*URL)MarshalYAMLadded inv0.22.1

func (u *URL) MarshalYAML() (interface{},error)

func (*URL)Set

func (u *URL) Set(vstring)error

func (*URL)String

func (u *URL) String()string

func (*URL)Type

func (*URL) Type()string

func (*URL)UnmarshalJSON

func (u *URL) UnmarshalJSON(b []byte)error

func (*URL)UnmarshalYAMLadded inv0.22.1

func (u *URL) UnmarshalYAML(n *yaml.Node)error

func (*URL)Value

func (u *URL) Value() *url.URL

typeValidatoradded inv0.26.1

type Validator[Tpflag.Value] struct {Value T// contains filtered or unexported fields}

Validator is a wrapper around a pflag.Value that allows for validationof the value after or before it has been set.

funcValidateadded inv0.26.1

func Validate[Tpflag.Value](opt T, validate func(value T)error) *Validator[T]

func (*Validator[T])Setadded inv0.26.1

func (i *Validator[T]) Set(inputstring)error

func (*Validator[T])Stringadded inv0.26.1

func (i *Validator[T]) String()string

func (*Validator[T])Typeadded inv0.26.1

func (i *Validator[T]) Type()string

typeValueSourceadded inv0.22.1

type ValueSourcestring
const (ValueSourceNoneValueSource = ""ValueSourceFlagValueSource = "flag"ValueSourceEnvValueSource = "env"ValueSourceYAMLValueSource = "yaml"ValueSourceDefaultValueSource = "default")

typeYAMLConfigPathadded inv0.22.1

type YAMLConfigPathstring

YAMLConfigPath is a special value type that encodes a path to a YAMLconfiguration file where options are read from.

func (*YAMLConfigPath)Setadded inv0.22.1

func (p *YAMLConfigPath) Set(vstring)error

func (*YAMLConfigPath)Stringadded inv0.22.1

func (p *YAMLConfigPath) String()string

func (*YAMLConfigPath)Typeadded inv0.22.1

func (*YAMLConfigPath) Type()string

Source Files

View all Source files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f orF : Jump to
y orY : Canonical URL
go.dev uses cookies from Google to deliver and enhance the quality of its services and to analyze traffic.Learn more.

[8]ページ先頭

©2009-2025 Movatter.jp