From 2b68a7556ea700e1952beafa07357a7e4e60a606 Mon Sep 17 00:00:00 2001
From: Volker Schukai <volker.schukai@schukai.com>
Date: Sun, 17 Jul 2022 16:48:04 +0200
Subject: [PATCH] chore: commit save point

---
 application/source/commands/08_document_pdf.go |  2 +-
 application/source/document/pandoc.go          |  4 ++++
 application/source/document/pdf.go             | 15 +++++++++++----
 application/source/environment/template.go     | 10 +++++++++-
 release.json                                   |  2 +-
 5 files changed, 26 insertions(+), 7 deletions(-)

diff --git a/application/source/commands/08_document_pdf.go b/application/source/commands/08_document_pdf.go
index 39efe16..fa7ab67 100644
--- a/application/source/commands/08_document_pdf.go
+++ b/application/source/commands/08_document_pdf.go
@@ -37,7 +37,7 @@ func initDocumentPDF(command *flags.Command) {
 		case "template":
 			opt.Description = translations.T.Sprintf("template for the new document")
 		case "output":
-			opt.Description = translations.T.Sprintf("directory in which the finished documentation is to be written")
+			opt.Description = translations.T.Sprintf("filename for the new document")
 		case "format":
 			opt.Description = translations.T.Sprintf("format of the finished documentation")
 		case "verbose":
diff --git a/application/source/document/pandoc.go b/application/source/document/pandoc.go
index 3f933d4..9574352 100644
--- a/application/source/document/pandoc.go
+++ b/application/source/document/pandoc.go
@@ -87,6 +87,10 @@ func runPandoc(source string, outputName string, latexPath string, luaFilter str
 	arguments += "--toc "
 	arguments += "--output=" + outputName + " "
 
+	if verbose {
+		fmt.Println(arguments)
+	}
+
 	cmd := exec.Command("bash", "-c", arguments)
 	log, err := cmd.Output()
 
diff --git a/application/source/document/pdf.go b/application/source/document/pdf.go
index 63a53ed..eaf58d2 100644
--- a/application/source/document/pdf.go
+++ b/application/source/document/pdf.go
@@ -87,6 +87,17 @@ func BuildPDF(env BuildPdfEnvironment) error {
 		environment.ExitWithError(2, "if the type is pdf, the output option must be specified")
 	}
 
+	fileInfo, err := os.Stat(output)
+	if err != nil {
+		if !os.IsNotExist(err) {
+			environment.ExitWithError(2, "cannot stat output file", err.Error())
+		}
+	} else {
+		if fileInfo.IsDir() {
+			environment.ExitWithError(2, "output file is a directory", output)
+		}
+	}
+
 	file, err := ioutil.TempFile(os.TempDir(), environment.State.GetInfo().Mnemonic)
 	checkError(err)
 
@@ -113,10 +124,6 @@ func BuildPDF(env BuildPdfEnvironment) error {
 		}
 	}()
 
-	c, _ := os.ReadFile(file.Name())
-
-	os.WriteFile("/tmp/debug.txt", c, 0644)
-
 	runPandoc(file.Name(), output, env.Templates.Latex, luaFilter.Name(), env.Verbose)
 	return nil
 
diff --git a/application/source/environment/template.go b/application/source/environment/template.go
index 5967d6c..32260b8 100644
--- a/application/source/environment/template.go
+++ b/application/source/environment/template.go
@@ -8,8 +8,16 @@ import (
 	"strings"
 )
 
+const defaultMarkdownTemplate = `
+{{ .Documents }}
+`
+
 func ReadTemplate(argPath string) string {
 
+	if argPath == "" {
+		return defaultMarkdownTemplate
+	}
+
 	current, err := os.Getwd()
 	if err != nil {
 		ExitWithError(2, "The current directory cannot be read")
@@ -23,7 +31,7 @@ func ReadTemplate(argPath string) string {
 
 	template, err := os.ReadFile(p)
 	if err != nil {
-		ExitWithError(2, "The file %s cannot be read", p)
+		ExitWithError(2, "The template file %s cannot be read.", p)
 	}
 
 	return convertTemplateImages(string(template), path.Dir(p))
diff --git a/release.json b/release.json
index 4e38767..331eef0 100644
--- a/release.json
+++ b/release.json
@@ -1,3 +1,3 @@
 {
-  "version": "1.0.35"
+  "version": "1.0.36"
 }
\ No newline at end of file
-- 
GitLab