template / commit
adding template init
.goreleaser.yaml | 2 +- .vscode/launch.json | 10 ++++++++++ Makefile | 2 +- main.go | 26 ++++++++++++++++++++++++++ 4 files changed, 38 insertions(+), 2 deletions(-) diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 8941f3a..e246608 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -89,4 +89,4 @@ brews: # Could be used to do any additional work after the "install" script # Default is empty. post_install: | - system "#{bin}/template reset" + system "#{bin}/template init" diff --git a/.vscode/launch.json b/.vscode/launch.json index 9252761..6139813 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -30,6 +30,16 @@ "reset", ] }, + { + "name": "Run: template init", + "type": "go", + "request": "launch", + "mode": "auto", + "program": ".", + "args": [ + "init", + ] + }, { "name": "Run: template list", "type": "go", diff --git a/Makefile b/Makefile index fb95975..f5525ce 100644 --- a/Makefile +++ b/Makefile @@ -39,7 +39,7 @@ test_coverage_html: test_coverage install: build test lint go install ${LDFLAGS} - template reset + template init uninstall: go clean -i gitlab.com/PavelSafronov/template... diff --git a/main.go b/main.go index 2a4217a..57b87ca 100644 --- a/main.go +++ b/main.go @@ -290,6 +290,32 @@ func main() { return nil }, }, + { + Name: "init", + Usage: "if global template config is not present, initializes the global template config with default profiles", + Action: func(c *cli.Context) error { + usr, err := user.Current() + if err != nil { + log.Fatal(err) + } + fullConfigPath := getFullPath(argumentValues.configFilePath, *usr) + + _, err = os.Stat(fullConfigPath) + if err == nil { + fmt.Printf("Config file already exists at '%v', skipping init\n", fullConfigPath) + fmt.Println() + return nil + } + + fmt.Printf("Setting config at '%v' to default\n", fullConfigPath) + err = saveConfig(fullConfigPath, defaultConfig()) + if err != nil { + return fmt.Errorf("error saving default config: %v", err) + } + fmt.Println() + return nil + }, + }, { Name: "reset", Usage: "reset the global template config to default profiles",