Skip to content

Commit

Permalink
Add colors for Windows; Add minor code fixes; Add go-critic
Browse files Browse the repository at this point in the history
  • Loading branch information
koddr committed Oct 19, 2021
1 parent dd12085 commit f14c516
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 28 deletions.
4 changes: 2 additions & 2 deletions .github/stale.yml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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.
Expand Down
19 changes: 11 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
11 changes: 6 additions & 5 deletions cmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"}
}

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkg/cgapp/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/cgapp/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
21 changes: 13 additions & 8 deletions pkg/cgapp/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand All @@ -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)
}
2 changes: 1 addition & 1 deletion pkg/registry/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit f14c516

Please sign in to comment.