config

package module
v3.0.0-...-247640f Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2025 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxLenOptionName  = 18
	MaxLenCommandName = 20
	MaxLenAppName     = 30
	DateFormat        = Datetime("YYYY-MM-DD")
	TimeFormat        = Datetime("hh:mm:ss")
	TimeFormatShort   = Datetime("hh:mm")
)
View Source
const (
	LocalConfig  fileType = "local"
	UserConfig   fileType = "user"
	GlobalConfig fileType = "global"
)

Variables

View Source
var (
	//USER_DIR    string
	CONFIG_DIR  string
	GLOBAL_DIRS string // colon separated list to look for
	WORKING_DIR string
	CONFIG_EXT  = ".conf"
)

Functions

func ValidateName

func ValidateName(name string) (err error)

rules for names:

must not start with numbers
may not have more than an underscore in a row
may not have more than a dash in a row
may not start or end with an underscore
may not start or end with a dash
may not have an underscore followed by a dash
may not have a dash followed by an underscore
other than that, just lowercase letters are allowed
we need at least two characters

Types

type App

type App struct {
	Name        string
	Description string
	Version     version.Version

	*Command
	Commands []*Command
	// contains filtered or unexported fields
}

func NewApp

func NewApp(mainfn func(*App) error, name string) *App

func NewApp(mainfn func() error, name string, opts ...appOption) *App {

func (*App) ActiveCommand

func (a *App) ActiveCommand() *Command

func (*App) CommandUsage

func (c *App) CommandUsage(cmd string) string

func (*App) DefaultValues

func (a *App) DefaultValues() values

func (*App) EnvVar

func (a *App) EnvVar(o optionInterface) string

func (*App) GetCommandByName

func (a *App) GetCommandByName(name string) *Command

func (*App) NewCommand

func (a *App) NewCommand(fn func(a *App) error, name string) *Command

func (*App) Reset

func (a *App) Reset()

func (*App) Run

func (a *App) Run() (err error)

func (*App) SaveToGlobalConfig

func (a *App) SaveToGlobalConfig(opts ...optionInterface) error

func (*App) SaveToLocalConfig

func (a *App) SaveToLocalConfig(opts ...optionInterface) error

func (*App) SaveToUserConfig

func (a *App) SaveToUserConfig(opts ...optionInterface) error

func (*App) SetArgs

func (a *App) SetArgs(args []string) *App

func (*App) SetHelp

func (a *App) SetHelp(str string) *App

func (*App) SetVersion

func (a *App) SetVersion(maj, min, patch int) *App

func (*App) Usage

func (c *App) Usage() string

func (*App) WithAsciiArt

func (a *App) WithAsciiArt() *App

type Bool

type Bool struct{}

func (Bool) Parse

func (Bool) Parse(s string) (bool, error)

func (Bool) ToString

func (Bool) ToString(s bool) string

func (Bool) Type

func (Bool) Type() string

type Command

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

func (*Command) Bool

func (c *Command) Bool(target *bool, name string) *Option[bool]

Bool allows input that is a boolean (true/false)

func (*Command) Date

func (c *Command) Date(target *Time, name string) *Option[Time]

Date allows a date input in the format defined by DateFormat

func (*Command) DateTime

func (c *Command) DateTime(target *Time, name, format string) *Option[Time]

DateTime allows a date/time input in the format defined by the given format string (MS Excel style)

func (*Command) Float

func (c *Command) Float(target *float64, name string) *Option[float64]

Float allows input that is a floating number

func (*Command) Floats

func (c *Command) Floats(target *[]float64, name string) *Option[[]float64]

Floats allows input of multiple floats, separated by #

func (*Command) GetLastOption

func (c *Command) GetLastOption() optionInterface

func (*Command) GetOptionByName

func (c *Command) GetOptionByName(name string) optionInterface

func (*Command) HasLastOption

func (c *Command) HasLastOption() bool

func (Command) Help

func (c Command) Help() string

func (*Command) Int

func (c *Command) Int(target *int, name string) *Option[int]

Int allows input that is a integer

func (*Command) Ints

func (c *Command) Ints(target *[]int, name string) *Option[[]int]

Ints allows input of multiple ints, separated by #

func (*Command) Json

func (c *Command) Json(target *Json, name string) *Option[Json]

func (*Command) MultiSelect

func (c *Command) MultiSelect(target *[]string, name string, choices []string) *Option[[]string]

MultiSelect offers a range of choices to select multiple from (separated by #)

func (*Command) MultiSelectInput

func (c *Command) MultiSelectInput(target *[]string, name string, choices []string) *Option[[]string]

MultiSelectInput offers a range of choices to select multiple from (separated by #), but also user defined strings can be used

func (Command) Name

func (c Command) Name() string

func (*Command) Path

func (c *Command) Path(target *Path, name string) *Option[Path]

Path allows input that is a path

func (*Command) Relax

func (c *Command) Relax(opts ...string) *Command

func (*Command) Select

func (c *Command) Select(target *string, name string, choices []string) *Option[string]

Select offers a range of choices to select from

func (*Command) SelectInput

func (c *Command) SelectInput(target *string, name string, choices []string) *Option[string]

SelectInput offers a range of choices to select from, but also a user defined string can be used

func (*Command) SetHelp

func (c *Command) SetHelp(str string) *Command

func (*Command) Skip

func (c *Command) Skip(opts ...string) *Command

func (*Command) SkipAllBut

func (c *Command) SkipAllBut(except ...string) *Command

func (*Command) String

func (c *Command) String(target *string, name string) *Option[string]

String allows any string input

func (*Command) Strings

func (c *Command) Strings(target *[]string, name string) *Option[[]string]

Strings allows input that is a list of strings, separated by #

func (*Command) Time

func (c *Command) Time(target *Time, name string) *Option[Time]

Time allows a time input in the format defined by TimeFormat

func (*Command) TimeShort

func (c *Command) TimeShort(target *Time, name string) *Option[Time]

TimeShort allows a time input in the format defined by Time

type Datetime

type Datetime string

func (Datetime) MustParse

func (d Datetime) MustParse(s string) Time

func (Datetime) Parse

func (d Datetime) Parse(s string) (t Time, err error)

func (Datetime) ToString

func (Datetime) ToString(tf Time) string

func (Datetime) Type

func (s Datetime) Type() string

type Float

type Float struct{}

func (Float) Parse

func (Float) Parse(s string) (float64, error)

func (Float) ToString

func (Float) ToString(s float64) string

func (Float) Type

func (Float) Type() string

type Floats

type Floats struct{}

func (Floats) Parse

func (Floats) Parse(s string) (res []float64, err error)

func (Floats) ToString

func (Floats) ToString(flts []float64) string

func (Floats) Type

func (s Floats) Type() string

type Int

type Int struct{}

func (Int) Parse

func (Int) Parse(s string) (int, error)

func (Int) ToString

func (Int) ToString(s int) string

func (Int) Type

func (Int) Type() string

type Ints

type Ints struct{}

func (Ints) Parse

func (Ints) Parse(s string) (res []int, err error)

func (Ints) ToString

func (Ints) ToString(ints []int) string

func (Ints) Type

func (s Ints) Type() string

type InvalidNameError

type InvalidNameError string

func (InvalidNameError) Error

func (e InvalidNameError) Error() string

type Json

type Json map[string]any

func (Json) MustParse

func (t Json) MustParse(s string) Json

func (Json) Parse

func (Json) Parse(s string) (Json, error)

func (Json) String

func (j Json) String() string

func (Json) ToString

func (Json) ToString(s Json) string

func (Json) Type

func (Json) Type() string

type MultiSelect

type MultiSelect struct {
	Choices       []string
	InputPossible bool
}

func (MultiSelect) Parse

func (opt MultiSelect) Parse(s string) (res []string, err error)

func (MultiSelect) ToString

func (MultiSelect) ToString(s []string) string

func (MultiSelect) Type

func (s MultiSelect) Type() string

type Option

type Option[T any] struct {
	// contains filtered or unexported fields
}

func Custom

func Custom[T any](c *Command, target *T, name string, type_ TypeHandler[T]) *Option[T]

Custom creates a custom option for any given type

func (*Option[T]) Command

func (o *Option[T]) Command() string

func (*Option[T]) Default

func (o *Option[T]) Default() any

func (*Option[T]) Get

func (o *Option[T]) Get() (v T)

func (*Option[T]) Help

func (o *Option[T]) Help() string

func (*Option[T]) IsSet

func (o *Option[T]) IsSet() bool

func (*Option[T]) Name

func (o *Option[T]) Name() string

func (*Option[T]) Required

func (o *Option[T]) Required() bool

func (*Option[T]) Set

func (o *Option[T]) Set(s string) error

func (*Option[T]) SetAsLast

func (o *Option[T]) SetAsLast() *Option[T]

func (*Option[T]) SetDefault

func (o *Option[T]) SetDefault(v T) *Option[T]

func (*Option[T]) SetHelp

func (o *Option[T]) SetHelp(str string) *Option[T]

func (*Option[T]) SetRequired

func (o *Option[T]) SetRequired() *Option[T]

func (*Option[T]) SetShortflag

func (o *Option[T]) SetShortflag(r rune) *Option[T]

func (*Option[T]) SetValidator

func (o *Option[T]) SetValidator(v Validator[T]) *Option[T]

maybe that can just become a method of Type ? (and wrapped for further validations?)

func (*Option[T]) ShortFlag

func (o *Option[T]) ShortFlag() string

func (*Option[T]) Type

func (o *Option[T]) Type() string

func (*Option[T]) Validate

func (o *Option[T]) Validate() error

func (*Option[T]) Value

func (o *Option[T]) Value() any

type Path

type Path struct {
	File string
	Dirs []string
	Ext  string
}

func (Path) Parse

func (Path) Parse(s string) (Path, error)

func (Path) String

func (t Path) String() string

func (Path) ToString

func (Path) ToString(s Path) string

func (Path) Type

func (Path) Type() string

type Select

type Select struct {
	Choices       []string
	InputPossible bool
}

func (Select) Parse

func (opt Select) Parse(s string) (string, error)

func (Select) ToString

func (Select) ToString(s string) string

func (Select) Type

func (s Select) Type() string

type String

type String struct{}

func (String) Parse

func (String) Parse(s string) (string, error)

func (String) ToString

func (String) ToString(s string) string

func (String) Type

func (String) Type() string

type Strings

type Strings struct{}

func (Strings) Parse

func (Strings) Parse(s string) ([]string, error)

func (Strings) ToString

func (Strings) ToString(s []string) string

func (Strings) Type

func (s Strings) Type() string

type Time

type Time struct {
	time.Time
	Format string
}

func (Time) String

func (t Time) String() string

type TypeHandler

type TypeHandler[T any] interface {
	Parse(s string) (T, error)
	ToString(T) string
	Type() string
}

type Validator

type Validator[T any] interface {
	Validate(T) error
}

Jump to

Keyboard shortcuts

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