func (op *OptionParser) ParseConfig(filename string, args []string) (err os.Error) { data, err := yaml.ParseFile(filename) if err != nil { return err } for config, opt := range op.config2options { if opt.defined { continue } value, ok := data[config] if !ok { if opt.requiredConfig { runtime.Error("%s: error: required: %s", args[0], opt) } else { continue } } if opt.valueType == "bool" { if value == "true" || value == "on" || value == "yes" { *opt.boolValue = true } else if value == "false" || value == "off" || value == "no" { *opt.boolValue = false } else { runtime.Error("%s: error: invalid boolean value for %s: %q\n", args[0], config, value) } } else if opt.valueType == "string" { *opt.stringValue = value } else if opt.valueType == "int" { intValue, err := strconv.Atoi(value) if err != nil { runtime.Error("%s: error: couldn't convert the %s value %q to an integer\n", args[0], config, value) } *opt.intValue = intValue } } return nil }
func (nodule *Nodule) LoadConf() (err os.Error) { filename := filepath.Join(nodule.Path, "nodule.yaml") conf, err := yaml.ParseFile(filename) if err != nil { return nodule.ConfigError(err.String()) } typ, ok := conf.GetString("type") if !ok { return nodule.ConfigError("Couldn't get a config value for 'type' in %s", filename) } run, ok := conf.GetStringList("run") if !ok { switch typ { case "go": run = []string{"./" + nodule.Name, "{{$.Profile}}.yaml"} default: return nodule.ConfigError("Couldn't get a config value for 'run' in %s", filename) } } if len(run) == 0 { return nodule.ConfigError("Couldn't get a config value for 'run' in %s", filename) } env := GetConfigEnv() run, err = EvalStrings("run", run, env) if err != nil { return nodule.ConfigError(err.String()) } build, ok := conf.GetStringList("build") if !ok { switch typ { case "go": build = []string{"{{if $.FreeBSD}}gmake{{else}}make{{end}}"} default: return nodule.ConfigError("Couldn't get a config value for 'build' in %s", filename) } } if len(build) == 0 { return nodule.ConfigError("Couldn't get a config value for 'build' in %s", filename) } build, err = EvalStrings("build", build, env) if err != nil { return nodule.ConfigError(err.String()) } test, ok := conf.GetStringList("test") if !ok { switch typ { case "go": test = []string{"gotest", "-v"} default: return nodule.ConfigError("Couldn't get a config value for 'test' in %s", filename) } } if len(test) == 0 { return nodule.ConfigError("Couldn't get a config value for 'test' in %s", filename) } test, err = EvalStrings("test", test, env) if err != nil { return nodule.ConfigError(err.String()) } depends, ok := conf.GetStringList("depends") if !ok { switch typ { case "go": depends = []string{"*.go"} default: depends = make([]string, 0) } } nodule.Conf = &Config{ Type: typ, Build: build, Run: run, Test: test, Depends: depends, } return }
func (nodule *Nodule) LoadConf() (err os.Error) { filename := filepath.Join(nodule.Path, "nodule.yaml") conf, err := yaml.ParseFile(filename) if err != nil { return nodule.ConfigError(err.String()) } typ, ok := conf.GetString("type") if !ok { return nodule.ConfigError("Couldn't get a config value for 'type' in %s", filename) } run, ok := conf.GetStringList("run") if !ok { switch typ { case "go": run = []string{"./" + nodule.Name, "{{$.Profile}}.yaml"} default: return nodule.ConfigError("Couldn't get a config value for 'run' in %s", filename) } } if len(run) == 0 { return nodule.ConfigError("Couldn't get a config value for 'run' in %s", filename) } env := GetConfigEnv() run, err = EvalStrings("run", run, env) if err != nil { return nodule.ConfigError(err.String()) } build, ok := conf.GetStringList("build") if !ok { switch typ { case "go": build = goBuild default: return nodule.ConfigError("Couldn't get a config value for 'build' in %s", filename) } } if len(build) == 0 { return nodule.ConfigError("Couldn't get a config value for 'build' in %s", filename) } build, err = EvalStrings("build", build, env) if err != nil { return nodule.ConfigError(err.String()) } test, ok := conf.GetStringList("test") if !ok { switch typ { case "go": test = goTest default: return nodule.ConfigError("Couldn't get a config value for 'test' in %s", filename) } } if len(test) == 0 { return nodule.ConfigError("Couldn't get a config value for 'test' in %s", filename) } test, err = EvalStrings("test", test, env) if err != nil { return nodule.ConfigError(err.String()) } depends, ok := conf.GetStringList("depends") if !ok { switch typ { case "go": length := len(goDepends) + 1 depends = make([]string, length) copy(depends, goDepends) depends[length-1] = nodule.Name default: depends = defaultDepends } } ignore, ok := conf.GetStringList("ignore") if !ok { switch typ { case "go": ignore = goIgnore default: ignore = defaultIgnore } } nodule.Conf = &Config{ Type: typ, Build: build, Run: run, Test: test, Depends: depends, Ignore: ignore, } return }