Documentation
¶
Index ¶
- type Flag
- type FlagValues
- func (c *FlagValues) GetBool(name string) bool
- func (c *FlagValues) GetBoolSlice(name string) []bool
- func (c *FlagValues) GetDate(name string) time.Time
- func (c *FlagValues) GetDateSlice(name string) []time.Time
- func (c *FlagValues) GetDateTime(name string) time.Time
- func (c *FlagValues) GetDateTimeSlice(name string) []time.Time
- func (c *FlagValues) GetDirname(name string) string
- func (c *FlagValues) GetDirnameSlice(name string) []string
- func (c *FlagValues) GetDirpath(name string) string
- func (c *FlagValues) GetDirpathSlice(name string) []string
- func (c *FlagValues) GetDuration(name string) time.Duration
- func (c *FlagValues) GetDurationSlice(name string) []time.Duration
- func (c *FlagValues) GetEmail(name string) string
- func (c *FlagValues) GetEmailSlice(name string) []string
- func (c *FlagValues) GetFilename(name string) string
- func (c *FlagValues) GetFilenameSlice(name string) []string
- func (c *FlagValues) GetFilepath(name string) string
- func (c *FlagValues) GetFilepathSlice(name string) []string
- func (c *FlagValues) GetFloat(name string) float64
- func (c *FlagValues) GetFloatSlice(name string) []float64
- func (c *FlagValues) GetFullURL(name string) string
- func (c *FlagValues) GetFullURLSlice(name string) []string
- func (c *FlagValues) GetInt(name string) int
- func (c *FlagValues) GetIntSlice(name string) []int
- func (c *FlagValues) GetJSON(name string) string
- func (c *FlagValues) GetPath(name string) string
- func (c *FlagValues) GetPathSlice(name string) []string
- func (c *FlagValues) GetRelativeURL(name string) string
- func (c *FlagValues) GetRelativeURLSlice(name string) []string
- func (c *FlagValues) GetString(name string) string
- func (c *FlagValues) GetStringSlice(name string) []string
- func (c *FlagValues) GetTime(name string) time.Time
- func (c *FlagValues) GetTimeSlice(name string) []time.Time
- func (c *FlagValues) GetURL(name string) string
- func (c *FlagValues) GetURLSlice(name string) []string
- func (c *FlagValues) Has(name string) bool
- func (c *FlagValues) SetInternalValue(name string, val any)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Flag ¶
type Flag struct {
// LongName is the full identifier invoked via double dashes (e.g., "output" for --output).
LongName string
// ShortName is the shorthand identifier invoked via a single dash (e.g., "out" for -out).
// It supports up to 3 characters. Flag bundling/agglutination is not supported.
ShortName string
// ShortDescription is a brief explanation of the flag purpose used in the help menu.
ShortDescription string
// LongDescription is a detailed explanation of the flag usage (optional, defaults to ShortDescription).
LongDescription string
// Required determines if the command execution must fail if this flag is absent.
Required bool
// DefaultValue is the fallback value applied if the flag is omitted. Ignored if Required is true.
DefaultValue any
// Type specifies the data format for conversion and validation (e.g., "string", "int", "email", "[]int").
Type xcliconstt.FlagType
// Min defines the inclusive lower bound allowed for quantifiable types. Ignored if nil.
Min any
// Max defines the inclusive upper bound allowed for quantifiable types. Ignored if nil.
Max any
// MinLength defines the minimum number of characters required for string types. Ignored if nil.
MinLength *int
// MaxLength defines the maximum number of characters allowed for string types. Ignored if nil.
MaxLength *int
// Regex is a regular expression pattern that the raw string value must match. Ignored if empty.
Regex string
// MinItems defines the minimum number of elements required when the flag is an array. Ignored if nil.
MinItems *int
// MaxItems defines the maximum number of elements allowed when the flag is an array. Ignored if nil.
MaxItems *int
// MustExist enforces that the filepath or dirpath must already exist on disk.
// If false, the validator will only check syntax and write permissions.
MustExist bool
// Access defines the permission level (read, write, readwrite) required for the resource.
// If left empty, the router will skip permission checks and only validate syntax/existence.
Access xcliconstt.AccessMode
}
Flag defines a command-line option, its data type, and validation constraints.
type FlagValues ¶
type FlagValues struct {
// contains filtered or unexported fields
}
Context holds the completely parsed, converted, and validated flag values for the currently executing command.
func NewFlagValues ¶
func NewFlagValues() *FlagValues
NewFlagValues initializes an empty container for validated flag values.
func (*FlagValues) GetBool ¶
func (c *FlagValues) GetBool(name string) bool
GetBool returns the value of a boolean flag.
Returns false if the flag is absent or is not a boolean type.
func (*FlagValues) GetBoolSlice ¶
func (c *FlagValues) GetBoolSlice(name string) []bool
GetBoolSlice returns the value of a boolean array flag.
Returns nil if the flag is absent or is not a []bool type.
func (*FlagValues) GetDate ¶
func (c *FlagValues) GetDate(name string) time.Time
GetDate returns the value of a date flag as a time.Time object.
Returns a zero time.Time object if the flag is absent or is not a time.Time type.
func (*FlagValues) GetDateSlice ¶
func (c *FlagValues) GetDateSlice(name string) []time.Time
GetDateSlice returns the value of a date array flag.
Returns nil if the flag is absent or is not a []time.Time type.
func (*FlagValues) GetDateTime ¶
func (c *FlagValues) GetDateTime(name string) time.Time
GetDateTime returns the value of a datetime flag as a time.Time object.
Returns a zero time.Time object if the flag is absent or is not a time.Time type.
func (*FlagValues) GetDateTimeSlice ¶
func (c *FlagValues) GetDateTimeSlice(name string) []time.Time
GetDateTimeSlice returns the value of a datetime array flag.
Returns nil if the flag is absent or is not a []time.Time type.
func (*FlagValues) GetDirname ¶
func (c *FlagValues) GetDirname(name string) string
GetDirname returns the syntactically valid directory name layout string.
It returns an empty string if the flag is absent or is not a string type.
func (*FlagValues) GetDirnameSlice ¶
func (c *FlagValues) GetDirnameSlice(name string) []string
GetDirnameSlice returns the value of a dirname array flag.
Returns nil if the flag is absent or is not a []string type.
func (*FlagValues) GetDirpath ¶
func (c *FlagValues) GetDirpath(name string) string
GetDirpath returns the normalized physical directory path string.
It returns an empty string if the flag is absent or is not a string type.
func (*FlagValues) GetDirpathSlice ¶
func (c *FlagValues) GetDirpathSlice(name string) []string
GetDirpathSlice returns the value of a dirpath array flag.
Returns nil if the flag is absent or is not a []string type.
func (*FlagValues) GetDuration ¶
func (c *FlagValues) GetDuration(name string) time.Duration
GetDuration returns the value of a duration flag as a time.Duration object.
Returns 0 if the flag is absent or is not a time.Duration type.
func (*FlagValues) GetDurationSlice ¶
func (c *FlagValues) GetDurationSlice(name string) []time.Duration
GetDurationSlice returns the value of a duration array flag.
Returns nil if the flag is absent or is not a []time.Duration type.
func (*FlagValues) GetEmail ¶
func (c *FlagValues) GetEmail(name string) string
GetEmail returns the value of an email flag.
It returns an empty string if the flag is absent or is not a string type.
func (*FlagValues) GetEmailSlice ¶
func (c *FlagValues) GetEmailSlice(name string) []string
GetEmailSlice returns the value of an email array flag.
Returns nil if the flag is absent or is not a []string type.
func (*FlagValues) GetFilename ¶
func (c *FlagValues) GetFilename(name string) string
GetFilename returns the syntactically valid standalone filename string.
It returns an empty string if the flag is absent or is not a string type.
func (*FlagValues) GetFilenameSlice ¶
func (c *FlagValues) GetFilenameSlice(name string) []string
GetFilenameSlice returns the value of a filename array flag.
Returns nil if the flag is absent or is not a []string type.
func (*FlagValues) GetFilepath ¶
func (c *FlagValues) GetFilepath(name string) string
GetFilepath returns the normalized physical file path string.
It returns an empty string if the flag is absent or is not a string type.
func (*FlagValues) GetFilepathSlice ¶
func (c *FlagValues) GetFilepathSlice(name string) []string
GetFilepathSlice returns the value of a filepath array flag.
Returns nil if the flag is absent or is not a []string type.
func (*FlagValues) GetFloat ¶
func (c *FlagValues) GetFloat(name string) float64
GetFloat returns the value of a float flag.
Returns 0.0 if the flag is absent or is not a float64 type.
func (*FlagValues) GetFloatSlice ¶
func (c *FlagValues) GetFloatSlice(name string) []float64
GetFloatSlice returns the value of a float array flag.
Returns nil if the flag is absent or is not a []float64 type.
func (*FlagValues) GetFullURL ¶
func (c *FlagValues) GetFullURL(name string) string
GetFullURL returns the validated full URL domain locator string.
It returns an empty string if the flag is absent or is not a string type.
func (*FlagValues) GetFullURLSlice ¶
func (c *FlagValues) GetFullURLSlice(name string) []string
GetFullURLSlice returns the value of a full URL array flag.
Returns nil if the flag is absent or is not a []string type.
func (*FlagValues) GetInt ¶
func (c *FlagValues) GetInt(name string) int
GetInt returns the value of an integer flag.
Returns 0 if the flag is absent or is not an integer type.
func (*FlagValues) GetIntSlice ¶
func (c *FlagValues) GetIntSlice(name string) []int
GetIntSlice returns the value of an integer array flag.
Returns nil if the flag is absent or is not a []int type.
func (*FlagValues) GetJSON ¶
func (c *FlagValues) GetJSON(name string) string
GetJSON returns the validated JSON raw payload text.
It returns an empty string if the flag is absent or is not a string type.
func (*FlagValues) GetPath ¶
func (c *FlagValues) GetPath(name string) string
GetPath returns the cleaned semantic path component layout string.
It returns an empty string if the flag is absent or is not a string type.
func (*FlagValues) GetPathSlice ¶
func (c *FlagValues) GetPathSlice(name string) []string
GetPathSlice returns the value of a path array flag.
Returns nil if the flag is absent or is not a []string type.
func (*FlagValues) GetRelativeURL ¶
func (c *FlagValues) GetRelativeURL(name string) string
GetRelativeURL returns the validated relative target path string layout.
It returns an empty string if the flag is absent or is not a string type.
func (*FlagValues) GetRelativeURLSlice ¶
func (c *FlagValues) GetRelativeURLSlice(name string) []string
GetRelativeURLSlice returns the value of a relative URL array flag.
Returns nil if the flag is absent or is not a []string type.
func (*FlagValues) GetString ¶
func (c *FlagValues) GetString(name string) string
GetString returns the value of a string flag.
Returns empty string if the flag is absent or is not a string type.
func (*FlagValues) GetStringSlice ¶
func (c *FlagValues) GetStringSlice(name string) []string
GetStringSlice returns the value of a string array flag.
Returns nil if the flag is absent or is not a []string type.
func (*FlagValues) GetTime ¶
func (c *FlagValues) GetTime(name string) time.Time
GetTime returns the value of a time flag as a time.Time object.
Returns a zero time.Time object if the flag is absent or is not a time.Time type.
func (*FlagValues) GetTimeSlice ¶
func (c *FlagValues) GetTimeSlice(name string) []time.Time
GetTimeSlice returns the value of a time array flag.
Returns nil if the flag is absent or is not a []time.Time type.
func (*FlagValues) GetURL ¶
func (c *FlagValues) GetURL(name string) string
GetURL returns the validated basic URL target string layout.
It returns an empty string if the flag is absent or is not a string type.
func (*FlagValues) GetURLSlice ¶
func (c *FlagValues) GetURLSlice(name string) []string
GetURLSlice returns the value of a URL array flag.
Returns nil if the flag is absent or is not a []string type.
func (*FlagValues) Has ¶
func (c *FlagValues) Has(name string) bool
Has checks if a specific flag was explicitly provided by the user in the terminal.
Useful to differentiate between a flag omitted (using default) and one explicitly sent.
func (*FlagValues) SetInternalValue ¶
func (c *FlagValues) SetInternalValue(name string, val any)
SetInternalValue stores a raw or processed value inside the internal map.
Arguments:
- name: The long name identifier of the target flag.
- val: The computed or raw value payload to hold.