configfilearg

package
v0.0.0-...-f4dfa5d Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2024 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultParser = &Parser{
	After:         []string{"server", "agent", "etcd-snapshot:1"},
	ConfigFlags:   []string{"--config", "-c"},
	EnvName:       version.ProgramUpper + "_CONFIG_FILE",
	DefaultConfig: "/etc/rancher/" + version.Program + "/config.yaml",
	ValidFlags:    map[string][]cli.Flag{"server": cmds.ServerFlags, "etcd-snapshot": cmds.EtcdSnapshotFlags},
}

Functions

func MustFindString

func MustFindString(args []string, target string) string

func MustParse

func MustParse(args []string) []string

Types

type Parser

type Parser struct {
	After         []string
	ConfigFlags   []string
	OverrideFlags []string
	EnvName       string
	DefaultConfig string
	// ValidFlags are maps of flags that are valid for that particular conmmand. This enables us to ignore flags in
	// the config file that do no apply to the current command.
	ValidFlags map[string][]cli.Flag
}

func (*Parser) FindString

func (p *Parser) FindString(args []string, target string) (string, error)

func (*Parser) Parse

func (p *Parser) Parse(args []string) ([]string, error)

Parse will parse an os.Args style slice looking for Parser.FlagNames after Parse.After. It will read the parameter value of Parse.FlagNames and read the file, appending all flags directly after the Parser.After value. This means a the non-config file flags will override, or if a slice append to, the config file values. If Parser.DefaultConfig is set, the existence of the config file is optional if not set in the os.Args. This means if Parser.DefaultConfig is set we will always try to read the config file but only fail if it's not found if the args contains Parser.FlagNames

Jump to

Keyboard shortcuts

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