update deps for kingpeon update

use os.exec instead of syscall.exec for windows
This commit is contained in:
Cory Bennett
2017-09-08 18:53:21 -07:00
parent 036ebb4bf7
commit 86b963bdb5
70 changed files with 592 additions and 276 deletions
+36 -38
View File
@@ -78,8 +78,41 @@ func (f *FigTree) LoadAllConfigs(configFile string, options interface{}) error {
return nil
}
func (f *FigTree) LoadConfig(file string, options interface{}) (err error) {
func (f *FigTree) LoadConfigBytes(config []byte, source string, options interface{}) (err error) {
f.populateEnv(options)
m := &merger{sourceFile: source}
type tmpOpts struct {
Config ConfigOptions
}
tmp := reflect.New(reflect.ValueOf(options).Elem().Type()).Interface()
// look for config settings first
err = yaml.Unmarshal(config, m)
if err != nil {
return errors.Wrap(err, fmt.Sprintf("Unable to parse %s", source))
}
// then parse document into requested struct
err = yaml.Unmarshal(config, tmp)
if err != nil {
return errors.Wrap(err, fmt.Sprintf("Unable to parse %s", source))
}
m.setSource(reflect.ValueOf(tmp))
m.mergeStructs(
reflect.ValueOf(options),
reflect.ValueOf(tmp),
)
if m.Config.Stop {
f.stop = true
return nil
}
f.populateEnv(options)
return nil
}
func (f *FigTree) LoadConfig(file string, options interface{}) (err error) {
basePath, err := os.Getwd()
if err != nil {
return err
@@ -89,29 +122,12 @@ func (f *FigTree) LoadConfig(file string, options interface{}) (err error) {
if err != nil {
rel = file
}
m := &merger{sourceFile: rel}
type tmpOpts struct {
Config ConfigOptions
}
if stat, err := os.Stat(file); err == nil {
tmp := reflect.New(reflect.ValueOf(options).Elem().Type()).Interface()
if stat.Mode()&0111 == 0 {
log.Debugf("Loading config %s", file)
// first parse out any config processing option
if data, err := ioutil.ReadFile(file); err == nil {
err := yaml.Unmarshal(data, m)
if err != nil {
return errors.Wrap(err, fmt.Sprintf("Unable to parse %s", file))
}
err = yaml.Unmarshal(data, tmp)
if err != nil {
return errors.Wrap(err, fmt.Sprintf("Unable to parse %s", file))
}
// if reflect.ValueOf(tmp).Kind() == reflect.Map {
// tmp, _ = util.YamlFixup(tmp)
// }
return f.LoadConfigBytes(data, rel, options)
}
} else {
log.Debugf("Found Executable Config file: %s", file)
@@ -123,26 +139,8 @@ func (f *FigTree) LoadConfig(file string, options interface{}) (err error) {
if err := cmd.Run(); err != nil {
return errors.Wrap(err, fmt.Sprintf("%s is exectuable, but it failed to execute:\n%s", file, cmd.Stderr))
}
// first parse out any config processing option
err := yaml.Unmarshal(stdout.Bytes(), m)
if err != nil {
return errors.Wrap(err, fmt.Sprintf("Unable to parse %s", file))
}
err = yaml.Unmarshal(stdout.Bytes(), tmp)
if err != nil {
return errors.Wrap(err, fmt.Sprintf("Failed to parse STDOUT from executable config file %s", file))
}
return f.LoadConfigBytes(stdout.Bytes(), rel, options)
}
m.setSource(reflect.ValueOf(tmp))
m.mergeStructs(
reflect.ValueOf(options),
reflect.ValueOf(tmp),
)
if m.Config.Stop {
f.stop = true
return nil
}
f.populateEnv(options)
}
return nil
}
+2 -2
View File
@@ -58,10 +58,10 @@ func lookupCommand(app *kingpin.Application, command *DynamicCommand) *kingpin.C
}
func RegisterDynamicCommands(app *kingpin.Application, commands DynamicCommands, t *template.Template) error {
return doRegisterDynamicCommands(syscall.Exec, app, commands, t)
return RegisterDynamicCommandsWithRunner(syscall.Exec, app, commands, t)
}
func doRegisterDynamicCommands(run runner, app *kingpin.Application, commands DynamicCommands, t *template.Template) error {
func RegisterDynamicCommandsWithRunner(run runner, app *kingpin.Application, commands DynamicCommands, t *template.Template) error {
args := map[string]interface{}{}
opts := map[string]interface{}{}
+1 -1
View File
@@ -32,7 +32,7 @@ func TestRegisterDynamicCommands(t *testing.T) {
return nil
}
err = doRegisterDynamicCommands(run, app, data.DynamicCommands, tmpl)
err = RegisterDynamicCommandsWithRunner(run, app, data.DynamicCommands, tmpl)
assert.Nil(t, err)
expectedShell = "echo hello world"