config

package
v0.0.0-...-e53fd9e Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2020 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AppProperties

type AppProperties struct {
	PackageName    string
	EnvConfigName  string
	FileConfigName string
	ReqEnvName     string
	PermConfigFile os.FileMode
	PermConfigDir  os.FileMode
}

AppProperties represents constants associated with the running application.

func (*AppProperties) ConfigPath

func (app *AppProperties) ConfigPath() string

ConfigPath provides the default YAML configuration file path when not overridden by the user via command-line Parameters.

func (*AppProperties) HomeDir

func (app *AppProperties) HomeDir() string

HomeDir provides an absolute path to the user's home directory. Note that if no $HOME dir can be determined, the current working dir is returned.

type ArgExpansion

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

ArgExpansion defines the simple single-pass expansion rules performed on the args elements defined in the YAML configuration file.

func NewArgExpansion

func NewArgExpansion(initFile string, shellArgs ...string) *ArgExpansion

NewArgExpansion constructs a new expansion ruleset with given expansion values and compiles the internal key matcher.

func (*ArgExpansion) Compile

func (ae *ArgExpansion) Compile() *regexp.Regexp

Compile builds a regexp pattern that matches a key in the ruleset by simply using a group-logical-OR of each key escaped via regexp.QuoteMeta.

func (*ArgExpansion) Expand

func (ae *ArgExpansion) Expand(arg string) interface{}

Expand performs a single-pass literal string substitution according to the rule map. If the given arg matches exactly a rule key, then the rule value is returned, otherwise the original arg is returned.

func (*ArgExpansion) ExpandArgs

func (ae *ArgExpansion) ExpandArgs(args ...string) []string

ExpandArgs calls Expand on each element in args.

type ArgList

type ArgList []string

ArgList contains the positional arguments given to the shell command. Do NOT include the command at position 0 (as required); it will be added for you.

type BoolFlag

type BoolFlag struct {
	Flag   string
	Desc   string
	Preset bool
}

BoolFlag contains the attributes of a bool type command-line flag.

type Config

type Config struct {
	Shell   string  `yaml:"shell"`
	Args    ArgList `yaml:"args"`
	CmdFlag string  `yaml:"cmdflag"`
	Env     EnvList `yaml:"env"`
}

Config represents the parameters to launch and configure the user shell.

func ParseFile

func ParseFile(filePath string) (*Config, error)

ParseFile parses the YAML configuration into our tidy struct.

func (*Config) String

func (cfg *Config) String() string

type EnvList

type EnvList []Source

EnvList contains the named environments able to be sourced.

type Parameters

type Parameters struct {
	App           AppProperties
	ConfigPath    string
	ShellCommand  string
	LogHandler    string
	DebugEnabled  bool
	OrphanEnviron bool
	Profiles      Profile
	ShellArgs     []string
}

Parameters represents the global configuration of the application, mostly defined or initialized by command-line arguments.

type Profile

type Profile []string

Profile represents gosh environments to load.

func (*Profile) Set

func (p *Profile) Set(value string) error

Set implements the flag.Value interface to parse profiles from -p flags.

func (*Profile) String

func (p *Profile) String() string

String constructs a descriptive representation of a Profile.

type ProfileFlag

type ProfileFlag struct {
	Flag string
	Desc string
}

ProfileFlag contains the attributes of a Profile type command-line flag.

type Source

type Source map[string]SourceList

Source associates a named directory/environment with a SourceList.

type SourceList

type SourceList []string

SourceList contains names of files to be sourced by the shell environment.

type StartFlags

type StartFlags struct {
	ConfigPath    StringFlag
	ShellCommand  StringFlag
	Profiles      ProfileFlag
	OrphanEnviron BoolFlag
	LogHandler    StringFlag
	DebugEnabled  BoolFlag
}

StartFlags contains attributes of the pre-defined command-line flags.

func (*StartFlags) Parse

func (sf *StartFlags) Parse(app *AppProperties) *Parameters

Parse initializes the default flagset and parses command-line flags into the shareable Parameters struct.

type StringFlag

type StringFlag struct {
	Flag   string
	Desc   string
	Preset string
}

StringFlag contains the attributes of a string type command-line flag.

Jump to

Keyboard shortcuts

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