diff --git a/application/source/commands/01_config.go b/application/source/commands/01_config.go index 15a3f89ae0c0540cdfd9e6b7a005c0dc7a4f8437..42c8c36a5000bc2a3ad7526566736a4cfd505851 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 ae411f8b7316a94369778244531a5662ff6703b1..a6fa7bc1be5cef2080742719d6fa0d16f80715a4 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 3aae1769ebdefa22679a1f0c55b0d084f43ac8b4..9b66add14946ca3a5f228994a9c7c5c947b33477 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 11229c3cb5dfeb435f2cddd31eb44abb898895bf..cda98677f57809b13644d144f42c2b5bc2a283f3 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 ac3a40b1911268369c9a2504cd396da349e49bee..f7d33d4e6a5ed6d37926c17a185d7556be828702 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 0000000000000000000000000000000000000000..b03c81805c9ab886c4cc03df3b9cc66fcbb10ba7 --- /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 0000000000000000000000000000000000000000..b03c81805c9ab886c4cc03df3b9cc66fcbb10ba7 --- /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 0000000000000000000000000000000000000000..b03c81805c9ab886c4cc03df3b9cc66fcbb10ba7 --- /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.