Skip to content
Snippets Groups Projects
Verified Commit a7e1a28f authored by Volker Schukai's avatar Volker Schukai :alien:
Browse files

chore: commit save point

parent 9718f34d
No related branches found
No related tags found
No related merge requests found
...@@ -12,8 +12,9 @@ const configName = "config.yaml" ...@@ -12,8 +12,9 @@ const configName = "config.yaml"
type Configuration struct { type Configuration struct {
Document struct { Document struct {
Path string `yaml:"Path" envconfig:"PATH"` Path string `yaml:"Path" envconfig:"PATH"`
Template string `yaml:"Template" envconfig:"TEMPLATE"` Template string `yaml:"Template" envconfig:"TEMPLATE"`
DateFormat string `yaml:"DateFormat" envconfig:"DATE_FORMAT"`
} `yaml:"Document"` } `yaml:"Document"`
} }
......
...@@ -54,6 +54,19 @@ func (e *stateStruct) setCode(code int) *stateStruct { ...@@ -54,6 +54,19 @@ func (e *stateStruct) setCode(code int) *stateStruct {
return e 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 { func (e *stateStruct) getDocumentPath() string {
if e.definition.Document.Path != "" { if e.definition.Document.Path != "" {
return e.definition.Document.Path return e.definition.Document.Path
...@@ -100,7 +113,7 @@ func (e *stateStruct) getDocumentTemplate() string { ...@@ -100,7 +113,7 @@ func (e *stateStruct) getDocumentTemplate() string {
return t return t
} }
return newDocumentTemplate return ""
} }
......
...@@ -16,8 +16,9 @@ func init() { ...@@ -16,8 +16,9 @@ func init() {
} }
type DocumentDefinition struct { type DocumentDefinition struct {
Path string `long:"path" short:"p"` Path string `long:"path" short:"p"`
Add DocumentAddDefinition `command:"add" alias:"a"` DateFormat string `long:"date-format" short:"d"`
Add DocumentAddDefinition `command:"add" alias:"a"`
} }
func initDocument(command *flags.Command) { func initDocument(command *flags.Command) {
...@@ -29,6 +30,8 @@ func initDocument(command *flags.Command) { ...@@ -29,6 +30,8 @@ func initDocument(command *flags.Command) {
switch opt.LongName { switch opt.LongName {
case "path": case "path":
opt.Description = translations.T.Sprintf("base directory in which the documents are saved") 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")
} }
} }
......
...@@ -6,6 +6,8 @@ import ( ...@@ -6,6 +6,8 @@ import (
"os" "os"
"path" "path"
"path/filepath" "path/filepath"
"strings"
"time"
) )
const documentAddSymbol = "document-add" const documentAddSymbol = "document-add"
...@@ -87,6 +89,14 @@ func createNewDocument(name string) { ...@@ -87,6 +89,14 @@ func createNewDocument(name string) {
} }
template := state.getDocumentTemplate() 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) err := os.WriteFile(path, []byte(template), 0644)
CheckError(err) CheckError(err)
......
Document: Document:
Path: /home/volker.schukai/projekte/gitlab/oss/utilities/documentation-manager/development/examples/example2 Path: /home/volker.schukai/projekte/gitlab/oss/utilities/documentation-manager/development/examples/example2
DateFormat: 02.01.2006
---
# 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.
---
# 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.
---
# 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.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment