From e837d2e94b972616529403c26b9557b96bc67d2f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 3 May 2024 02:10:34 +0000 Subject: [PATCH 01/13] Bump github.com/essentialkaos/ek/v12 from 12.118.0 to 12.121.0 Bumps [github.com/essentialkaos/ek/v12](https://github.com/essentialkaos/ek) from 12.118.0 to 12.121.0. - [Release notes](https://github.com/essentialkaos/ek/releases) - [Changelog](https://github.com/essentialkaos/ek/blob/master/CHANGELOG.md) - [Commits](https://github.com/essentialkaos/ek/compare/v12.118.0...v12.121.0) --- updated-dependencies: - dependency-name: github.com/essentialkaos/ek/v12 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- go.mod | 4 ++-- go.sum | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index a762990..58db1c5 100644 --- a/go.mod +++ b/go.mod @@ -3,13 +3,13 @@ module github.com/essentialkaos/aligo/v2 go 1.18 require ( - github.com/essentialkaos/ek/v12 v12.118.0 + github.com/essentialkaos/ek/v12 v12.121.0 github.com/kisielk/gotool v1.0.0 golang.org/x/tools v0.20.0 ) require ( - github.com/essentialkaos/depsy v1.1.0 // indirect + github.com/essentialkaos/depsy v1.3.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 006b917..a845f33 100644 --- a/go.sum +++ b/go.sum @@ -1,8 +1,8 @@ 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.118.0 h1:fosk+jCK9GrrnPiua1O6PQSwrlQ25arwespB6fnbi9g= -github.com/essentialkaos/ek/v12 v12.118.0/go.mod h1:VVCk0ZA3CB5lPkQ7bUHo/mOBs02jkjMRlLS8ES2TQpw= +github.com/essentialkaos/depsy v1.3.0 h1:CN7bRgBU2jGTHSkg/Sh38eDUn7cvmaTp2sxFt2HpFeU= +github.com/essentialkaos/depsy v1.3.0/go.mod h1:kpiTAV17dyByVnrbNaMcZt2jRwvuXClUYOzpyJQwtG8= +github.com/essentialkaos/ek/v12 v12.121.0 h1:Ax/6FsF6mYzT9KSaphqGqrphvMuWslSCIUCrQqWk0v0= +github.com/essentialkaos/ek/v12 v12.121.0/go.mod h1:VUiC4T8afqtE+UzJftTlIypDBKI1s+0nxxNfBhjyIbo= 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= From 909d017378db57fb30566b41919f0b626c3981bf Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 6 May 2024 02:10:26 +0000 Subject: [PATCH 02/13] Bump github.com/essentialkaos/ek/v12 from 12.121.0 to 12.122.0 Bumps [github.com/essentialkaos/ek/v12](https://github.com/essentialkaos/ek) from 12.121.0 to 12.122.0. - [Release notes](https://github.com/essentialkaos/ek/releases) - [Changelog](https://github.com/essentialkaos/ek/blob/master/CHANGELOG.md) - [Commits](https://github.com/essentialkaos/ek/compare/v12.121.0...v12.122.0) --- updated-dependencies: - dependency-name: github.com/essentialkaos/ek/v12 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 58db1c5..d09cbf0 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/essentialkaos/aligo/v2 go 1.18 require ( - github.com/essentialkaos/ek/v12 v12.121.0 + github.com/essentialkaos/ek/v12 v12.122.0 github.com/kisielk/gotool v1.0.0 golang.org/x/tools v0.20.0 ) diff --git a/go.sum b/go.sum index a845f33..bff32e6 100644 --- a/go.sum +++ b/go.sum @@ -1,8 +1,8 @@ github.com/essentialkaos/check v1.4.0 h1:kWdFxu9odCxUqo1NNFNJmguGrDHgwi3A8daXX1nkuKk= github.com/essentialkaos/depsy v1.3.0 h1:CN7bRgBU2jGTHSkg/Sh38eDUn7cvmaTp2sxFt2HpFeU= github.com/essentialkaos/depsy v1.3.0/go.mod h1:kpiTAV17dyByVnrbNaMcZt2jRwvuXClUYOzpyJQwtG8= -github.com/essentialkaos/ek/v12 v12.121.0 h1:Ax/6FsF6mYzT9KSaphqGqrphvMuWslSCIUCrQqWk0v0= -github.com/essentialkaos/ek/v12 v12.121.0/go.mod h1:VUiC4T8afqtE+UzJftTlIypDBKI1s+0nxxNfBhjyIbo= +github.com/essentialkaos/ek/v12 v12.122.0 h1:bIc4JhnnZwdF8pR9GmO51338WARHy6uvVT5eN0JZafU= +github.com/essentialkaos/ek/v12 v12.122.0/go.mod h1:VUiC4T8afqtE+UzJftTlIypDBKI1s+0nxxNfBhjyIbo= 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= From 517a03233c422cb0d44f27d8ff2de428039b3c0b Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 8 May 2024 02:50:05 +0000 Subject: [PATCH 03/13] Bump github.com/essentialkaos/ek/v12 from 12.122.0 to 12.123.2 Bumps [github.com/essentialkaos/ek/v12](https://github.com/essentialkaos/ek) from 12.122.0 to 12.123.2. - [Release notes](https://github.com/essentialkaos/ek/releases) - [Changelog](https://github.com/essentialkaos/ek/blob/master/CHANGELOG.md) - [Commits](https://github.com/essentialkaos/ek/compare/v12.122.0...v12.123.2) --- updated-dependencies: - dependency-name: github.com/essentialkaos/ek/v12 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- go.mod | 4 ++-- go.sum | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index d09cbf0..25e21ed 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/essentialkaos/aligo/v2 go 1.18 require ( - github.com/essentialkaos/ek/v12 v12.122.0 + github.com/essentialkaos/ek/v12 v12.123.2 github.com/kisielk/gotool v1.0.0 golang.org/x/tools v0.20.0 ) @@ -12,5 +12,5 @@ require ( github.com/essentialkaos/depsy v1.3.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 + golang.org/x/sys v0.20.0 // indirect ) diff --git a/go.sum b/go.sum index bff32e6..5e6ef2e 100644 --- a/go.sum +++ b/go.sum @@ -1,8 +1,8 @@ github.com/essentialkaos/check v1.4.0 h1:kWdFxu9odCxUqo1NNFNJmguGrDHgwi3A8daXX1nkuKk= github.com/essentialkaos/depsy v1.3.0 h1:CN7bRgBU2jGTHSkg/Sh38eDUn7cvmaTp2sxFt2HpFeU= github.com/essentialkaos/depsy v1.3.0/go.mod h1:kpiTAV17dyByVnrbNaMcZt2jRwvuXClUYOzpyJQwtG8= -github.com/essentialkaos/ek/v12 v12.122.0 h1:bIc4JhnnZwdF8pR9GmO51338WARHy6uvVT5eN0JZafU= -github.com/essentialkaos/ek/v12 v12.122.0/go.mod h1:VUiC4T8afqtE+UzJftTlIypDBKI1s+0nxxNfBhjyIbo= +github.com/essentialkaos/ek/v12 v12.123.2 h1:pTJ/XfEAPXb4RUU9ZtCtVfeOT9kLpZsUhtYFVOoCTwI= +github.com/essentialkaos/ek/v12 v12.123.2/go.mod h1:cnS6YLrSZc9Ct7NvS5Qx0/7+sMRcEwPp4vGNHMq95/Y= 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= @@ -12,7 +12,7 @@ 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/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y= +golang.org/x/sys v0.20.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= From dfaeaf103cba6d082bfdc03a005e4c6690cc4883 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 8 May 2024 09:03:06 +0000 Subject: [PATCH 04/13] Bump golang.org/x/tools from 0.20.0 to 0.21.0 Bumps [golang.org/x/tools](https://github.com/golang/tools) from 0.20.0 to 0.21.0. - [Release notes](https://github.com/golang/tools/releases) - [Commits](https://github.com/golang/tools/compare/v0.20.0...v0.21.0) --- updated-dependencies: - dependency-name: golang.org/x/tools dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 25e21ed..02c911c 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.18 require ( github.com/essentialkaos/ek/v12 v12.123.2 github.com/kisielk/gotool v1.0.0 - golang.org/x/tools v0.20.0 + golang.org/x/tools v0.21.0 ) require ( diff --git a/go.sum b/go.sum index 5e6ef2e..10f7c99 100644 --- a/go.sum +++ b/go.sum @@ -14,5 +14,5 @@ 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.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y= golang.org/x/sys v0.20.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= +golang.org/x/tools v0.21.0 h1:qc0xYgIbsSDt9EyWz05J5wfa7LOVW0YTLOXrqdLAWIw= +golang.org/x/tools v0.21.0/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk= From b917a9caf36457c87876027cb8bf78d11329b341 Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Sun, 12 May 2024 13:54:09 +0300 Subject: [PATCH 05/13] Code refactoring --- cli/cli.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cli/cli.go b/cli/cli.go index 5b1ed1b..cc653f9 100644 --- a/cli/cli.go +++ b/cli/cli.go @@ -106,9 +106,11 @@ func Run(gitRev string, gomod []byte) { genAbout(gitRev).Print(options.GetS(OPT_VER)) os.Exit(0) case options.GetB(OPT_VERB_VER): - support.Collect(APP, VER).WithRevision(gitRev). + support.Collect(APP, VER). + WithRevision(gitRev). WithDeps(deps.Extract(gomod)). - WithApps(apps.Golang()).Print() + WithApps(apps.Golang()). + Print() os.Exit(0) case options.GetB(OPT_HELP) || len(args) < 2: genUsage().Print() From 9f1a7ef01d996a577bfae5e970692ca5a15c1c1c Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Sun, 12 May 2024 14:31:50 +0300 Subject: [PATCH 06/13] Fix type conversion panic in inspect.GetMaxAlign --- inspect/inspect.go | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/inspect/inspect.go b/inspect/inspect.go index d38bed9..42cea66 100644 --- a/inspect/inspect.go +++ b/inspect/inspect.go @@ -13,6 +13,7 @@ import ( "go/token" "go/types" "path" + "reflect" "sort" "strings" @@ -78,7 +79,23 @@ func GetMaxAlign() int64 { return 8 } - return Sizes.(*types.StdSizes).MaxAlign + switch t := Sizes.(type) { + case *types.StdSizes: + return t.MaxAlign + } + + // Get MaxAlign from private struct like *types.gcSizes + ptr := reflect.ValueOf(Sizes) + + if ptr.IsValid() { + f := reflect.Indirect(ptr).FieldByName("MaxAlign") + + if f.IsValid() { + return f.Int() + } + } + + return 8 } // ////////////////////////////////////////////////////////////////////////////////// // From 90b23da34901934cc3566854285e3fcafccb7cbe Mon Sep 17 00:00:00 2001 From: silves-xiang <62538535+silves-xiang@users.noreply.github.com> Date: Sun, 12 May 2024 20:23:42 +0800 Subject: [PATCH 07/13] Fix byte position error when aligning memory (#154) --- cli/render.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cli/render.go b/cli/render.go index 1cb9823..c528858 100644 --- a/cli/render.go +++ b/cli/render.go @@ -282,6 +282,11 @@ func printCurrentFieldsInfo(fields []*report.Field) { fmt.Print(strings.Repeat(" ", int(counter+1))) + for counter%field.Size != 0 { + fmtc.Printf("{r}□ {!}") + counter++ + } + for i := int64(0); i < field.Size; i++ { fmtc.Printf("{g}■ {!}") From 3002c0efb65a973561816111c426b37c09f3fc66 Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Sun, 12 May 2024 15:25:36 +0300 Subject: [PATCH 08/13] Version bump --- cli/cli.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/cli.go b/cli/cli.go index cc653f9..884ddfe 100644 --- a/cli/cli.go +++ b/cli/cli.go @@ -40,7 +40,7 @@ import ( // App info const ( APP = "aligo" - VER = "2.1.3" + VER = "2.1.4" DESC = "Utility for viewing and checking Go struct alignment" ) From 4745a9b4d5f7e57158fb153180b51a97f9b79d91 Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Sun, 12 May 2024 15:49:23 +0300 Subject: [PATCH 09/13] Code refactoring --- cli/render.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/cli/render.go b/cli/render.go index c528858..af6b460 100644 --- a/cli/render.go +++ b/cli/render.go @@ -245,11 +245,11 @@ func printStructInfo(str *report.Struct, optimal bool) { printStructSizeInfo(str, optimal) if str.Size == 0 { - fmtc.Printf(" type {*}%s{!} struct {s}{ }{!}\n\n", str.Name) + fmtc.Printf(" type {&}{*}%s{!} struct {s}{ }{!}\n\n", str.Name) return } - fmtc.Printf(" type {*}%s{!} struct {s}{{!}\n", str.Name) + fmtc.Printf(" type {&}{*}%s{!} struct {s}{{!}\n", str.Name) if optimal { printAlignedFieldsInfo(str.AlignedFields) @@ -283,12 +283,12 @@ func printCurrentFieldsInfo(fields []*report.Field) { fmt.Print(strings.Repeat(" ", int(counter+1))) for counter%field.Size != 0 { - fmtc.Printf("{r}□ {!}") + fmtc.Printf("{r}□{!} ") counter++ } for i := int64(0); i < field.Size; i++ { - fmtc.Printf("{g}■ {!}") + fmtc.Printf("{g}■{!} ") counter++ @@ -302,10 +302,10 @@ func printCurrentFieldsInfo(fields []*report.Field) { } if index+1 < len(fields) && counter != 0 && fields[index+1].Size > maxAlign-counter { - fmtc.Printf(strings.Repeat("{r}□ {!}", int(maxAlign-counter))) + fmtc.Printf(strings.Repeat("{r}□{!} ", int(maxAlign-counter))) counter = 0 } else if index+1 == len(fields) && counter != 0 { - fmtc.Printf(strings.Repeat("{g}□ {!}", int(maxAlign-counter))) + fmtc.Printf(strings.Repeat("{g}□{!} ", int(maxAlign-counter))) } fmtc.NewLine() From 6c2b2910ea01c6cbc143bb4846311437c52ea6b4 Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Mon, 13 May 2024 00:07:12 +0300 Subject: [PATCH 10/13] Improve README --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ba0e8fc..c93a3a8 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@

-

ScreenshotsInstallationCommand-line completionMan documentationFAQUsageBuild StatusContributingThanksLicense

+

ScreenshotsInstallationCommand-line completionMan documentationFAQUsageCI StatusContributingThanksLicense


@@ -144,7 +144,7 @@ Examples Show info about PostMessageParameters struct ``` -### Build Status +### CI Status | Branch | Status | |--------|--------| From 1ccaf45fb06e05c2f723b5031d9aba145586f5c2 Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Mon, 13 May 2024 00:07:24 +0300 Subject: [PATCH 11/13] Regenerate Makefile with the latest version of gomakegen --- Makefile | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index 0b6707c..79ae4b7 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ ################################################################################ -# This Makefile generated by GoMakeGen 3.0.0 using next command: +# This Makefile generated by GoMakeGen 3.0.1 using next command: # gomakegen --mod . # # More info: https://kaos.sh/gomakegen @@ -25,15 +25,15 @@ GITREV ?= $(shell test -s $(MAKEDIR)/.git && git rev-parse --short HEAD) all: aligo ## Build all binaries aligo: - @echo "[1/1] Building aligo…" + @echo "Building aligo…" @go build $(VERBOSE_FLAG) -ldflags="-X main.gitrev=$(GITREV)" aligo.go install: ## Install all binaries - @echo "[1/1] Installing binaries…" + @echo "Installing binaries…" @cp aligo /usr/bin/aligo uninstall: ## Uninstall all binaries - @echo "[1/1] Removing installed binaries…" + @echo "Removing installed binaries…" @rm -f /usr/bin/aligo init: mod-init ## Initialize new module @@ -81,23 +81,23 @@ endif @test -d vendor && rm -rf vendor && go mod vendor $(VERBOSE_FLAG) || : mod-download: - @echo "[1/1] Downloading dependencies…" + @echo "Downloading dependencies…" @go mod download mod-vendor: - @echo "[1/1] Vendoring dependencies…" + @echo "Vendoring dependencies…" @rm -rf vendor && go mod vendor $(VERBOSE_FLAG) || : fmt: ## Format source code with gofmt - @echo "[1/1] Formatting sources…" + @echo "Formatting sources…" @find . -name "*.go" -exec gofmt -s -w {} \; vet: ## Runs 'go vet' over sources - @echo "[1/1] Running 'go vet' over sources…" + @echo "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 - @echo "[1/1] Removing built binaries…" + @echo "Removing built binaries…" @rm -f aligo help: ## Show this info @@ -109,6 +109,6 @@ help: ## Show this info | sed 's/ifdef //' \ | awk 'BEGIN {FS = " .*?## "}; {printf " \033[32m%-11s\033[0m %s\n", $$1, $$2}' @echo -e '' - @echo -e '\033[90mGenerated by GoMakeGen 3.0.0\033[0m\n' + @echo -e '\033[90mGenerated by GoMakeGen 3.0.1\033[0m\n' ################################################################################ From 689797b023c2d3b50569fed7c8f3ac9d31f85857 Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Mon, 13 May 2024 00:07:48 +0300 Subject: [PATCH 12/13] Dependencies update --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 02c911c..30b60e7 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/essentialkaos/aligo/v2 go 1.18 require ( - github.com/essentialkaos/ek/v12 v12.123.2 + github.com/essentialkaos/ek/v12 v12.124.0 github.com/kisielk/gotool v1.0.0 golang.org/x/tools v0.21.0 ) diff --git a/go.sum b/go.sum index 10f7c99..7ed58e5 100644 --- a/go.sum +++ b/go.sum @@ -1,8 +1,8 @@ github.com/essentialkaos/check v1.4.0 h1:kWdFxu9odCxUqo1NNFNJmguGrDHgwi3A8daXX1nkuKk= github.com/essentialkaos/depsy v1.3.0 h1:CN7bRgBU2jGTHSkg/Sh38eDUn7cvmaTp2sxFt2HpFeU= github.com/essentialkaos/depsy v1.3.0/go.mod h1:kpiTAV17dyByVnrbNaMcZt2jRwvuXClUYOzpyJQwtG8= -github.com/essentialkaos/ek/v12 v12.123.2 h1:pTJ/XfEAPXb4RUU9ZtCtVfeOT9kLpZsUhtYFVOoCTwI= -github.com/essentialkaos/ek/v12 v12.123.2/go.mod h1:cnS6YLrSZc9Ct7NvS5Qx0/7+sMRcEwPp4vGNHMq95/Y= +github.com/essentialkaos/ek/v12 v12.124.0 h1:WyeEHCalPV7LcF/7YaoR5T3YHBIpOYzmsef9LI7nvbQ= +github.com/essentialkaos/ek/v12 v12.124.0/go.mod h1:cnS6YLrSZc9Ct7NvS5Qx0/7+sMRcEwPp4vGNHMq95/Y= 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= From 98318baee4f9b591f8d950bf1329145c7bd3cde5 Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Mon, 20 May 2024 17:28:46 +0300 Subject: [PATCH 13/13] Add internationalization --- .gitignore | 2 + cli/cli.go | 50 ++++++------ cli/i18n/i18n.go | 192 +++++++++++++++++++++++++++++++++++++++++++++++ cli/render.go | 15 ++-- go.mod | 2 +- go.sum | 4 +- 6 files changed, 233 insertions(+), 32 deletions(-) create mode 100644 .gitignore create mode 100644 cli/i18n/i18n.go diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e52c207 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +vendor +aligo diff --git a/cli/cli.go b/cli/cli.go index 884ddfe..015ed29 100644 --- a/cli/cli.go +++ b/cli/cli.go @@ -32,6 +32,7 @@ import ( "github.com/essentialkaos/ek/v12/usage/man" "github.com/essentialkaos/ek/v12/usage/update" + "github.com/essentialkaos/aligo/v2/cli/i18n" "github.com/essentialkaos/aligo/v2/inspect" ) @@ -39,9 +40,8 @@ import ( // App info const ( - APP = "aligo" - VER = "2.1.4" - DESC = "Utility for viewing and checking Go struct alignment" + APP = "aligo" + VER = "2.2.0" ) // Constants with options names @@ -89,7 +89,7 @@ func Run(gitRev string, gomod []byte) { args, errs := options.Parse(optMap) if !errs.IsEmpty() { - terminal.Error("Options parsing errors:") + terminal.Error(i18n.UI.ERRORS.OPTION_PARSING.Add("", ":")) terminal.Error(errs.String()) os.Exit(1) } @@ -142,6 +142,8 @@ func preConfigureUI() { default: colorTagApp, colorTagVer = "{*}{&}{c}", "{c}" } + + i18n.SetLanguage() } // configureUI configures user interface @@ -165,7 +167,7 @@ func prepare() error { inspect.Sizes = types.SizesFor("gc", arch) if inspect.Sizes == nil { - return fmt.Errorf("Unknown arch %s", arch) + return fmt.Errorf(i18n.UI.ERRORS.UNKNOWN_ARCH.String(), arch) } return nil @@ -215,7 +217,7 @@ func process(args options.Arguments) (error, bool) { } default: - return fmt.Errorf("Command %s is unsupported", cmd), false + return fmt.Errorf(i18n.UI.ERRORS.UNSUPPORTED_COMMAND.String(), cmd), false } return nil, true @@ -248,40 +250,44 @@ func printMan() { // genUsage generates usage info func genUsage() *usage.Info { - info := usage.NewInfo("", "package…") + info := usage.NewInfo("", i18n.UI.USAGE.ARGUMENTS.String()) info.AppNameColorTag = colorTagApp - info.AddCommand("check", "Check package for alignment problems") - info.AddCommand("view", "Print alignment info for all structs") + info.AddCommand("check", i18n.UI.USAGE.COMMANDS.CHECK.String()) + info.AddCommand("view", i18n.UI.USAGE.COMMANDS.VIEW.String()) - info.AddOption(OPT_ARCH, "Architecture name", "name") - info.AddOption(OPT_STRUCT, "Print info only about struct with given name", "name") - info.AddOption(OPT_TAGS, "Build tags {s-}(mergeble){!}", "tag…") - info.AddOption(OPT_PAGER, "Use pager for long output") - info.AddOption(OPT_NO_COLOR, "Disable colors in output") - info.AddOption(OPT_HELP, "Show this help message") - info.AddOption(OPT_VER, "Show version") + info.AddOption(OPT_ARCH, i18n.UI.USAGE.OPTIONS.ARCH.String(), i18n.UI.USAGE.OPTIONS.ARCH_VAL.String()) + info.AddOption(OPT_STRUCT, i18n.UI.USAGE.OPTIONS.STRUCT.String(), i18n.UI.USAGE.OPTIONS.STRUCT_VAL.String()) + info.AddOption(OPT_TAGS, i18n.UI.USAGE.OPTIONS.TAGS.String(), i18n.UI.USAGE.OPTIONS.TAGS_VAL.String()) + info.AddOption(OPT_PAGER, i18n.UI.USAGE.OPTIONS.PAGER.String()) + info.AddOption(OPT_NO_COLOR, i18n.UI.USAGE.OPTIONS.NO_COLOR.String()) + info.AddOption(OPT_HELP, i18n.UI.USAGE.OPTIONS.HELP.String()) + info.AddOption(OPT_VER, i18n.UI.USAGE.OPTIONS.VER.String()) info.AddExample( - "view .", "Show info about all structs in current package", + "view .", + i18n.UI.USAGE.EXAMPLES.EXAMPLE_1.String(), ) info.AddExample( - "check .", "Check current package", + "check .", + i18n.UI.USAGE.EXAMPLES.EXAMPLE_2.String(), ) info.AddExample( - "check ./...", "Check current package and all sub-packages", + "check ./...", + i18n.UI.USAGE.EXAMPLES.EXAMPLE_3.String(), ) info.AddExample( - "--tags tag1,tag2,tag3 check ./...", "Check current package and all sub-packages with custom build tags", + "--tags tag1,tag2,tag3 check ./...", + i18n.UI.USAGE.EXAMPLES.EXAMPLE_4.String(), ) info.AddExample( "-s PostMessageParameters view .", - "Show info about PostMessageParameters struct", + i18n.UI.USAGE.EXAMPLES.EXAMPLE_5.String(), ) return info @@ -292,7 +298,7 @@ func genAbout(gitRev string) *usage.About { about := &usage.About{ App: APP, Version: VER, - Desc: DESC, + Desc: i18n.UI.USAGE.DESC.String(), Year: 2009, Owner: "ESSENTIAL KAOS", diff --git a/cli/i18n/i18n.go b/cli/i18n/i18n.go new file mode 100644 index 0000000..8e5d1a3 --- /dev/null +++ b/cli/i18n/i18n.go @@ -0,0 +1,192 @@ +package i18n + +// ////////////////////////////////////////////////////////////////////////////////// // +// // +// Copyright (c) 2023 ESSENTIAL KAOS // +// Apache License, Version 2.0 // +// // +// ////////////////////////////////////////////////////////////////////////////////// // + +import ( + "os" + "strings" + + "github.com/essentialkaos/ek/v12/i18n" +) + +// ////////////////////////////////////////////////////////////////////////////////// // + +type I18NBundle struct { + INFO *I18NInfo + USAGE *I18NUsage + + ERRORS *I18NErrors +} + +type I18NErrors struct { + OPTION_PARSING i18n.String + UNSUPPORTED_COMMAND i18n.String + UNKNOWN_ARCH i18n.String + + EMPTY_STRUCT_NAME i18n.String + NO_STRUCT i18n.String + NO_ANY_STRUCTS i18n.String +} + +type I18NInfo struct { + ALL_OPTIMAL i18n.String + OPTIMIZE_ADVICE i18n.String + WITH_OPTIMAL i18n.String + ALREADY_OPTIMAL i18n.String +} + +type I18NUsage struct { + DESC i18n.String + ARGUMENTS i18n.String + + COMMANDS *I18NCommands + OPTIONS *I18NOptions + EXAMPLES *I18NExamples +} + +type I18NCommands struct { + CHECK i18n.String + VIEW i18n.String +} + +type I18NOptions struct { + ARCH i18n.String + ARCH_VAL i18n.String + STRUCT i18n.String + STRUCT_VAL i18n.String + TAGS i18n.String + TAGS_VAL i18n.String + PAGER i18n.String + NO_COLOR i18n.String + HELP i18n.String + VER i18n.String +} + +type I18NExamples struct { + EXAMPLE_1 i18n.String + EXAMPLE_2 i18n.String + EXAMPLE_3 i18n.String + EXAMPLE_4 i18n.String + EXAMPLE_5 i18n.String +} + +// ////////////////////////////////////////////////////////////////////////////////// // + +// UI is a bundle with data for used language +var UI = getEN() + +// ////////////////////////////////////////////////////////////////////////////////// // + +// SetLanguage sets app language +func SetLanguage() { + lang, _, _ := strings.Cut(os.Getenv("LANG"), "_") + + switch strings.ToLower(lang) { + case "ru": + l, _ := i18n.Fallback(getEN(), getRU()) + UI = l.(*I18NBundle) + } +} + +// ////////////////////////////////////////////////////////////////////////////////// // + +// getEN returns bundle for English language +func getEN() *I18NBundle { + return &I18NBundle{ + INFO: &I18NInfo{ + ALL_OPTIMAL: "{g}All structs are well aligned{!}", + OPTIMIZE_ADVICE: "Struct {*}%s{!} {s-}(%s:%d){!} fields order can be optimized (%d → %d)", + WITH_OPTIMAL: "{s-}// %s:%d | Size: %d (Optimal: %d){!}", + ALREADY_OPTIMAL: "{s-}// %s:%d | Size: %d{!}", + }, + ERRORS: &I18NErrors{ + OPTION_PARSING: "Options parsing errors", + UNSUPPORTED_COMMAND: "Command %s is unsupported", + UNKNOWN_ARCH: "Unknown arch %s", + + NO_ANY_STRUCTS: "Given package doesn't have any structs", + NO_STRUCT: "Can't find struct with name %q", + EMPTY_STRUCT_NAME: "You should define struct name", + }, + USAGE: &I18NUsage{ + DESC: "Utility for viewing and checking Go struct alignment", + ARGUMENTS: "path…", + COMMANDS: &I18NCommands{ + CHECK: "Check package for alignment problems", + VIEW: "Print alignment info for all structs", + }, + OPTIONS: &I18NOptions{ + ARCH: "Architecture name", + ARCH_VAL: "name", + STRUCT: "Print info only about struct with given name", + STRUCT_VAL: "name", + TAGS: "Build tags {s-}(mergeble){!}", + TAGS_VAL: "tag…", + PAGER: "Use pager for long output", + NO_COLOR: "Disable colors in output", + HELP: "Show this help message", + VER: "Show version", + }, + EXAMPLES: &I18NExamples{ + EXAMPLE_1: "Show info about all structs in current package", + EXAMPLE_2: "Check current package", + EXAMPLE_3: "Check current package and all sub-packages", + EXAMPLE_4: "Check current package and all sub-packages with custom build tags", + EXAMPLE_5: "Show info about PostMessageParameters struct", + }, + }, + } +} + +// getRU returns bundle for Russian language +func getRU() *I18NBundle { + return &I18NBundle{ + INFO: &I18NInfo{ + ALL_OPTIMAL: "{g}Проблем с выравниванием структур не обнаружено{!}", + OPTIMIZE_ADVICE: "Поля структуры {*}%s{!} {s-}(%s:%d){!} могут быть оптимизированны (%d → %d)", + WITH_OPTIMAL: "{s-}// %s:%d | Размер: %d (Оптимальный: %d){!}", + ALREADY_OPTIMAL: "{s-}// %s:%d | Размер: %d{!}", + }, + ERRORS: &I18NErrors{ + OPTION_PARSING: "Ошибки обработки опций", + UNSUPPORTED_COMMAND: "Команда %s не поддерживается", + UNKNOWN_ARCH: "Неизвестная архитектура %s", + + NO_ANY_STRUCTS: "Указанный пакет не содержит структур", + NO_STRUCT: "Структура с именем %q не найдена", + EMPTY_STRUCT_NAME: "Вы должны указать имя структуры", + }, + USAGE: &I18NUsage{ + DESC: "Утилита для просмотра и проверки выравнивания полей в структрах Go", + ARGUMENTS: "путь…", + COMMANDS: &I18NCommands{ + CHECK: "Проверка на наличие проблем с выравниванием", + VIEW: "Отображние информации о выравнивании", + }, + OPTIONS: &I18NOptions{ + ARCH: "Название архитектуры", + ARCH_VAL: "имя", + STRUCT: "Отображение информации только для указанной структуры", + STRUCT_VAL: "имя", + TAGS: "Тэги сборки {s-}(повторяемая опция){!}", + TAGS_VAL: "тэг…", + PAGER: "Использовать паджинацию для длинного вывода", + NO_COLOR: "Отключение цветного вывода", + HELP: "Показать это справочное сообщение", + VER: "Показать версию", + }, + EXAMPLES: &I18NExamples{ + EXAMPLE_1: "Просмотр информации о всех структурах пакета", + EXAMPLE_2: "Проверка текущей директории", + EXAMPLE_3: "Проверка текущей директории и всех дочерних", + EXAMPLE_4: "Проверка текущей директории и всех дочерних с использованием тэгов", + EXAMPLE_5: "Отображение информации о структуре PostMessageParameters", + }, + }, + } +} diff --git a/cli/render.go b/cli/render.go index af6b460..7d618b8 100644 --- a/cli/render.go +++ b/cli/render.go @@ -16,6 +16,7 @@ import ( "github.com/essentialkaos/ek/v12/mathutil" "github.com/essentialkaos/ek/v12/terminal" + "github.com/essentialkaos/aligo/v2/cli/i18n" "github.com/essentialkaos/aligo/v2/inspect" "github.com/essentialkaos/aligo/v2/report" ) @@ -51,14 +52,14 @@ func PrintStruct(r *report.Report, strName string, optimal bool) { } if strName == "" { - terminal.Warn("You should define struct name") + terminal.Warn(i18n.UI.ERRORS.EMPTY_STRUCT_NAME) return } pkg, str := findStruct(r, strName) if pkg == nil && str == nil { - terminal.Warn("Can't find struct with name %q", strName) + terminal.Warn(i18n.UI.ERRORS.NO_STRUCT, strName) return } @@ -85,7 +86,7 @@ func Check(r *report.Report) bool { } if !hasProblems { - fmtc.Println("{g}All structs are well aligned{!}") + fmtc.Println(i18n.UI.INFO.ALL_OPTIMAL.String()) return true } @@ -186,7 +187,7 @@ func (r *Renderer) PrintPlaceholder() { // isEmptyReport returns true if report is empty func isEmptyReport(r *report.Report) bool { if r.IsEmpty() { - terminal.Warn("Given package doesn't have any structs") + terminal.Warn(i18n.UI.ERRORS.NO_ANY_STRUCTS) return true } @@ -222,18 +223,18 @@ func printPackageInfo(pkg *report.Package, onlyProblems bool) { func printStructSizeInfo(str *report.Struct, optimal bool) { if optimal { fmtc.Printf( - "Struct {*}%s{!} {s-}(%s:%d){!} fields order can be optimized (%d → %d)\n\n", + i18n.UI.INFO.OPTIMIZE_ADVICE.Add("", "\n\n"), str.Name, str.Position.File, str.Position.Line, str.Size, str.OptimalSize, ) } else { if str.Size != str.OptimalSize { fmtc.Printf( - " {s-}// %s:%d | Size: %d (Optimal: %d){!}\n", + i18n.UI.INFO.WITH_OPTIMAL.Add(" ", "\n"), str.Position.File, str.Position.Line, str.Size, str.OptimalSize, ) } else { fmtc.Printf( - " {s-}// %s:%d | Size: %d{!}\n", + i18n.UI.INFO.ALREADY_OPTIMAL.Add(" ", "\n"), str.Position.File, str.Position.Line, str.Size, ) } diff --git a/go.mod b/go.mod index 30b60e7..93c61ce 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/essentialkaos/aligo/v2 go 1.18 require ( - github.com/essentialkaos/ek/v12 v12.124.0 + github.com/essentialkaos/ek/v12 v12.125.0 github.com/kisielk/gotool v1.0.0 golang.org/x/tools v0.21.0 ) diff --git a/go.sum b/go.sum index 7ed58e5..01971cc 100644 --- a/go.sum +++ b/go.sum @@ -1,8 +1,8 @@ github.com/essentialkaos/check v1.4.0 h1:kWdFxu9odCxUqo1NNFNJmguGrDHgwi3A8daXX1nkuKk= github.com/essentialkaos/depsy v1.3.0 h1:CN7bRgBU2jGTHSkg/Sh38eDUn7cvmaTp2sxFt2HpFeU= github.com/essentialkaos/depsy v1.3.0/go.mod h1:kpiTAV17dyByVnrbNaMcZt2jRwvuXClUYOzpyJQwtG8= -github.com/essentialkaos/ek/v12 v12.124.0 h1:WyeEHCalPV7LcF/7YaoR5T3YHBIpOYzmsef9LI7nvbQ= -github.com/essentialkaos/ek/v12 v12.124.0/go.mod h1:cnS6YLrSZc9Ct7NvS5Qx0/7+sMRcEwPp4vGNHMq95/Y= +github.com/essentialkaos/ek/v12 v12.125.0 h1:LVtDVESX0Rr0/34ZBOwgmpATaQfoQ/FDExqZyAzQp8I= +github.com/essentialkaos/ek/v12 v12.125.0/go.mod h1:cnS6YLrSZc9Ct7NvS5Qx0/7+sMRcEwPp4vGNHMq95/Y= 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=