finally pterm based refactoring
Some checks reported errors
continuous-integration/drone/push Build encountered an error

needed to drop the approach to print the quote in a terminal box.
This commit is contained in:
Marvin Steadfast 2021-03-03 14:03:18 +01:00
parent 3c56eee5bf
commit 08e2c5e5fc
6 changed files with 143 additions and 71 deletions

View File

@ -1,27 +1,42 @@
--- ---
kind: pipeline kind: pipeline
type: docker name: default
steps: steps:
- name: tags
image: alpine/git
commands:
- git fetch --tags
- name: lint
image: golangci/golangci-lint:latest
commands:
- make lint
- name: test - name: test
image: golang:1.13 image: golang:latest
commands: commands:
- make test - make test
- name: lint
image: golangci/golangci-lint:v1.23-alpine
commands:
- apk add --no-cache make
- make lint
- name: build - name: build
image: golang:1.13 image: goreleaser/goreleaser:latest
commands: commands:
- go get -u github.com/mitchellh/gox
- make build - make build
- name: publish
image: plugins/github-release
settings:
api_key:
from_secret: github_token
files:
- fortlit-go_*
when: 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

1
.gitignore vendored
View File

@ -16,3 +16,4 @@
# Own stuff # Own stuff
dist/* dist/*
.envrc

65
.goreleaser.yml Normal file
View File

@ -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 <marvin@xsteadfastx.org>
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"

View File

@ -1,3 +1,23 @@
.PHONY: generate .PHONY: generate
generate: generate:
go generate -v 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/

32
main.go
View File

@ -1,7 +1,8 @@
// nolint: exhaustivestruct, gochecknoglobals, gomnd // nolint: exhaustivestruct, gochecknoglobals, gomnd, forbidigo
package main package main
import ( import (
"flag"
"fmt" "fmt"
"math/rand" "math/rand"
"regexp" "regexp"
@ -15,7 +16,15 @@ import (
//go:generate go run tools/gen/gen.go //go:generate go run tools/gen/gen.go
//go:generate gofumpt -w quotes/quotes.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 ( var (
ColorAuthor = pterm.NewRGB(189, 147, 249) ColorAuthor = pterm.NewRGB(189, 147, 249)
@ -57,6 +66,15 @@ func stringWrap(text string, limit int) string {
} }
func main() { 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() now := time.Now()
t := fmt.Sprintf("%02d:%02d", now.Hour(), now.Minute()) t := fmt.Sprintf("%02d:%02d", now.Hour(), now.Minute())
q := getQuote(quotes.FortData, t) q := getQuote(quotes.FortData, t)
@ -68,10 +86,10 @@ func main() {
m := regexp.MustCompile(fmt.Sprintf("(?i)(%s)", q.Time)) m := regexp.MustCompile(fmt.Sprintf("(?i)(%s)", q.Time))
text := m.ReplaceAllString(q.Text, ColorTime.Sprint("$1")) text := m.ReplaceAllString(q.Text, ColorTime.Sprint("$1"))
pterm.DefaultCenter.Println( wrapText := stringWrap(text, lineWords)
pterm.DefaultBox.Sprint(
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))) pterm.DefaultCenter.Println(fmt.Sprintf("✍️ %s - 📖 %s", ColorAuthor.Sprint(q.Author), ColorBook.Sprint(q.Book)))
} }

View File

@ -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)
// }
// }
// }