finally pterm based refactoring
Some checks reported errors
continuous-integration/drone/push Build encountered an error
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:
parent
3c56eee5bf
commit
08e2c5e5fc
49
.drone.yml
49
.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
|
||||
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -16,3 +16,4 @@
|
||||
|
||||
# Own stuff
|
||||
dist/*
|
||||
.envrc
|
||||
|
65
.goreleaser.yml
Normal file
65
.goreleaser.yml
Normal 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"
|
20
Makefile
20
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/
|
||||
|
32
main.go
32
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)))
|
||||
}
|
||||
|
47
main_test.go
47
main_test.go
@ -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)
|
||||
// }
|
||||
// }
|
||||
// }
|
Loading…
Reference in New Issue
Block a user