configfilearg

package
v0.0.0-...-ca78c08 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2022 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"},
	FlagNames:     []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
	FlagNames     []string
	EnvName       string
	DefaultConfig string
	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