From 7449b0eccc74630db3b4057e57d5f2555802908d Mon Sep 17 00:00:00 2001 From: "Jip J. Dekker" Date: Sat, 19 Mar 2016 17:21:15 +0100 Subject: [PATCH] Fixes some coding mistakes, now the code compiles again --- compiler/compile.go | 12 ++++++++---- compiler/file_discovery.go | 14 +++++++------- compiler/lilypond.go | 7 ++++--- 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/compiler/compile.go b/compiler/compile.go index 9942da8..2b82ea9 100644 --- a/compiler/compile.go +++ b/compiler/compile.go @@ -15,6 +15,7 @@ package compiler import ( + "fmt" "os" "path/filepath" @@ -28,31 +29,34 @@ func CompileDir(path string, opts *settings.Settings) { // Find all scores scores, collector := generateScores() filepath.Walk(path, compilePath(path, opts, collector)) + + fmt.Println(scores) } func generateScores() ([]*settings.Score, func(string, os.FileInfo) error) { - scores := make([]*settings.Score) + var scores []*settings.Score return scores, func(path string, file os.FileInfo) error { switch filepath.Ext(path) { case ".ly": log.WithFields(log.Fields{"path": path}).Info("adding lilypond file") - append(scores, &settings.Score{Path: path}) + scores = append(scores, &settings.Score{Path: path}) case ".json": if filepath.Base(path) != "ponder.json" { log.WithFields(log.Fields{"path": path}).Info("adding json file") - if score, err := fromJSON(path); err != nil { + if score, err := settings.FromJSON(path); err != nil { log.WithFields(log.Fields{ "error": err, "path": path, }).Warning("unable to parse score settings, skipping...") } else { - append(scores, score) + scores = append(scores, score) } } default: log.WithFields(log.Fields{"path": path}).Debug("ignoring file") } + return nil } } diff --git a/compiler/file_discovery.go b/compiler/file_discovery.go index 4666eb5..3ffee43 100644 --- a/compiler/file_discovery.go +++ b/compiler/file_discovery.go @@ -27,11 +27,11 @@ import ( // of the ignored directories func compilePath(root string, opts *settings.Settings, f func(string, os.FileInfo) error) filepath.WalkFunc { - return func(path string, info os.FileInfo, err error) error { + return func(path string, info os.FileInfo, walkError error) error { // Handle walking error - if err != nil { - log.withFields(log.Fields{ - "error": err, + if walkError != nil { + log.WithFields(log.Fields{ + "error": walkError, "path": path, }).Warning("error occurred transversing project path") return nil @@ -39,9 +39,9 @@ func compilePath(root string, opts *settings.Settings, if info.IsDir() { // Skip directories that are ignored - relPath, err = filepath.Rel(root, path) + relPath, err := filepath.Rel(root, path) helpers.Check(err, "Unable to create relative Path") - for dir := range append(append(opts.IgnoreDirs, opts.LilypondIncludes), []string{opts.OutputDir}) { + for _, dir := range append(append(opts.IgnoreDirs, opts.LilypondIncludes...), opts.OutputDir) { if relPath == dir || (filepath.IsAbs(dir) && path == dir) { log.WithFields(log.Fields{"path": path}).Info("Ignoring directory") return filepath.SkipDir @@ -49,7 +49,7 @@ func compilePath(root string, opts *settings.Settings, } } else { // Call function on non-directory - err = f(path, info) + err := f(path, info) if err != nil { log.WithFields(log.Fields{ "error": err, diff --git a/compiler/lilypond.go b/compiler/lilypond.go index 29284da..bfb2bf6 100644 --- a/compiler/lilypond.go +++ b/compiler/lilypond.go @@ -31,7 +31,7 @@ var ( // compilation function using the given settings func PrepareLilypond(opts *settings.Settings) { // Adds all includes to the lilypond arguments - for dir := range opts.LilypondIncludes { + for _, dir := range opts.LilypondIncludes { lilypondArgs = append(lilypondArgs, "--include=\""+dir+"\"") } lilypondArgs = append(lilypondArgs, "--loglevel=ERROR") @@ -40,7 +40,7 @@ func PrepareLilypond(opts *settings.Settings) { // TODO: Make this an absolute path. lilypondArgs = append(lilypondArgs, "--output=\""+opts.OutputDir+"\"") if !helpers.Exists(opts.OutputDir) { - err := os.MkdirAll(path, os.ModePerm) + err := os.MkdirAll(opts.OutputDir, os.ModePerm) helpers.Check(err, "Could not create output directory") } } @@ -49,5 +49,6 @@ func PrepareLilypond(opts *settings.Settings) { // using the arguments prepared by the PrepareLilypond function func Lilypond(path string) (string, error) { cmd := exec.Command(lilypondCmd, append(lilypondArgs, path)...) - return cmd.CombinedOutput() + out, err := cmd.CombinedOutput() + return string(out), err }