Skip to content

Commit

Permalink
Merge pull request #1387 from Khan/benkraft.config
Browse files Browse the repository at this point in the history
codegen/config: Add a new API to finish an already-validated config
  • Loading branch information
mtibben authored Sep 6, 2021
2 parents 71507df + 18b5df1 commit b978593
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions codegen/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,16 @@ func LoadConfig(filename string) (*Config, error) {
return nil, errors.Wrap(err, "unable to parse config")
}

if err := CompleteConfig(config); err != nil {
return nil, err
}

return config, nil
}

// CompleteConfig fills in the schema and other values to a config loaded from
// YAML.
func CompleteConfig(config *Config) error {
defaultDirectives := map[string]DirectiveConfig{
"skip": {SkipRuntime: true},
"include": {SkipRuntime: true},
Expand Down Expand Up @@ -140,12 +150,13 @@ func LoadConfig(filename string) (*Config, error) {

return nil
}); err != nil {
return nil, errors.Wrapf(err, "failed to walk schema at root %s", pathParts[0])
return errors.Wrapf(err, "failed to walk schema at root %s", pathParts[0])
}
} else {
var err error
matches, err = filepath.Glob(f)
if err != nil {
return nil, errors.Wrapf(err, "failed to glob schema filename %s", f)
return errors.Wrapf(err, "failed to glob schema filename %s", f)
}
}

Expand All @@ -163,13 +174,12 @@ func LoadConfig(filename string) (*Config, error) {
var schemaRaw []byte
schemaRaw, err = ioutil.ReadFile(filename)
if err != nil {
return nil, errors.Wrap(err, "unable to open schema")
return errors.Wrap(err, "unable to open schema")
}

config.Sources = append(config.Sources, &ast.Source{Name: filename, Input: string(schemaRaw)})
}

return config, nil
return nil
}

func (c *Config) Init() error {
Expand Down

0 comments on commit b978593

Please sign in to comment.