flagx

package
v1.4.5 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

----------------------------------------------------------------- * L o r d O f S c r i p t s (tm) * Copyright (C)2026 Dídimo Grimaldo T. * APP_NAME * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * A custom Byte flag for the flag package that can be displayed as rune. *-----------------------------------------------------------------

----------------------------------------------------------------- * L o r d O f S c r i p t s (tm) * Copyright (C)2026 Dídimo Grimaldo T. * APP_NAME * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * A custom Date Flag for the GO flag package. You can specify dates * in various formats as defined by your application. *-----------------------------------------------------------------

----------------------------------------------------------------- * L o r d O f S c r i p t s (tm) * Copyright (C)2026 Dídimo Grimaldo T. * go-App * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * Utility object to handle command-line sub-commands using the * standard flag package. Moved here from goVault. *-----------------------------------------------------------------

----------------------------------------------------------------- * L o r d O f S c r i p t s (tm) * Copyright (C)2026 Dídimo Grimaldo T. * APP_NAME * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * A custom Rune Flag for the GO flag package. We can now use rune * flags in the command line. For that we implement the flag.Value * interface. * This implementation works with both single and multi-byte runes. *-----------------------------------------------------------------

----------------------------------------------------------------- * L o r d O f S c r i p t s (tm) * Copyright (C)2025 Dídimo Grimaldo T. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * A Flag for the GO flag package. Useful when you want a flag/CLI option * to be any of a pre-determined list of strings. *-----------------------------------------------------------------

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterByteVar

func RegisterByteVar(r *ByteFlag, name string, usage string)

func RegisterByteVarSet

func RegisterByteVarSet(r *ByteFlag, name string, value byte, usage string)

func RegisterDateVar

func RegisterDateVar(r *DateFlag, name string, usage string, formats ...string)

registers an instance of DateFlag with the flag package for parsing.

func RegisterRuneVar

func RegisterRuneVar(r *RuneFlag, name string, value rune, usage string)

func ThisMonth

func ThisMonth() time.Time

A (local) date that corresponds to the 1st of the current month, no time.

func ThisYear

func ThisYear() time.Time

A (local) date that corresponds to January 1st of the current year, no time.

func Today

func Today() time.Time

A (local) date that corresponds to today. No time.

Types

type ByteFlag

type ByteFlag struct {
	Value byte
	IsSet bool
}

func (*ByteFlag) Set

func (r *ByteFlag) Set(value string) error

func (*ByteFlag) String

func (r *ByteFlag) String() string

type DateFlag

type DateFlag struct {
	Value time.Time
	IsSet bool
	// contains filtered or unexported fields
}

func NewDateVar

func NewDateVar(formats ...string) *DateFlag

func (*DateFlag) Has

func (r *DateFlag) Has() (year, month, day bool)

returns an indication of what the default format has (Year,Month,Day)

func (*DateFlag) Set

func (r *DateFlag) Set(value string) error

invoked by flag.Parse() to set the value. We attempt to convert the date with "now" or "ahora" to a full date/time, "today" and "hoy" to today's date without time, or to the first interpretation of the formats given at the constructor. Else an error is produced. Time is in UTC.

func (*DateFlag) String

func (r *DateFlag) String() string

implements fmt.Stringer rendering the set date in the first format of the constructor list, else defaults to YYYY-MM-DD

type FlagSubCommander added in v1.4.1

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

func NewFlagSubCommander added in v1.4.1

func NewFlagSubCommander() *FlagSubCommander

(ctor) utility for dealing with flag subcommands

func (*FlagSubCommander) ChosenCommand added in v1.4.1

func (fsc *FlagSubCommander) ChosenCommand() *flag.FlagSet

After Parse() without error this method returns the flagset corresponding to the selected sub-command.

func (*FlagSubCommander) ChosenCommandName added in v1.4.1

func (fsc *FlagSubCommander) ChosenCommandName() string

After Parse() without error this method returns the name of the sub-command.

func (*FlagSubCommander) Define added in v1.4.1

func (fsc *FlagSubCommander) Define(subCommandName string, eh flag.ErrorHandling) *flag.FlagSet

Defines a new flag set (subcommand) with the subcommand name and error handling directive (ExitOnError, ContinueOnError, PanicOnError). if already defined a warning message is produced but returns the previously-defined flag set.

func (*FlagSubCommander) FreeArguments added in v1.4.1

func (fsc *FlagSubCommander) FreeArguments() []string

Returns the free arguments after the flags of the sub-command.

func (*FlagSubCommander) IsValidSubcommand added in v1.4.1

func (fsc *FlagSubCommander) IsValidSubcommand(name string) bool

Returns true if name represents a valid/registered sub-command. It is normalized to lowercase.

func (*FlagSubCommander) Parse added in v1.4.1

func (fsc *FlagSubCommander) Parse() error

Verifies that the subcommand name is given and parses the flags after the subcommand, returning nil or an error if any. After this, upon successful completion, use ChosenCommandName() to obtain the sub-command given in the command-line, and ChosenCommand() to get the flag.FlagSet corresponding to that command.

func (*FlagSubCommander) String added in v1.4.1

func (fsc *FlagSubCommander) String() string

Implements fmt.Stringer. Returns the list of defined subcommands. i.e. "foo,bar"

type RuneFlag

type RuneFlag struct {
	Value rune
	IsSet bool
}

func (*RuneFlag) Set

func (r *RuneFlag) Set(value string) error

func (*RuneFlag) String

func (r *RuneFlag) String() string

type StringsFlag added in v1.3.0

type StringsFlag struct {
	Value string
	IsSet bool
	// contains filtered or unexported fields
}

func RegisterSelectVar added in v1.3.0

func RegisterSelectVar(r *StringsFlag, name string, value string, usage string) *StringsFlag

func (*StringsFlag) Help added in v1.3.0

func (r *StringsFlag) Help() string

return the list of allowed values (choices) and default value

func (*StringsFlag) IsValid added in v1.3.0

func (r *StringsFlag) IsValid() bool

func (*StringsFlag) Set added in v1.3.0

func (r *StringsFlag) Set(value string) error

implements flag.Value

func (*StringsFlag) SetChoices added in v1.3.0

func (r *StringsFlag) SetChoices(choices []string) *StringsFlag

set the string choices that will be considered valid. Any other values will be rejected by Set(). Values will be lowercased.

func (*StringsFlag) Strict added in v1.3.0

func (r *StringsFlag) Strict(strict bool) *StringsFlag

when strict is set, the Set() function only accepts the values defined in SetChoices(), else it accepts any; thus behaving like a simple flag.StringVar

func (*StringsFlag) String added in v1.3.0

func (r *StringsFlag) String() string

implements flag.Value and fmt.Stringer

Jump to

Keyboard shortcuts

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