From e9c72213d0e74cb777f14ab204bdc2a12c9f4f4b Mon Sep 17 00:00:00 2001 From: "Jip J. Dekker" Date: Sun, 20 Mar 2016 16:22:48 +0100 Subject: [PATCH] Split finding and parsing of the settings file off into a function --- cmd/compile.go | 10 +--------- cmd/root.go | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/cmd/compile.go b/cmd/compile.go index 1abcfd0..095f48b 100644 --- a/cmd/compile.go +++ b/cmd/compile.go @@ -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) diff --git a/cmd/root.go b/cmd/root.go index 2256ef5..0fa6f4c 100644 --- a/cmd/root.go +++ b/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 +}