From f14c51608a0848266dfd214443524be72877d421 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Vic=20Sh=C3=B3stak?= <vic@shostak.dev>
Date: Tue, 19 Oct 2021 10:43:04 +0300
Subject: [PATCH] Add colors for Windows; Add minor code fixes; Add go-critic

---
 .github/stale.yml        |  4 ++--
 Makefile                 | 19 +++++++++++--------
 README.md                |  2 +-
 cmd/create.go            | 11 ++++++-----
 go.mod                   |  2 +-
 pkg/cgapp/files.go       |  2 +-
 pkg/cgapp/git.go         |  2 +-
 pkg/cgapp/utils.go       | 21 +++++++++++++--------
 pkg/registry/defaults.go |  2 +-
 9 files changed, 37 insertions(+), 28 deletions(-)

diff --git a/.github/stale.yml b/.github/stale.yml
index d4cf99f..414f1c3 100644
--- a/.github/stale.yml
+++ b/.github/stale.yml
@@ -1,5 +1,5 @@
 # Number of days of inactivity before an issue becomes stale
-daysUntilStale: 15
+daysUntilStale: 10
 
 # Number of days of inactivity before a stale issue is closed
 daysUntilClose: 3
@@ -14,7 +14,7 @@ staleLabel: wontfix
 
 # Comment to post when marking an issue as stale. Set to `false` to disable
 markComment: >
-  👋 Hello. Is this still relevant? If so, what is blocking it? Is there 
+  👋  Hello. Is this still relevant? If so, what is blocking it? Is there 
   anything you can do to help move it forward? 
 
   > This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. 
diff --git a/Makefile b/Makefile
index bbec44c..88e05bb 100644
--- a/Makefile
+++ b/Makefile
@@ -1,25 +1,28 @@
-.PHONY: clean test security install build release
+.PHONY: clean lint security critic test install build release
 
 clean:
 	rm -rf ./tmp coverage.out
 
-test: clean
-	go test -coverprofile=coverage.out ./...
-	go tool cover -func=coverage.out
-
 lint:
 	golangci-lint run
 
 security:
 	gosec -quiet ./...
 
-install: security lint test
+critic:
+	gocritic check ./...
+
+test: clean lint security critic
+	go test -coverprofile=coverage.out ./...
+	go tool cover -func=coverage.out
+
+install: test
 	CGO_ENABLED=0 go build -ldflags="-s -w" -o $(GOPATH)/bin/cgapp ./cmd/cgapp/main.go
 
-build: security test
+build: test
 	goreleaser --snapshot --skip-publish --rm-dist
 
-release: security test
+release: test
 	git tag -a $(VERSION) -m "$(VERSION)"
 	goreleaser --snapshot --skip-publish --rm-dist
 
diff --git a/README.md b/README.md
index cd122ab..aee9799 100644
--- a/README.md
+++ b/README.md
@@ -4,7 +4,7 @@
 </h1>
 <p align="center">Create a new production-ready project with <b>backend</b> (Golang), <b>frontend</b> (JavaScript, TypeScript)<br/>and <b>deploy automation</b> (Ansible, Docker) by running one CLI command.<br/><br/>Focus on <b>writing</b> code and <b>thinking</b> of business-logic! The CLI will take care of the rest.</p>
 
-<p align="center"><a href="https://github.com/create-go-app/cli/releases" target="_blank"><img src="https://img.shields.io/badge/version-v3.1.2-blue?style=for-the-badge&logo=none" alt="cli version" /></a>&nbsp;<a href="https://pkg.go.dev/github.com/create-go-app/cli/v3?tab=doc" target="_blank"><img src="https://img.shields.io/badge/Go-1.17+-00ADD8?style=for-the-badge&logo=go" alt="go version" /></a>&nbsp;<a href="https://gocover.io/github.com/create-go-app/cli/pkg/cgapp" target="_blank"><img src="https://img.shields.io/badge/Go_Cover-89.2%25-success?style=for-the-badge&logo=none" alt="go cover" /></a>&nbsp;<a href="https://goreportcard.com/report/github.com/create-go-app/cli" target="_blank"><img src="https://img.shields.io/badge/Go_report-A+-success?style=for-the-badge&logo=none" alt="go report" /></a>&nbsp;<img src="https://img.shields.io/badge/license-apache_2.0-red?style=for-the-badge&logo=none" alt="license" /></p>
+<p align="center"><a href="https://github.com/create-go-app/cli/releases" target="_blank"><img src="https://img.shields.io/badge/version-v3.2.0-blue?style=for-the-badge&logo=none" alt="cli version" /></a>&nbsp;<a href="https://pkg.go.dev/github.com/create-go-app/cli/v3?tab=doc" target="_blank"><img src="https://img.shields.io/badge/Go-1.17+-00ADD8?style=for-the-badge&logo=go" alt="go version" /></a>&nbsp;<a href="https://gocover.io/github.com/create-go-app/cli/pkg/cgapp" target="_blank"><img src="https://img.shields.io/badge/Go_Cover-89.2%25-success?style=for-the-badge&logo=none" alt="go cover" /></a>&nbsp;<a href="https://goreportcard.com/report/github.com/create-go-app/cli" target="_blank"><img src="https://img.shields.io/badge/Go_report-A+-success?style=for-the-badge&logo=none" alt="go report" /></a>&nbsp;<img src="https://img.shields.io/badge/license-apache_2.0-red?style=for-the-badge&logo=none" alt="license" /></p>
 
 ## ⚡️ Quick start
 
diff --git a/cmd/create.go b/cmd/create.go
index 79c2a9d..837ea87 100644
--- a/cmd/create.go
+++ b/cmd/create.go
@@ -73,7 +73,7 @@ func runCreateCmd(cmd *cobra.Command, args []string) error {
 		// Define variables for better display.
 		backend = fmt.Sprintf(
 			"github.com/create-go-app/%v-go-template",
-			strings.Replace(createAnswers.Backend, "/", "_", -1),
+			strings.ReplaceAll(createAnswers.Backend, "/", "_"),
 		)
 		frontend = createAnswers.Frontend
 		proxy = createAnswers.Proxy
@@ -208,11 +208,12 @@ func runCreateCmd(cmd *cobra.Command, args []string) error {
 	*/
 
 	// Set unused proxy roles.
-	if proxy == "traefik" || proxy == "traefik-acme-dns" {
+	switch proxy {
+	case "traefik", "traefik-acme-dns":
 		proxyList = []string{"nginx"}
-	} else if proxy == "nginx" {
-		proxyList = []string{"traefik"}
-	} else {
+	case "nginx":
+		proxyList = []string{"nginx"}
+	default:
 		proxyList = []string{"traefik", "nginx"}
 	}
 
diff --git a/go.mod b/go.mod
index c4730c5..3d811c2 100644
--- a/go.mod
+++ b/go.mod
@@ -5,6 +5,7 @@ go 1.17
 require (
 	github.com/AlecAivazis/survey/v2 v2.3.2
 	github.com/go-git/go-git/v5 v5.4.2
+	github.com/mattn/go-colorable v0.1.11
 	github.com/spf13/cobra v1.2.1
 )
 
@@ -20,7 +21,6 @@ require (
 	github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
 	github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
 	github.com/kevinburke/ssh_config v1.1.0 // indirect
-	github.com/mattn/go-colorable v0.1.11 // indirect
 	github.com/mattn/go-isatty v0.0.14 // indirect
 	github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect
 	github.com/mitchellh/go-homedir v1.1.0 // indirect
diff --git a/pkg/cgapp/files.go b/pkg/cgapp/files.go
index f366a41..ab07bd4 100644
--- a/pkg/cgapp/files.go
+++ b/pkg/cgapp/files.go
@@ -89,7 +89,7 @@ func GenerateFileFromTemplate(fileName string, variables map[string]interface{})
 	_ = file.Close()
 
 	// Rename output file.
-	newFileName := strings.Replace(fileName, ".tmpl", "", -1)
+	newFileName := strings.ReplaceAll(fileName, ".tmpl", "")
 	if errRename := os.Rename(fileName, newFileName); errRename != nil {
 		return ShowError(errRename.Error())
 	}
diff --git a/pkg/cgapp/git.go b/pkg/cgapp/git.go
index 91fa3e8..9db79d7 100644
--- a/pkg/cgapp/git.go
+++ b/pkg/cgapp/git.go
@@ -30,7 +30,7 @@ func GitClone(templateType, templateURL string) error {
 		folder,
 		false,
 		&git.CloneOptions{
-			URL: "https://" + templateURL,
+			URL: fmt.Sprintf("https://%s", templateURL),
 		},
 	)
 	if errPlainClone != nil {
diff --git a/pkg/cgapp/utils.go b/pkg/cgapp/utils.go
index 4ca5d75..ba08284 100644
--- a/pkg/cgapp/utils.go
+++ b/pkg/cgapp/utils.go
@@ -12,10 +12,11 @@ import (
 )
 
 var (
-	Stdout = colorable.NewColorableStdout()
-	Stderr = colorable.NewColorableStderr()
+	Stdout = colorable.NewColorableStdout() // add a colorable std out
+	Stderr = colorable.NewColorableStderr() // add a colorable std err
 )
 
+// ShowMessage function for showing output messages.
 func ShowMessage(level, text string, startWithNewLine, endWithNewLine bool) {
 	// Define variables.
 	var startLine, endLine string
@@ -28,12 +29,16 @@ func ShowMessage(level, text string, startWithNewLine, endWithNewLine bool) {
 		endLine = "\n" // set a new line
 	}
 
-	fmt.Fprintln(Stdout, startLine+colorizeLevel(level)+text+endLine)
+	// Formatting message.
+	message := fmt.Sprintf("%s %s %s %s", startLine, colorizeLevel(level), text, endLine)
+
+	// Return output.
+	fmt.Fprintln(Stdout, message)
 }
 
 // ShowError function for send error message to output.
 func ShowError(text string) error {
-	return fmt.Errorf("%s", colorizeLevel("error")+text)
+	return fmt.Errorf("%s%s", colorizeLevel("error"), text)
 }
 
 // CalculateDurationTime func to calculate duration time.
@@ -56,17 +61,17 @@ func colorizeLevel(level string) string {
 	switch level {
 	case "success":
 		color = green
-		icon = "[OK] "
+		icon = "[OK]"
 	case "error":
 		color = red
-		icon = "[ERROR] "
+		icon = "[ERROR]"
 	case "info":
 		color = yellow
-		icon = "[INFO] "
+		icon = "[INFO]"
 	default:
 		color = noColor
 	}
 
 	// Send common or colored caption.
-	return color + icon + noColor
+	return fmt.Sprintf("%s%s%s", color, icon, noColor)
 }
diff --git a/pkg/registry/defaults.go b/pkg/registry/defaults.go
index e1ce083..d47eccb 100644
--- a/pkg/registry/defaults.go
+++ b/pkg/registry/defaults.go
@@ -11,7 +11,7 @@ import (
 )
 
 // CLIVersion version of Create Go App CLI.
-const CLIVersion string = "3.1.2"
+const CLIVersion string = "3.2.0"
 
 // Variables struct for Ansible variables (inventory, hosts).
 type Variables struct {