diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 775b0d0..7f99348 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -31,7 +31,7 @@ jobs: strategy: matrix: - go: [ '1.18.x', '1.19.x', '1.20.x', '1.21.x', '1.22.x' ] + go: [ '1.19.x', '1.20.x', '1.21.x', '1.22.x' ] steps: - name: Checkout diff --git a/Makefile b/Makefile index 190e1a6..0b6707c 100644 --- a/Makefile +++ b/Makefile @@ -1,38 +1,40 @@ ################################################################################ -# This Makefile generated by GoMakeGen 2.2.0 using next command: +# This Makefile generated by GoMakeGen 3.0.0 using next command: # gomakegen --mod . # # More info: https://kaos.sh/gomakegen ################################################################################ -export GO111MODULE=on - ifdef VERBOSE ## Print verbose information (Flag) VERBOSE_FLAG = -v endif +COMPAT ?= 1.19 MAKEDIR = $(dir $(realpath $(firstword $(MAKEFILE_LIST)))) GITREV ?= $(shell test -s $(MAKEDIR)/.git && git rev-parse --short HEAD) ################################################################################ .DEFAULT_GOAL := help -.PHONY = fmt vet all clean deps update init vendor mod-init mod-update mod-download mod-vendor help +.PHONY = fmt vet all install uninstall clean deps update init vendor mod-init mod-update mod-download mod-vendor help ################################################################################ all: aligo ## Build all binaries aligo: - go build $(VERBOSE_FLAG) -ldflags="-X main.gitrev=$(GITREV)" aligo.go + @echo "[1/1] Building aligo…" + @go build $(VERBOSE_FLAG) -ldflags="-X main.gitrev=$(GITREV)" aligo.go install: ## Install all binaries - cp aligo /usr/bin/aligo + @echo "[1/1] Installing binaries…" + @cp aligo /usr/bin/aligo uninstall: ## Uninstall all binaries - rm -f /usr/bin/aligo + @echo "[1/1] Removing installed binaries…" + @rm -f /usr/bin/aligo init: mod-init ## Initialize new module @@ -43,57 +45,70 @@ update: mod-update ## Update dependencies to the latest versions vendor: mod-vendor ## Make vendored copy of dependencies mod-init: + @echo "[1/2] Modules initialization…" ifdef MODULE_PATH ## Module path for initialization (String) - go mod init $(MODULE_PATH) + @go mod init $(MODULE_PATH) else - go mod init + @go mod init endif + @echo "[2/2] Dependencies cleanup…" ifdef COMPAT ## Compatible Go version (String) - go mod tidy $(VERBOSE_FLAG) -compat=$(COMPAT) + @go mod tidy $(VERBOSE_FLAG) -compat=$(COMPAT) -go=$(COMPAT) else - go mod tidy $(VERBOSE_FLAG) + @go mod tidy $(VERBOSE_FLAG) endif mod-update: + @echo "[1/4] Updating dependencies…" ifdef UPDATE_ALL ## Update all dependencies (Flag) - go get -u $(VERBOSE_FLAG) all + @go get -u $(VERBOSE_FLAG) all else - go get -u $(VERBOSE_FLAG) ./... + @go get -u $(VERBOSE_FLAG) ./... endif + @echo "[2/4] Stripping toolchain info…" + @grep -q 'toolchain ' go.mod && go mod edit -toolchain=none || : + + @echo "[3/4] Dependencies cleanup…" ifdef COMPAT - go mod tidy $(VERBOSE_FLAG) -compat=$(COMPAT) + @go mod tidy $(VERBOSE_FLAG) -compat=$(COMPAT) else - go mod tidy $(VERBOSE_FLAG) + @go mod tidy $(VERBOSE_FLAG) endif - test -d vendor && rm -rf vendor && go mod vendor $(VERBOSE_FLAG) || : + @echo "[4/4] Updating vendored dependencies…" + @test -d vendor && rm -rf vendor && go mod vendor $(VERBOSE_FLAG) || : mod-download: - go mod download + @echo "[1/1] Downloading dependencies…" + @go mod download mod-vendor: - rm -rf vendor && go mod vendor $(VERBOSE_FLAG) + @echo "[1/1] Vendoring dependencies…" + @rm -rf vendor && go mod vendor $(VERBOSE_FLAG) || : fmt: ## Format source code with gofmt - find . -name "*.go" -exec gofmt -s -w {} \; + @echo "[1/1] Formatting sources…" + @find . -name "*.go" -exec gofmt -s -w {} \; vet: ## Runs 'go vet' over sources - go vet -composites=false -printfuncs=LPrintf,TLPrintf,TPrintf,log.Debug,log.Info,log.Warn,log.Error,log.Critical,log.Print ./... + @echo "[1/1] Running 'go vet' over sources…" + @go vet -composites=false -printfuncs=LPrintf,TLPrintf,TPrintf,log.Debug,log.Info,log.Warn,log.Error,log.Critical,log.Print ./... clean: ## Remove generated files - rm -f aligo + @echo "[1/1] Removing built binaries…" + @rm -f aligo help: ## Show this info @echo -e '\n\033[1mTargets:\033[0m\n' @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) \ - | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[33m%-14s\033[0m %s\n", $$1, $$2}' + | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[33m%-9s\033[0m %s\n", $$1, $$2}' @echo -e '\n\033[1mVariables:\033[0m\n' @grep -E '^ifdef [A-Z_]+ .*?## .*$$' $(abspath $(lastword $(MAKEFILE_LIST))) \ | sed 's/ifdef //' \ - | awk 'BEGIN {FS = " .*?## "}; {printf " \033[32m%-14s\033[0m %s\n", $$1, $$2}' + | awk 'BEGIN {FS = " .*?## "}; {printf " \033[32m%-11s\033[0m %s\n", $$1, $$2}' @echo -e '' - @echo -e '\033[90mGenerated by GoMakeGen 2.2.0\033[0m\n' + @echo -e '\033[90mGenerated by GoMakeGen 3.0.0\033[0m\n' ################################################################################ diff --git a/README.md b/README.md index 9278700..ba0e8fc 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ #### From source -To build the _aligo_ from scratch, make sure you have a working Go 1.18+ workspace (_[instructions](https://go.dev/doc/install)_), then: +To build the _aligo_ from scratch, make sure you have a working Go 1.19+ workspace (_[instructions](https://go.dev/doc/install)_), then: ``` go install github.com/essentialkaos/aligo/v2@latest diff --git a/cli/cli.go b/cli/cli.go index 4078e51..5b1ed1b 100644 --- a/cli/cli.go +++ b/cli/cli.go @@ -23,6 +23,8 @@ import ( "github.com/essentialkaos/ek/v12/support" "github.com/essentialkaos/ek/v12/support/apps" "github.com/essentialkaos/ek/v12/support/deps" + "github.com/essentialkaos/ek/v12/terminal" + "github.com/essentialkaos/ek/v12/terminal/tty" "github.com/essentialkaos/ek/v12/usage" "github.com/essentialkaos/ek/v12/usage/completion/bash" "github.com/essentialkaos/ek/v12/usage/completion/fish" @@ -38,7 +40,7 @@ import ( // App info const ( APP = "aligo" - VER = "2.1.2" + VER = "2.1.3" DESC = "Utility for viewing and checking Go struct alignment" ) @@ -86,8 +88,9 @@ func Run(gitRev string, gomod []byte) { args, errs := options.Parse(optMap) - if len(errs) != 0 { - printError(errs[0].Error()) + if !errs.IsEmpty() { + terminal.Error("Options parsing errors:") + terminal.Error(errs.String()) os.Exit(1) } @@ -115,7 +118,7 @@ func Run(gitRev string, gomod []byte) { err, ok := process(args) if err != nil { - printError(err.Error()) + terminal.Error(err) } if !ok { @@ -125,9 +128,18 @@ func Run(gitRev string, gomod []byte) { // preConfigureUI preconfigures UI based on information about user terminal func preConfigureUI() { - if os.Getenv("NO_COLOR") != "" { + if !tty.IsTTY() { fmtc.DisableColors = true } + + switch { + case fmtc.IsTrueColorSupported(): + colorTagApp, colorTagVer = "{*}{&}{#00ADD8}", "{#5DC9E2}" + case fmtc.Is256ColorsSupported(): + colorTagApp, colorTagVer = "{*}{&}{#38}", "{#74}" + default: + colorTagApp, colorTagVer = "{*}{&}{c}", "{c}" + } } // configureUI configures user interface @@ -138,15 +150,6 @@ func configureUI() { strutil.EllipsisSuffix = "…" fmtutil.SeparatorSymbol = "–" - - switch { - case fmtc.IsTrueColorSupported(): - colorTagApp, colorTagVer = "{*}{&}{#00ADD8}", "{#5DC9E2}" - case fmtc.Is256ColorsSupported(): - colorTagApp, colorTagVer = "{*}{&}{#38}", "{#74}" - default: - colorTagApp, colorTagVer = "{*}{&}{c}", "{c}" - } } // prepare configures inspector @@ -216,16 +219,6 @@ func process(args options.Arguments) (error, bool) { return nil, true } -// printError prints error message to console -func printError(f string, a ...interface{}) { - fmtc.Fprintf(os.Stderr, "{r}"+f+"{!}\n", a...) -} - -// printError prints warning message to console -func printWarn(f string, a ...interface{}) { - fmtc.Fprintf(os.Stderr, "{y}"+f+"{!}\n", a...) -} - // ////////////////////////////////////////////////////////////////////////////////// // // printCompletion prints completion for given shell @@ -248,12 +241,7 @@ func printCompletion() int { // printMan prints man page func printMan() { - fmt.Println( - man.Generate( - genUsage(), - genAbout(""), - ), - ) + fmt.Println(man.Generate(genUsage(), genAbout(""))) } // genUsage generates usage info @@ -308,7 +296,7 @@ func genAbout(gitRev string) *usage.About { AppNameColorTag: colorTagApp, VersionColorTag: colorTagVer, - DescSeparator: "—", + DescSeparator: "{s}—{!}", License: "Apache License, Version 2.0 ", UpdateChecker: usage.UpdateChecker{"essentialkaos/aligo", update.GitHubChecker}, diff --git a/cli/render.go b/cli/render.go index 2efcdaf..1cb9823 100644 --- a/cli/render.go +++ b/cli/render.go @@ -14,6 +14,7 @@ import ( "github.com/essentialkaos/ek/v12/fmtc" "github.com/essentialkaos/ek/v12/fmtutil" "github.com/essentialkaos/ek/v12/mathutil" + "github.com/essentialkaos/ek/v12/terminal" "github.com/essentialkaos/aligo/v2/inspect" "github.com/essentialkaos/aligo/v2/report" @@ -50,14 +51,14 @@ func PrintStruct(r *report.Report, strName string, optimal bool) { } if strName == "" { - printWarn("You should define struct name") + terminal.Warn("You should define struct name") return } pkg, str := findStruct(r, strName) if pkg == nil && str == nil { - printWarn("Can't find struct with name \"%s\"", strName) + terminal.Warn("Can't find struct with name %q", strName) return } @@ -185,7 +186,7 @@ func (r *Renderer) PrintPlaceholder() { // isEmptyReport returns true if report is empty func isEmptyReport(r *report.Report) bool { if r.IsEmpty() { - printWarn("Given package doesn't have any structs") + terminal.Warn("Given package doesn't have any structs") return true } diff --git a/go.mod b/go.mod index e74695e..a762990 100644 --- a/go.mod +++ b/go.mod @@ -3,13 +3,14 @@ module github.com/essentialkaos/aligo/v2 go 1.18 require ( - github.com/essentialkaos/ek/v12 v12.113.1 + github.com/essentialkaos/ek/v12 v12.118.0 github.com/kisielk/gotool v1.0.0 - golang.org/x/tools v0.19.0 + golang.org/x/tools v0.20.0 ) require ( github.com/essentialkaos/depsy v1.1.0 // indirect - golang.org/x/mod v0.16.0 // indirect - golang.org/x/sys v0.18.0 // indirect + golang.org/x/mod v0.17.0 // indirect + golang.org/x/sync v0.7.0 // indirect + golang.org/x/sys v0.19.0 // indirect ) diff --git a/go.sum b/go.sum index d6cecfb..006b917 100644 --- a/go.sum +++ b/go.sum @@ -1,17 +1,18 @@ github.com/essentialkaos/check v1.4.0 h1:kWdFxu9odCxUqo1NNFNJmguGrDHgwi3A8daXX1nkuKk= github.com/essentialkaos/depsy v1.1.0 h1:U6dp687UkQwXlZU17Hg2KMxbp3nfZAoZ8duaeUFYvJI= github.com/essentialkaos/depsy v1.1.0/go.mod h1:kpiTAV17dyByVnrbNaMcZt2jRwvuXClUYOzpyJQwtG8= -github.com/essentialkaos/ek/v12 v12.113.1 h1:3opV9dwRpIQq1fqg5mkaSEt6ogECL4VLzrH/829qeYg= -github.com/essentialkaos/ek/v12 v12.113.1/go.mod h1:SslW97Se34YQKc08Ume2V/8h/HPTgLS1+Iok64cNF/U= +github.com/essentialkaos/ek/v12 v12.118.0 h1:fosk+jCK9GrrnPiua1O6PQSwrlQ25arwespB6fnbi9g= +github.com/essentialkaos/ek/v12 v12.118.0/go.mod h1:VVCk0ZA3CB5lPkQ7bUHo/mOBs02jkjMRlLS8ES2TQpw= github.com/kisielk/gotool v1.0.0 h1:AV2c/EiW3KqPNT9ZKl07ehoAGi4C5/01Cfbblndcapg= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M= -golang.org/x/mod v0.16.0 h1:QX4fJ0Rr5cPQCF7O9lh9Se4pmwfwskqZfq5moyldzic= -golang.org/x/mod v0.16.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= -golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ= -golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4= -golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/tools v0.19.0 h1:tfGCXNR1OsFG+sVdLAitlpjAvD/I6dHDKnYrpEZUHkw= -golang.org/x/tools v0.19.0/go.mod h1:qoJWxmGSIBmAeriMx19ogtrEPrGtDbPK634QFIcLAhc= +golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA= +golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= +golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= +golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o= +golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/tools v0.20.0 h1:hz/CVckiOxybQvFw6h7b/q80NTr9IUQb4s1IIzW7KNY= +golang.org/x/tools v0.20.0/go.mod h1:WvitBU7JJf6A4jOdg4S1tviW9bhUxkgeCui/0JHctQg=