Skip to content

Commit

Permalink
feat(config): Set existing build options from configuration file
Browse files Browse the repository at this point in the history
  • Loading branch information
elldritch committed Jan 24, 2018
1 parent 6010976 commit 0dd5ee9
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions cmd/fossa/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,33 +73,44 @@ func MakeCmd(c *cli.Context) error {
// A successful build will set Module.Resolved to true
// An unsuccessful build will set Module.Error to a value
func BuildCmd(c *cli.Context) error {
// Read configuration file
config, err := ReadConfig()
if err != nil {
return err
}
log.Logger.Errorf("read config: %+v\n", config)

mod := build.Module{
Type: c.String("type"),
// Set build options
buildType := c.String("type")
if len(buildType) == 0 && config != nil && len(config.Analyze) > 0 {
buildType = config.Analyze[0].Type
}

entryPoint := c.String("entry-point")
if len(entryPoint) == 0 && config != nil && len(config.Analyze) > 0 {
entryPoint = config.Analyze[0].Path
}

module := build.Module{
Type: buildType,
}

buildOpts := make(map[string]interface{})
buildOpts["install"] = c.Bool("install")
buildOpts["no-cache"] = c.Bool("no-cache")
buildOpts["entry-point"] = c.String("entry-point")
buildOpts["entry-point"] = entryPoint

if buildOpts["entry-point"].(string) != "" {
if len(buildOpts["entry-point"].(string)) > 0 {
// override module manifest
mod.Manifest = buildOpts["entry-point"].(string)
module.Manifest = buildOpts["entry-point"].(string)
}

if err := mod.Analyze(buildOpts); err != nil {
if err := module.Analyze(buildOpts); err != nil {
log.Logger.Fatalf("analysis failed (%v);\ntry pre-building and then running `fossa`", err)
}

log.Logger.Debugf("found (%s) deduped dependencies", len(mod.Build.RawDependencies))
log.Logger.Debugf("found (%s) deduped dependencies", len(module.Build.RawDependencies))

dat, _ := json.Marshal(mod)
dat, _ := json.Marshal(module)
fmt.Print(string(dat))
return nil
}

0 comments on commit 0dd5ee9

Please sign in to comment.