From 08e2c5e5fcee0709901e1264b8260816a6d68d2e Mon Sep 17 00:00:00 2001 From: Marvin Steadfast Date: Wed, 3 Mar 2021 14:03:18 +0100 Subject: [PATCH] finally pterm based refactoring needed to drop the approach to print the quote in a terminal box. --- .drone.yml | 49 ++++++++++++++++++++++++------------- .gitignore | 1 + .goreleaser.yml | 65 +++++++++++++++++++++++++++++++++++++++++++++++++ Makefile | 20 +++++++++++++++ main.go | 32 ++++++++++++++++++------ main_test.go | 47 ----------------------------------- 6 files changed, 143 insertions(+), 71 deletions(-) create mode 100644 .goreleaser.yml delete mode 100644 main_test.go diff --git a/.drone.yml b/.drone.yml index 68b0248..e58b469 100644 --- a/.drone.yml +++ b/.drone.yml @@ -1,27 +1,42 @@ --- kind: pipeline -type: docker +name: default + steps: + - name: tags + image: alpine/git + commands: + - git fetch --tags + + - name: lint + image: golangci/golangci-lint:latest + commands: + - make lint + - name: test - image: golang:1.13 + image: golang:latest commands: - make test - - name: lint - image: golangci/golangci-lint:v1.23-alpine - commands: - - apk add --no-cache make - - make lint + - name: build - image: golang:1.13 + image: goreleaser/goreleaser:latest commands: - - go get -u github.com/mitchellh/gox - make build - - name: publish - image: plugins/github-release - settings: - api_key: - from_secret: github_token - files: - - fortlit-go_* when: - event: tag + event: + exclude: + - tag + + - name: release + image: goreleaser/goreleaser:latest + environment: + GITHUB_TOKEN: + from_secret: github_token + commands: + - goreleaser release --rm-dist --parallelism=1 + depends_on: + - submodules + - clean + when: + event: + - tag diff --git a/.gitignore b/.gitignore index 813ca47..cb52a15 100644 --- a/.gitignore +++ b/.gitignore @@ -16,3 +16,4 @@ # Own stuff dist/* +.envrc diff --git a/.goreleaser.yml b/.goreleaser.yml new file mode 100644 index 0000000..fee3902 --- /dev/null +++ b/.goreleaser.yml @@ -0,0 +1,65 @@ +--- +project_name: fortlit + +builds: + - binary: revive + env: + - CGO_ENABLED=0 + ldflags: + - "-s" + - "-w" + - "-extldflags '-static'" + - "-X gitlab.com/wobcom/iot/revive/cmd.version={{.Version}}" + - "-X gitlab.com/wobcom/iot/revive/cmd.commit={{.ShortCommit}}" + - "-X gitlab.com/wobcom/iot/revive/cmd.date={{.Date}}" + goarch: + - 386 + - amd64 + - arm + - arm64 + +archives: + - replacements: + darwin: macos + +checksum: + name_template: "checksums.txt" + +snapshot: + name_template: "{{ .Tag }}-next" + +changelog: + sort: asc + filters: + exclude: + - "^docs:" + - "^test:" + +release: + github: + owner: xsteadfastx + name: fortlit-go + +nfpms: + - formats: + - apk + - deb + - rpm + replacements: + 386: i386 + homepage: https://git.xsfx.dev/xsteadfastx/fortlit + maintainer: Marvin Preuss + +brews: + - name: fortlit + tap: + owner: xsteadfastx + name: homebrew-tap + commit_author: + name: Marvin Steadfast + email: marvin@xsteadfastx.org + homepage: https://git.xsfx.dev/xsteadfastx/fortlit + install: | + bin.install "fortlit" + test: | + system "#{bin}/fortlit -version" diff --git a/Makefile b/Makefile index 8340c06..9830620 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,23 @@ .PHONY: generate generate: go generate -v + +.PHONY: build +build: + goreleaser build --rm-dist --snapshot + +.PHONY: release +release: + goreleaser release --rm-dist --snapshot --skip-publish + +.PHONY: test +test: + GOFLAGS=-mod=vendor go test -race -cover -v ./... + +.PHONY: lint +lint: + golangci-lint run --enable-all --disable gomnd --disable godox --disable exhaustivestruct --timeout 5m + +.PHONY: clean +clean: + rm -rf dist/ diff --git a/main.go b/main.go index bb565ad..c62137b 100644 --- a/main.go +++ b/main.go @@ -1,7 +1,8 @@ -// nolint: exhaustivestruct, gochecknoglobals, gomnd +// nolint: exhaustivestruct, gochecknoglobals, gomnd, forbidigo package main import ( + "flag" "fmt" "math/rand" "regexp" @@ -15,7 +16,15 @@ import ( //go:generate go run tools/gen/gen.go //go:generate gofumpt -w quotes/quotes.go -const lineWords = 8 +var flagVersion bool + +var ( + version = "dev" + commit = "none" + date = "unknown" +) + +const lineWords = 10 var ( ColorAuthor = pterm.NewRGB(189, 147, 249) @@ -57,6 +66,15 @@ func stringWrap(text string, limit int) string { } func main() { + flag.BoolVar(&flagVersion, "version", false, "version") + flag.Parse() + + if flagVersion { + fmt.Printf("revive %s, commit %s, %s", version, commit, date) + + return + } + now := time.Now() t := fmt.Sprintf("%02d:%02d", now.Hour(), now.Minute()) q := getQuote(quotes.FortData, t) @@ -68,10 +86,10 @@ func main() { m := regexp.MustCompile(fmt.Sprintf("(?i)(%s)", q.Time)) text := m.ReplaceAllString(q.Text, ColorTime.Sprint("$1")) - pterm.DefaultCenter.Println( - pterm.DefaultBox.Sprint( - stringWrap(text, lineWords), - ), - ) + wrapText := stringWrap(text, lineWords) + + fmt.Print("\n\n") + + pterm.DefaultCenter.Println(wrapText) pterm.DefaultCenter.Println(fmt.Sprintf("✍️ %s - 📖 %s", ColorAuthor.Sprint(q.Author), ColorBook.Sprint(q.Book))) } diff --git a/main_test.go b/main_test.go deleted file mode 100644 index 2354e25..0000000 --- a/main_test.go +++ /dev/null @@ -1,47 +0,0 @@ -package main - -import ( - "testing" - - "github.com/alecthomas/assert" -) - -func TestGenWordSlice(t *testing.T) { - assert := assert.New(t) - - tables := []struct { - input []string - index int - expected [][]string - }{ - { - []string{"foo", "bar", "zonk"}, - 2, - [][]string{{"foo", "bar"}, {"zonk"}}, - }, - } - - for _, table := range tables { - assert.Equal(genWordSlice(table.input, table.index), table.expected) - } -} - -// func TestGet(t *testing.T) { -// tables := []struct { -// m map[string][]Quote -// q Quote -// }{ -// { -// map[string][]Quote{"00:00": { -// Quote{"Max Mustermann", "Testbook", "This is a time!", "time"}, -// }}, -// Quote{"Max Mustermann", "Testbook", "This is a time!", "time"}, -// }, -// } -// for _, table := range tables { -// q := get(table.m, "00:00") -// if q != table.q { -// t.Errorf("quote \"%+v\" is not like \"%+v\"", q, table.q) -// } -// } -// }