Fixes some coding mistakes, now the code compiles again
This commit is contained in:
parent
0f1d0771ee
commit
7449b0eccc
@ -15,6 +15,7 @@
|
|||||||
package compiler
|
package compiler
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
@ -28,31 +29,34 @@ func CompileDir(path string, opts *settings.Settings) {
|
|||||||
// Find all scores
|
// Find all scores
|
||||||
scores, collector := generateScores()
|
scores, collector := generateScores()
|
||||||
filepath.Walk(path, compilePath(path, opts, collector))
|
filepath.Walk(path, compilePath(path, opts, collector))
|
||||||
|
|
||||||
|
fmt.Println(scores)
|
||||||
}
|
}
|
||||||
|
|
||||||
func generateScores() ([]*settings.Score, func(string, os.FileInfo) error) {
|
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 {
|
return scores, func(path string, file os.FileInfo) error {
|
||||||
switch filepath.Ext(path) {
|
switch filepath.Ext(path) {
|
||||||
case ".ly":
|
case ".ly":
|
||||||
log.WithFields(log.Fields{"path": path}).Info("adding lilypond file")
|
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":
|
case ".json":
|
||||||
if filepath.Base(path) != "ponder.json" {
|
if filepath.Base(path) != "ponder.json" {
|
||||||
log.WithFields(log.Fields{"path": path}).Info("adding json file")
|
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{
|
log.WithFields(log.Fields{
|
||||||
"error": err,
|
"error": err,
|
||||||
"path": path,
|
"path": path,
|
||||||
}).Warning("unable to parse score settings, skipping...")
|
}).Warning("unable to parse score settings, skipping...")
|
||||||
} else {
|
} else {
|
||||||
append(scores, score)
|
scores = append(scores, score)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
log.WithFields(log.Fields{"path": path}).Debug("ignoring file")
|
log.WithFields(log.Fields{"path": path}).Debug("ignoring file")
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,11 +27,11 @@ import (
|
|||||||
// of the ignored directories
|
// of the ignored directories
|
||||||
func compilePath(root string, opts *settings.Settings,
|
func compilePath(root string, opts *settings.Settings,
|
||||||
f func(string, os.FileInfo) error) filepath.WalkFunc {
|
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
|
// Handle walking error
|
||||||
if err != nil {
|
if walkError != nil {
|
||||||
log.withFields(log.Fields{
|
log.WithFields(log.Fields{
|
||||||
"error": err,
|
"error": walkError,
|
||||||
"path": path,
|
"path": path,
|
||||||
}).Warning("error occurred transversing project path")
|
}).Warning("error occurred transversing project path")
|
||||||
return nil
|
return nil
|
||||||
@ -39,9 +39,9 @@ func compilePath(root string, opts *settings.Settings,
|
|||||||
|
|
||||||
if info.IsDir() {
|
if info.IsDir() {
|
||||||
// Skip directories that are ignored
|
// 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")
|
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) {
|
if relPath == dir || (filepath.IsAbs(dir) && path == dir) {
|
||||||
log.WithFields(log.Fields{"path": path}).Info("Ignoring directory")
|
log.WithFields(log.Fields{"path": path}).Info("Ignoring directory")
|
||||||
return filepath.SkipDir
|
return filepath.SkipDir
|
||||||
@ -49,7 +49,7 @@ func compilePath(root string, opts *settings.Settings,
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Call function on non-directory
|
// Call function on non-directory
|
||||||
err = f(path, info)
|
err := f(path, info)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.WithFields(log.Fields{
|
log.WithFields(log.Fields{
|
||||||
"error": err,
|
"error": err,
|
||||||
|
@ -31,7 +31,7 @@ var (
|
|||||||
// compilation function using the given settings
|
// compilation function using the given settings
|
||||||
func PrepareLilypond(opts *settings.Settings) {
|
func PrepareLilypond(opts *settings.Settings) {
|
||||||
// Adds all includes to the lilypond arguments
|
// 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, "--include=\""+dir+"\"")
|
||||||
}
|
}
|
||||||
lilypondArgs = append(lilypondArgs, "--loglevel=ERROR")
|
lilypondArgs = append(lilypondArgs, "--loglevel=ERROR")
|
||||||
@ -40,7 +40,7 @@ func PrepareLilypond(opts *settings.Settings) {
|
|||||||
// TODO: Make this an absolute path.
|
// TODO: Make this an absolute path.
|
||||||
lilypondArgs = append(lilypondArgs, "--output=\""+opts.OutputDir+"\"")
|
lilypondArgs = append(lilypondArgs, "--output=\""+opts.OutputDir+"\"")
|
||||||
if !helpers.Exists(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")
|
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
|
// using the arguments prepared by the PrepareLilypond function
|
||||||
func Lilypond(path string) (string, error) {
|
func Lilypond(path string) (string, error) {
|
||||||
cmd := exec.Command(lilypondCmd, append(lilypondArgs, path)...)
|
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