From a7e1a28f7765e237a4a76c69e8de83fb5a55dab6 Mon Sep 17 00:00:00 2001 From: Volker Schukai <volker.schukai@schukai.com> Date: Wed, 6 Jul 2022 19:53:21 +0200 Subject: [PATCH] chore: commit save point --- application/source/commands/01_config.go | 5 +++-- application/source/commands/01_state.go | 15 ++++++++++++- application/source/commands/08_document.go | 7 +++++-- .../source/commands/08_document_add.go | 10 +++++++++ development/examples/example1/config.yaml | 1 + development/examples/example2/newdoc1.md | 21 +++++++++++++++++++ development/examples/example2/newdoc3.md | 21 +++++++++++++++++++ development/examples/example2/newdow2.md | 21 +++++++++++++++++++ 8 files changed, 96 insertions(+), 5 deletions(-) create mode 100644 development/examples/example2/newdoc1.md create mode 100644 development/examples/example2/newdoc3.md create mode 100644 development/examples/example2/newdow2.md diff --git a/application/source/commands/01_config.go b/application/source/commands/01_config.go index 15a3f89..42c8c36 100644 --- a/application/source/commands/01_config.go +++ b/application/source/commands/01_config.go @@ -12,8 +12,9 @@ const configName = "config.yaml" type Configuration struct { Document struct { - Path string `yaml:"Path" envconfig:"PATH"` - Template string `yaml:"Template" envconfig:"TEMPLATE"` + Path string `yaml:"Path" envconfig:"PATH"` + Template string `yaml:"Template" envconfig:"TEMPLATE"` + DateFormat string `yaml:"DateFormat" envconfig:"DATE_FORMAT"` } `yaml:"Document"` } diff --git a/application/source/commands/01_state.go b/application/source/commands/01_state.go index ae411f8..a6fa7bc 100644 --- a/application/source/commands/01_state.go +++ b/application/source/commands/01_state.go @@ -54,6 +54,19 @@ func (e *stateStruct) setCode(code int) *stateStruct { return e } +func (e *stateStruct) getDateFormat() string { + if e.definition.Document.DateFormat != "" { + return e.definition.Document.DateFormat + } + + if e.configuration.Document.DateFormat != "" { + return e.configuration.Document.DateFormat + } + + return "2006-01-02" + +} + func (e *stateStruct) getDocumentPath() string { if e.definition.Document.Path != "" { return e.definition.Document.Path @@ -100,7 +113,7 @@ func (e *stateStruct) getDocumentTemplate() string { return t } - return newDocumentTemplate + return "" } diff --git a/application/source/commands/08_document.go b/application/source/commands/08_document.go index 3aae176..9b66add 100644 --- a/application/source/commands/08_document.go +++ b/application/source/commands/08_document.go @@ -16,8 +16,9 @@ func init() { } type DocumentDefinition struct { - Path string `long:"path" short:"p"` - Add DocumentAddDefinition `command:"add" alias:"a"` + Path string `long:"path" short:"p"` + DateFormat string `long:"date-format" short:"d"` + Add DocumentAddDefinition `command:"add" alias:"a"` } func initDocument(command *flags.Command) { @@ -29,6 +30,8 @@ func initDocument(command *flags.Command) { switch opt.LongName { case "path": opt.Description = translations.T.Sprintf("base directory in which the documents are saved") + case "date-format": + opt.Description = translations.T.Sprintf("date format for the creation date") } } diff --git a/application/source/commands/08_document_add.go b/application/source/commands/08_document_add.go index 11229c3..cda9867 100644 --- a/application/source/commands/08_document_add.go +++ b/application/source/commands/08_document_add.go @@ -6,6 +6,8 @@ import ( "os" "path" "path/filepath" + "strings" + "time" ) const documentAddSymbol = "document-add" @@ -87,6 +89,14 @@ func createNewDocument(name string) { } template := state.getDocumentTemplate() + + if template == "" { + template = newDocumentTemplate + } + + date := time.Now().Format(state.getDateFormat()) + template = strings.Replace(template, "%%CREATED%%", date, -1) + err := os.WriteFile(path, []byte(template), 0644) CheckError(err) diff --git a/development/examples/example1/config.yaml b/development/examples/example1/config.yaml index ac3a40b..f7d33d4 100644 --- a/development/examples/example1/config.yaml +++ b/development/examples/example1/config.yaml @@ -1,2 +1,3 @@ Document: Path: /home/volker.schukai/projekte/gitlab/oss/utilities/documentation-manager/development/examples/example2 + DateFormat: 02.01.2006 diff --git a/development/examples/example2/newdoc1.md b/development/examples/example2/newdoc1.md new file mode 100644 index 0000000..b03c818 --- /dev/null +++ b/development/examples/example2/newdoc1.md @@ -0,0 +1,21 @@ + +--- +# Document title +Title: New Document + +# keywords mainly used for searching +Keywords: + - documentation + +# First and last name of the authors as a list +Author: + - null + +Created: 06.07.2022 +Last Update: 06.07.2022 + +... + +## {{ .Title }} + +Lorem ipsum dolor sit amet, consectetur adipiscing elit. diff --git a/development/examples/example2/newdoc3.md b/development/examples/example2/newdoc3.md new file mode 100644 index 0000000..b03c818 --- /dev/null +++ b/development/examples/example2/newdoc3.md @@ -0,0 +1,21 @@ + +--- +# Document title +Title: New Document + +# keywords mainly used for searching +Keywords: + - documentation + +# First and last name of the authors as a list +Author: + - null + +Created: 06.07.2022 +Last Update: 06.07.2022 + +... + +## {{ .Title }} + +Lorem ipsum dolor sit amet, consectetur adipiscing elit. diff --git a/development/examples/example2/newdow2.md b/development/examples/example2/newdow2.md new file mode 100644 index 0000000..b03c818 --- /dev/null +++ b/development/examples/example2/newdow2.md @@ -0,0 +1,21 @@ + +--- +# Document title +Title: New Document + +# keywords mainly used for searching +Keywords: + - documentation + +# First and last name of the authors as a list +Author: + - null + +Created: 06.07.2022 +Last Update: 06.07.2022 + +... + +## {{ .Title }} + +Lorem ipsum dolor sit amet, consectetur adipiscing elit. -- GitLab