From d38ef88c9ca42a051bebbc8e7227d2d270bffca4 Mon Sep 17 00:00:00 2001 From: "Jip J. Dekker" Date: Tue, 19 Apr 2016 11:55:27 +0200 Subject: [PATCH] Adds setting and flag to keep generated LaTeX book template --- cmd/book.go | 5 +++++ compiler/book.go | 4 +++- settings/settings.go | 1 + 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/cmd/book.go b/cmd/book.go index 6616768..0f0af32 100644 --- a/cmd/book.go +++ b/cmd/book.go @@ -19,6 +19,8 @@ import ( "github.com/spf13/cobra" ) +var keepTemplate bool + // bookCmd represents the book command var bookCmd = &cobra.Command{ Use: "book", @@ -26,10 +28,13 @@ var bookCmd = &cobra.Command{ Long: ``, Run: func(cmd *cobra.Command, args []string) { path, opts := getSettings() + opts.KeepBookTemplate = opts.KeepBookTemplate || keepTemplate compiler.MakeBook(path, opts) }, } func init() { + bookCmd.Flags().BoolVarP(&keepTemplate, "keep-template", + "k", false, "Leave the LaTeX source for the book in the output directory") RootCmd.AddCommand(bookCmd) } diff --git a/compiler/book.go b/compiler/book.go index 6a5cdbc..3f065d7 100644 --- a/compiler/book.go +++ b/compiler/book.go @@ -70,7 +70,9 @@ func MakeBook(path string, opts *settings.Settings) { "error": err, }).Error("failed to clean songbook latex files") } - err = os.Remove(texPath) + if !opts.KeepBookTemplate { + err = os.Remove(texPath) + } helpers.Check(err, "could not remove songbook latex template") } diff --git a/settings/settings.go b/settings/settings.go index 3bb0461..49f0a0a 100644 --- a/settings/settings.go +++ b/settings/settings.go @@ -36,6 +36,7 @@ type Settings struct { BookTitleTempl string // Override for the partial book template creating the title page BookCategoryTempl string // Override for the partial book template creating category pages BookScoreTempl string // Override for the partial book template placing scores + KeepBookTemplate bool // Leave the LaTeX source for the book in the output directory } // FromFile reads a settings file in json format and returns the Settings struct