Documentation ¶
Overview ¶
Package target implements gnu make like target processing from yaml files and OS environment variables.
Index ¶
- Constants
- Variables
- func Asset(name string) ([]byte, error)
- func AssetDir(name string) ([]string, error)
- func AssetInfo(name string) (os.FileInfo, error)
- func AssetNames() []string
- func BuiltinDefault() (string, string, error)
- func MustAsset(name string) []byte
- func RestoreAsset(dir, name string) error
- func RestoreAssets(dir, name string) error
- type ConfigFile
- type Configs
- type Env
- type File
- type MSS
- type Make
- type RawConfig
- type Remotes
- type Target
Constants ¶
const ( // ConfigDirName is the name of the folder where ron will look for yaml config // files. ConfigDirName = ".ron" // ConfigFileName is the main ron config file that overrides other files. ConfigFileName = "ron.yaml" )
const ( // ExecSentinel is the first character looked for in envs to // signify that the value should be executed in the shell // and the output assigned to the key. ExecSentinel = "+" )
Variables ¶
var ( // DefaultYamlBytes is used for the default built in binary targets // exported into default.go. If using as a library you can override this // by setting target.DefaultYamlBytes globally during startup. // defaultYaml, err := config.Asset("myconfig/default.yaml") // if err != nil { // return err // } // target.DefaultYamlBytes = defaultYaml DefaultYamlBytes = []byte{} )
var LoadConfigFile = func(path string) (*RawConfig, error) { path, err := filepath.Abs(path) if err != nil { return nil, err } f, err := fi.NewFile(path) if err != nil { return nil, err } content, err := template.RenderGo(path, f.String()) if err != nil { return nil, err } var c *ConfigFile err = yaml.Unmarshal([]byte(content), &c) if err != nil { return nil, extractConfigError(path, content, err) } if c == nil { return nil, fmt.Errorf("empty file requires envs and target keys") } envs, err := yaml.Marshal(c.Envs) if err != nil { return nil, err } remotes, err := yaml.Marshal(c.Remotes) if err != nil { return nil, err } targets, err := yaml.Marshal(c.Targets) if err != nil { return nil, err } return &RawConfig{ Envs: string(envs), Filepath: path, Remotes: string(remotes), Targets: string(targets), }, nil }
LoadConfigFile will open a given file path and return it's raw envs and targets.
Functions ¶
func Asset ¶
Asset loads and returns the asset for the given name. It returns an error if the asset could not be found or could not be loaded.
func AssetDir ¶
AssetDir returns the file names below a certain directory embedded in the file by go-bindata. For example if you run go-bindata on data/... and data contains the following hierarchy:
data/ foo.txt img/ a.png b.png
then AssetDir("data") would return []string{"foo.txt", "img"} AssetDir("data/img") would return []string{"a.png", "b.png"} AssetDir("foo.txt") and AssetDir("notexist") would return an error AssetDir("") will return []string{"data"}.
func AssetInfo ¶
AssetInfo loads and returns the asset info for the given name. It returns an error if the asset could not be found or could not be loaded.
func BuiltinDefault ¶
BuiltinDefault loads the binary yaml file and returns envs, targets, and any errors.
func MustAsset ¶
MustAsset is like Asset but panics when Asset would return an error. It simplifies safe initialization of global variables.
func RestoreAsset ¶
RestoreAsset restores an asset under the given directory
func RestoreAssets ¶
RestoreAssets restores an asset under the given directory recursively
Types ¶
type ConfigFile ¶
type ConfigFile struct { Envs []map[string]string `json:"envs" yaml:"envs"` Remotes *Remotes `json:"remotes" yaml:"remotes"` Targets map[string]struct { Before []string `json:"before" yaml:"before"` After []string `json:"after" yaml:"after"` Cmd string `json:"cmd" yaml:"cmd"` Description string `json:"description" yaml:"description"` } `json:"targets" yaml:"targets"` }
ConfigFile is used to unmarshal configuration files.
func (*ConfigFile) EnvsString ¶
func (c *ConfigFile) EnvsString() string
EnvsString is used for debugging the loaded envs.
func (*ConfigFile) RemotesString ¶
func (c *ConfigFile) RemotesString() string
RemotesString is used for debugging the loaded remotes.
func (*ConfigFile) TargetsString ¶
func (c *ConfigFile) TargetsString() string
TargetsString is used for debugging the loaded targets.
type Configs ¶
type Configs struct { RemoteEnv string // The remote hosts to run the command on. This is (file):env RemoteHosts []*execute.SSHConfig // a list of remote hosts to execute on. Files []*File StdOut io.Writer StdErr io.Writer }
Configs is a mapping of filename to target file.
func NewConfigs ¶
func NewConfigs(configs []*RawConfig, remoteEnv string, stdOut io.Writer, stdErr io.Writer) (*Configs, error)
NewConfigs takes a default set of yaml in config format and then overrides them with a new set of config target replacements.
func (*Configs) GetEnv ¶
GetEnv will return the targets associated environment variables to use when running the target.
func (*Configs) ListClean ¶
func (tc *Configs) ListClean()
ListClean will print out a full list of targets suitable for bash completion.
func (*Configs) ListRemotes ¶
ListRemotes will print out the list of remote envs set in each file.
type Env ¶
type Env struct { OSEnvs MSS // the initial environment variables W io.Writer // underlying writer // contains filtered or unexported fields }
Env takes a raw yaml environment definition and expands and overrides any variables.
func NewEnv ¶
NewEnv create a new environment variable parser similar to make variables. In order to populate the Config envs, the func Process must be run after initialization.
func (*Env) Config ¶
Config returns the envs config as a map[string]string. It will process each env if that has not been done already.
func (*Env) Getenv ¶
Getenv retrieves the value of the environment variable named by the key. It returns the value, which will be empty if the variable is not present.
func (*Env) List ¶
List prints to the underlying writer a list of the configured env based on overriden environment variables and default yaml ones.
type File ¶
type File struct { // Filepath is the path to the input file. Filepath string // Targets are the files targets. Targets map[string]*Target // Env are the files environment variables. Env *Env // Remotes is a mapping of environment to remote hosts. Remotes Remotes // contains filtered or unexported fields }
File is a mapping of the config file to its parsed envs and targets.
type MSS ¶
MSS is an alias for map[string]string
func ParseOSEnvs ¶
ParseOSEnvs takes a list of "key=val" and splits them into a map[string]string.
type Make ¶
type Make struct {
Configs *Configs
}
Make runs targets...like make kinda
type RawConfig ¶
RawConfig contains the raw strings from a loaded config file.
func LoadConfigFiles ¶
func LoadConfigFiles(defaultYamlPath, overrideYamlPath string, withHomeDirectory bool) ([]*RawConfig, string, error)
LoadConfigFiles loads the default, override, and any directory config files and returns them as a slice. If defaultYamlPath is an empty string, the defaults compiled into ron will be used instead. If overrideYamlPath is blank, it will find the nearest parent folder containing a ron.yaml file and use that file instead. In that case, the path to that file will be returned so that the caller can change the working directory to that folder before running further commands.
type Target ¶
type Target struct { File *File `json:"-" yaml:"-"` Name string `json:"name" yaml:"name"` Before []string `json:"before" yaml:"before"` After []string `json:"after" yaml:"after"` Cmd string `json:"cmd" yaml:"cmd"` Description string `json:"description" yaml:"description"` W io.Writer `json:"-" yaml:"-"` // underlying stdout writer WErr io.Writer `json:"-" yaml:"-"` // underlying stderr writer // contains filtered or unexported fields }
Target contains the set of commands to run along with any before and after targets to run.