Split finding and parsing of the settings file off into a function
This commit is contained in:
parent
6bddbd2470
commit
e9c72213d0
@ -15,11 +15,7 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
|
||||
"github.com/jjdekker/ponder/compiler"
|
||||
"github.com/jjdekker/ponder/helpers"
|
||||
"github.com/jjdekker/ponder/settings"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
@ -32,11 +28,7 @@ lilypond files in accordance to ponder settings file.
|
||||
Files that have already been compiled will be skipped,
|
||||
unless the lilypond file has been edited.`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
// Find and Unmarshal the settings file
|
||||
path, err := helpers.FindFileDir(settingsFile)
|
||||
helpers.Check(err, "unable to find library directory")
|
||||
opts, err := settings.FromFile(filepath.Join(path, settingsFile))
|
||||
helpers.Check(err, "unable to parse settings file")
|
||||
path, opts := getSettings()
|
||||
|
||||
// Compile files
|
||||
compiler.CompileDir(path, opts)
|
||||
|
15
cmd/root.go
15
cmd/root.go
@ -16,8 +16,11 @@ package cmd
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
log "github.com/Sirupsen/logrus"
|
||||
"github.com/jjdekker/ponder/helpers"
|
||||
"github.com/jjdekker/ponder/settings"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
@ -63,3 +66,15 @@ func setLogLevel() {
|
||||
log.SetLevel(log.WarnLevel)
|
||||
}
|
||||
}
|
||||
|
||||
// getSettings return the directory in which the settings file was
|
||||
// found and the parsed settings content
|
||||
func getSettings() (string, *settings.Settings) {
|
||||
// Find and Unmarshal the settings file
|
||||
path, err := helpers.FindFileDir(settingsFile)
|
||||
helpers.Check(err, "unable to find library directory")
|
||||
opts, err := settings.FromFile(filepath.Join(path, settingsFile))
|
||||
helpers.Check(err, "unable to parse settings file")
|
||||
|
||||
return path, opts
|
||||
}
|
||||
|
Reference in New Issue
Block a user