Archived
1
0

Split finding and parsing of the settings file off into a function

This commit is contained in:
Jip J. Dekker 2016-03-20 16:22:48 +01:00
parent 6bddbd2470
commit e9c72213d0
2 changed files with 16 additions and 9 deletions

View File

@ -15,11 +15,7 @@
package cmd package cmd
import ( import (
"path/filepath"
"github.com/jjdekker/ponder/compiler" "github.com/jjdekker/ponder/compiler"
"github.com/jjdekker/ponder/helpers"
"github.com/jjdekker/ponder/settings"
"github.com/spf13/cobra" "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, Files that have already been compiled will be skipped,
unless the lilypond file has been edited.`, unless the lilypond file has been edited.`,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
// Find and Unmarshal the settings file path, opts := getSettings()
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")
// Compile files // Compile files
compiler.CompileDir(path, opts) compiler.CompileDir(path, opts)

View File

@ -16,8 +16,11 @@ package cmd
import ( import (
"os" "os"
"path/filepath"
log "github.com/Sirupsen/logrus" log "github.com/Sirupsen/logrus"
"github.com/jjdekker/ponder/helpers"
"github.com/jjdekker/ponder/settings"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
@ -63,3 +66,15 @@ func setLogLevel() {
log.SetLevel(log.WarnLevel) 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
}