Fixes some coding mistakes, now the code compiles again
This commit is contained in:
parent
0f1d0771ee
commit
7449b0eccc
@ -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
|
||||
}
|
||||
}
|
||||
|
@ -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,
|
||||
|
@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user