From 32dd64bc21dc1fe5e3882e4b0af50581af2c5dea Mon Sep 17 00:00:00 2001 From: plastikfan Date: Thu, 24 Oct 2024 17:09:23 +0100 Subject: [PATCH 1/8] chore: update configs and scripts (#310) --- .github/workflows/ci-workflow.yml | 53 +++++++++++++++++++------- .github/workflows/release-workflow.yml | 35 +++++++++++++++++ .gitignore | 3 ++ .golangci.yml | 21 ++++------ .goreleaser.yaml | 51 +++++++++++++++++++++++++ .pre-commit-config.yaml | 2 +- .vscode/settings.json | 4 ++ go.mod | 2 +- scripts/apply-coverage-exclusions.sh | 34 +++++++++++++++++ scripts/coverage-exclusion-list.txt | 1 + 10 files changed, 177 insertions(+), 29 deletions(-) create mode 100644 .github/workflows/release-workflow.yml create mode 100644 .goreleaser.yaml create mode 100755 scripts/apply-coverage-exclusions.sh create mode 100644 scripts/coverage-exclusion-list.txt diff --git a/.github/workflows/ci-workflow.yml b/.github/workflows/ci-workflow.yml index ea2490d..4b86f13 100644 --- a/.github/workflows/ci-workflow.yml +++ b/.github/workflows/ci-workflow.yml @@ -1,4 +1,6 @@ name: Cobrass Continuous Integration + + on: push: @@ -7,43 +9,68 @@ jobs: name: lint runs-on: ubuntu-latest steps: - - uses: actions/setup-go@v3 + - uses: actions/setup-go@v4 with: - go-version: 1.22 + go-version: 1.23 - uses: actions/checkout@v3 - name: golangci-lint uses: golangci/golangci-lint-action@v3 with: - version: v1.56.2 + version: v1.60.3 args: --verbose test: strategy: matrix: - go-version: [1.22] + go-version: [1.23] platform: [ubuntu-latest, macos-latest] runs-on: ${{ matrix.platform }} + env: + COVER_DIR: ${{ github.workspace }}/coverage + COVER_FILE: coverage.out + COVER_OUT_PATH: ${{ github.workspace }}/coverage/coverage.out + COVER_HTML_PATH: ${{ github.workspace }}/coverage/coverage.html + GINKGO_REPORT: ginkgo.report + steps: - name: Install Go - uses: actions/setup-go@v3 + uses: actions/setup-go@v5 with: go-version: ${{ matrix.go-version }} - name: Install goveralls run: go install github.com/mattn/goveralls@latest + - name: Install ginkgo + run: go install github.com/onsi/ginkgo/v2/ginkgo@v2.20.2 + - name: Checkout code - uses: actions/checkout@v3 + uses: actions/checkout@v4 - - run: go test -v -coverprofile=coverage.out ./... + - name: Ensure coverage directory exists + run: | + mkdir -p ${{ github.workspace }}/coverage + + - name: Run tests and generate coverage profile with Ginkgo + run: | + ginkgo run -r -json-report {{env.GINKGO_REPORT}} -coverpkg=./... -coverprofile=coverage.out - - uses: shogo82148/actions-goveralls@v1 + - name: Apply coverage exclusions + run: | + ${{ github.workspace }}/scripts/apply-coverage-exclusions.sh + + - name: Check coverage directory contents + run: | + echo "Contents of ${{ github.workspace }}/coverage:" + ls -la ${{ github.workspace }}/coverage + + - name: Generate HTML coverage report + run: | + go tool cover -html=coverage.out -o ${{ github.workspace }}/coverage/coverage.html + + - name: Upload coverage to Coveralls + uses: shogo82148/actions-goveralls@v1 with: path-to-profile: coverage.out - - - name: Send coverage - env: - COVERALLS_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: goveralls -coverprofile=coverage.out -service=github diff --git a/.github/workflows/release-workflow.yml b/.github/workflows/release-workflow.yml new file mode 100644 index 0000000..c78ed17 --- /dev/null +++ b/.github/workflows/release-workflow.yml @@ -0,0 +1,35 @@ +name: Cobrass Release + +on: + push: + tags: + - '*' + +permissions: + contents: write + +jobs: + goreleaser: + if: startsWith(github.ref, 'refs/tags/') + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + - name: Git Fetch + run: git fetch --force --tags + - name: Setup + uses: actions/setup-go@v3 + with: + go-version: '>=1.23' + cache: true + - name: Generate Changelog Only + uses: goreleaser/goreleaser-action@v4 + with: + distribution: goreleaser + version: latest + args: release --clean + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.gitignore b/.gitignore index 9dbe56c..7fb94a8 100644 --- a/.gitignore +++ b/.gitignore @@ -23,7 +23,10 @@ generators/gola/out/ .env coverage +coverage.out ginkgo.report +report.json +coverage.html src/assistant/internal/l10n/out/translate.en-US.json diff --git a/.golangci.yml b/.golangci.yml index bd1c407..7ac922c 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -4,10 +4,6 @@ linters-settings: goconst: min-len: 2 min-occurrences: 3 - # since upgrading to v1.22.0 of go: - # ERRO [linters_context] gocritic: load embedded ruleguard - # rules: rules/rules.go:13: can't load fmt: setting an explicit GOROOT can fix this problem. - # gocritic: enabled-tags: - diagnostic @@ -16,43 +12,43 @@ linters-settings: - performance - style govet: - check-shadowing: true + shadow: true disable: - fieldalignment # too strict nolintlint: - require-explanation: true + require-explanation: false require-specific: true - linters: disable-all: true enable: - bodyclose + # - deadcode # depguard needs to be reviewed properly and then configured, before # it can be re-enabled. # https://github.com/OpenPeeDeeP/depguard#example-configs # - depguard + - copyloopvar - dogsled # - dupl - errcheck - - exportloopref - exhaustive - goconst - gocritic - gofmt - goimports - - gomnd - gocyclo - gosec - gosimple - govet - ineffassign - misspell + - mnd - nolintlint - nakedret - prealloc - predeclared - # - revive // over-bearing for generated code, too many instances + - revive - staticcheck # - structcheck - stylecheck @@ -72,8 +68,5 @@ issues: - "cuddle" run: - skip-dirs: - - /generators/gola/templates - skip-files: - - .*\.tmpl$ issues-exit-code: 1 + timeout: "5m" diff --git a/.goreleaser.yaml b/.goreleaser.yaml new file mode 100644 index 0000000..88d4f19 --- /dev/null +++ b/.goreleaser.yaml @@ -0,0 +1,51 @@ +before: + hooks: + - go mod tidy + # ? do we need a - go mod generate + # - go mod generate + +builds: + - id: "cobrass" + env: + - CGO_ENABLED=0 + goos: + - linux + - windows + - darwin + no_main_check: true + skip: true + +archives: + - format: tar.gz + # this name template makes the OS and Arch compatible with the results of uname. + name_template: >- + {{ .ProjectName }}_ + {{- title .Os }}_ + {{- if eq .Arch "amd64" }}x86_64 + {{- else if eq .Arch "386" }}i386 + {{- else }}{{ .Arch }}{{ end }} + {{- if .Arm }}v{{ .Arm }}{{ end }} + # use zip for windows archives + format_overrides: + - goos: windows + format: zip +checksum: + name_template: "checksums.txt" +snapshot: + name_template: "{{ incpatch .Version }}-next" +changelog: + use: github + sort: asc + filters: + exclude: + - "^docs:" + - "^test:" + groups: + - title: "๐Ÿš€ Features" + regexp: '^.*?feat(\([[:word:]]+\))??!?:.+$' + order: 0 + - title: "๐Ÿ› Bug fixes" + regexp: '^.*?fix(\([[:word:]]+\))??!?:.+$' + order: 1 + - title: "๐Ÿฅ Others" + order: 999 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index cd09558..f263848 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: https://github.com/golangci/golangci-lint - rev: v1.54.2 + rev: v1.56.2 hooks: - id: golangci-lint diff --git a/.vscode/settings.json b/.vscode/settings.json index e8d5a21..8a56925 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -12,6 +12,7 @@ "cogen", "colors", "Comparables", + "copyloopvar", "deadcode", "depguard", "dogsled", @@ -38,6 +39,7 @@ "gomega", "gomnd", "gomock", + "gomod", "GOROOT", "gosec", "gosimple", @@ -45,6 +47,7 @@ "govet", "gradientf", "gradientsf", + "incpatch", "ineffassign", "infex", "Infexion", @@ -56,6 +59,7 @@ "memfs", "mockgen", "nakedret", + "nefilim", "nicksnyder", "nolint", "nolintlint", diff --git a/go.mod b/go.mod index 465920b..7ce9b7f 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/snivilised/cobrass -go 1.22.0 +go 1.23.0 require ( github.com/avfs/avfs v0.33.0 diff --git a/scripts/apply-coverage-exclusions.sh b/scripts/apply-coverage-exclusions.sh new file mode 100755 index 0000000..9f3c6d6 --- /dev/null +++ b/scripts/apply-coverage-exclusions.sh @@ -0,0 +1,34 @@ +#!/bin/bash + +# Define paths relative to the root directory +ROOT_DIR="$(git rev-parse --show-toplevel)" +COVERAGE_FILE="$ROOT_DIR/coverage.out" +EXCLUSIONS_FILE="$ROOT_DIR/scripts/coverage-exclusion-list.txt" + +# Check if required files exist +if [ ! -f "$COVERAGE_FILE" ]; then + echo "Error: Coverage file not found at $COVERAGE_FILE" + exit 1 +fi + +if [ ! -f "$EXCLUSIONS_FILE" ]; then + echo "Error: Exclusions file not found at $EXCLUSIONS_FILE" + exit 1 +fi + +# Create a temporary file +TEMP_FILE=$(mktemp) + +# Process the exclusions +while IFS= read -r line || [[ -n "$line" ]]; do + # Escape special characters in the line for use in sed + escaped_line=$(echo "$line" | sed 's/[\/&]/\\&/g') + + # Remove matching lines from the coverage file + sed "/${escaped_line}/d" "$COVERAGE_FILE" > "$TEMP_FILE" + + # Replace the original file with the modified content + mv "$TEMP_FILE" "$COVERAGE_FILE" +done < "$EXCLUSIONS_FILE" + +echo "Coverage exclusions have been applied successfully." diff --git a/scripts/coverage-exclusion-list.txt b/scripts/coverage-exclusion-list.txt new file mode 100644 index 0000000..d3d9c76 --- /dev/null +++ b/scripts/coverage-exclusion-list.txt @@ -0,0 +1 @@ +github.com/snivilised/cobrass/src/internal/third From 6c4194837aafcb83cbee570df80c737f88cb0304 Mon Sep 17 00:00:00 2001 From: plastikfan Date: Thu, 24 Oct 2024 17:18:53 +0100 Subject: [PATCH 2/8] ref: rename i18n pkg to locale (#310) --- src/assistant/cobra-container.go | 16 +- src/assistant/enum.go | 6 +- src/assistant/get-third-party-cl_test.go | 4 +- .../default/cobrass.active.en.json | 0 .../deploy/cobrass.active.en-US.json | 0 src/assistant/{i18n => locale}/i18n-defs.go | 2 +- src/assistant/{i18n => locale}/i18n.go | 2 +- .../{i18n => locale}/i18n_suite_test.go | 2 +- .../{i18n => locale}/messages-command.go | 2 +- .../messages-native-errors.go | 2 +- .../messages-native-errors_test.go | 22 +- .../messages-validation-errors_test.go | 14 +- .../{i18n => locale}/messages-validation.go | 2 +- src/assistant/{i18n => locale}/utils.go | 2 +- src/assistant/option-validator-container.go | 4 +- .../param-set-binder-helpers-auto.go | 234 +++++++++--------- src/assistant/param-set.go | 4 +- src/store/families_test.go | 4 +- src/store/family-cascade.go | 6 +- src/store/family-filter.go | 24 +- src/store/family-i18n.go | 4 +- src/store/family-interactions.go | 6 +- src/store/family-preview.go | 4 +- src/store/family-profile.go | 6 +- src/store/family-sampling.go | 10 +- src/store/family-worker-pool.go | 6 +- 26 files changed, 194 insertions(+), 194 deletions(-) rename src/assistant/{i18n => locale}/default/cobrass.active.en.json (100%) rename src/assistant/{i18n => locale}/deploy/cobrass.active.en-US.json (100%) rename src/assistant/{i18n => locale}/i18n-defs.go (95%) rename src/assistant/{i18n => locale}/i18n.go (90%) rename src/assistant/{i18n => locale}/i18n_suite_test.go (92%) rename src/assistant/{i18n => locale}/messages-command.go (99%) rename src/assistant/{i18n => locale}/messages-native-errors.go (99%) rename src/assistant/{i18n => locale}/messages-native-errors_test.go (74%) rename src/assistant/{i18n => locale}/messages-validation-errors_test.go (82%) rename src/assistant/{i18n => locale}/messages-validation.go (99%) rename src/assistant/{i18n => locale}/utils.go (90%) diff --git a/src/assistant/cobra-container.go b/src/assistant/cobra-container.go index 0a0d317..80f6955 100644 --- a/src/assistant/cobra-container.go +++ b/src/assistant/cobra-container.go @@ -6,7 +6,7 @@ import ( "github.com/samber/lo" "github.com/spf13/cobra" - "github.com/snivilised/cobrass/src/assistant/i18n" + "github.com/snivilised/cobrass/src/assistant/locale" ) // CobraCommandSpec is a wrapper around the cobra command, require to register @@ -43,7 +43,7 @@ func NewCobraContainer(root *cobra.Command) *CobraContainer { func (container *CobraContainer) insert(command *cobra.Command) error { name := command.Name() if _, exists := container.commands[name]; exists { - return i18n.NewCommandAlreadyRegisteredNativeError(name) + return locale.NewCommandAlreadyRegisteredNativeError(name) } container.commands[name] = command @@ -68,7 +68,7 @@ func (container *CobraContainer) MustRegisterCommand(parent string, command *cob pc.AddCommand(command) } else { - panic(i18n.NewParentCommandNotRegisteredNativeError(parent)) + panic(locale.NewParentCommandNotRegisteredNativeError(parent)) } } @@ -130,19 +130,19 @@ func (container *CobraContainer) Command(name string) *cobra.Command { // an inappropriate type. func (container *CobraContainer) MustRegisterParamSet(name string, ps any) { if _, exists := container.paramSets[name]; exists { - panic(i18n.NewParamSetAlreadyRegisteredNativeError(name)) + panic(locale.NewParamSetAlreadyRegisteredNativeError(name)) } if reflect.TypeOf(ps).Kind() != reflect.Ptr { typeOf := reflect.TypeOf(ps) - panic(i18n.NewParamSetObjectMustBePointerNativeError(name, typeOf.String())) + panic(locale.NewParamSetObjectMustBePointerNativeError(name, typeOf.String())) } if reflect.TypeOf(ps).Elem().Kind() != reflect.Struct { typeOf := reflect.TypeOf(ps) - panic(i18n.NewParamSetObjectMustBeStructNativeError(name, typeOf.String())) + panic(locale.NewParamSetObjectMustBeStructNativeError(name, typeOf.String())) } container.paramSets[name] = ps @@ -162,7 +162,7 @@ func (container *CobraContainer) Native(name string) any { return paramSetStruct.FieldByName("Native").Interface() } - panic(i18n.NewParamSetNotFoundNativeError(name)) + panic(locale.NewParamSetNotFoundNativeError(name)) } // MustGetParamSet like Native, except that it returns the parameter set @@ -174,5 +174,5 @@ func (container *CobraContainer) MustGetParamSet(name string) any { return paramSet } - panic(i18n.NewParamSetNotFoundNativeError(name)) + panic(locale.NewParamSetNotFoundNativeError(name)) } diff --git a/src/assistant/enum.go b/src/assistant/enum.go index 608a85d..7b482b7 100644 --- a/src/assistant/enum.go +++ b/src/assistant/enum.go @@ -6,7 +6,7 @@ import ( "strings" "github.com/samber/lo" - "github.com/snivilised/cobrass/src/assistant/i18n" + "github.com/snivilised/cobrass/src/assistant/locale" ) // AcceptableEnumValues maps values of enum type to an array of @@ -104,7 +104,7 @@ func NewEnumInfo[E ~int](acceptables AcceptableEnumValues[E]) *EnumInfo[E] { for enum, values := range acceptables { for _, acc := range values { if existing, found := info.reverseLookup[acc]; found { - panic(i18n.NewEnumValueValueAlreadyExistsNativeError( + panic(locale.NewEnumValueValueAlreadyExistsNativeError( info.NameOf(existing), int(existing)), ) } @@ -264,7 +264,7 @@ func (ev *EnumValue[E]) IsValidOrEmpty() bool { // client needs to validate incoming input as performed in a binder operation. func (ev *EnumValue[E]) String() string { if _, found := ev.Info.reverseLookup[ev.Source]; !found { - panic(i18n.NewIsNotValidEnumValueNativeError(ev.Source)) + panic(locale.NewIsNotValidEnumValueNativeError(ev.Source)) } return ev.Source diff --git a/src/assistant/get-third-party-cl_test.go b/src/assistant/get-third-party-cl_test.go index 6d9b53f..0e339cc 100644 --- a/src/assistant/get-third-party-cl_test.go +++ b/src/assistant/get-third-party-cl_test.go @@ -9,7 +9,7 @@ import ( "github.com/snivilised/cobrass" "github.com/snivilised/cobrass/src/assistant" - "github.com/snivilised/cobrass/src/assistant/i18n" + "github.com/snivilised/cobrass/src/assistant/locale" "github.com/snivilised/cobrass/src/clif" "github.com/snivilised/cobrass/src/internal/helpers" "github.com/snivilised/cobrass/src/store" @@ -47,7 +47,7 @@ var _ = Describe("GetThirdPartyCL", Ordered, func() { from = xi18n.LoadFrom{ Path: l10nPath, Sources: xi18n.TranslationFiles{ - i18n.CobrassSourceID: xi18n.TranslationSource{Name: "test"}, + locale.CobrassSourceID: xi18n.TranslationSource{Name: "test"}, }, } diff --git a/src/assistant/i18n/default/cobrass.active.en.json b/src/assistant/locale/default/cobrass.active.en.json similarity index 100% rename from src/assistant/i18n/default/cobrass.active.en.json rename to src/assistant/locale/default/cobrass.active.en.json diff --git a/src/assistant/i18n/deploy/cobrass.active.en-US.json b/src/assistant/locale/deploy/cobrass.active.en-US.json similarity index 100% rename from src/assistant/i18n/deploy/cobrass.active.en-US.json rename to src/assistant/locale/deploy/cobrass.active.en-US.json diff --git a/src/assistant/i18n/i18n-defs.go b/src/assistant/locale/i18n-defs.go similarity index 95% rename from src/assistant/i18n/i18n-defs.go rename to src/assistant/locale/i18n-defs.go index 12306dd..b9af377 100644 --- a/src/assistant/i18n/i18n-defs.go +++ b/src/assistant/locale/i18n-defs.go @@ -1,4 +1,4 @@ -package i18n +package locale import ( "github.com/nicksnyder/go-i18n/v2/i18n" diff --git a/src/assistant/i18n/i18n.go b/src/assistant/locale/i18n.go similarity index 90% rename from src/assistant/i18n/i18n.go rename to src/assistant/locale/i18n.go index 8c10656..f7e0f89 100644 --- a/src/assistant/i18n/i18n.go +++ b/src/assistant/locale/i18n.go @@ -1,4 +1,4 @@ -package i18n +package locale import ( xi18n "github.com/snivilised/extendio/i18n" diff --git a/src/assistant/i18n/i18n_suite_test.go b/src/assistant/locale/i18n_suite_test.go similarity index 92% rename from src/assistant/i18n/i18n_suite_test.go rename to src/assistant/locale/i18n_suite_test.go index dac047d..fae3007 100644 --- a/src/assistant/i18n/i18n_suite_test.go +++ b/src/assistant/locale/i18n_suite_test.go @@ -1,4 +1,4 @@ -package i18n_test +package locale_test import ( "testing" diff --git a/src/assistant/i18n/messages-command.go b/src/assistant/locale/messages-command.go similarity index 99% rename from src/assistant/i18n/messages-command.go rename to src/assistant/locale/messages-command.go index df5e784..0c4f9d5 100644 --- a/src/assistant/i18n/messages-command.go +++ b/src/assistant/locale/messages-command.go @@ -1,4 +1,4 @@ -package i18n +package locale // FilesGlobParamUsageTemplData // ๐ŸงŠ diff --git a/src/assistant/i18n/messages-native-errors.go b/src/assistant/locale/messages-native-errors.go similarity index 99% rename from src/assistant/i18n/messages-native-errors.go rename to src/assistant/locale/messages-native-errors.go index 593b988..30a8894 100644 --- a/src/assistant/i18n/messages-native-errors.go +++ b/src/assistant/locale/messages-native-errors.go @@ -1,4 +1,4 @@ -package i18n +package locale import ( "fmt" diff --git a/src/assistant/i18n/messages-native-errors_test.go b/src/assistant/locale/messages-native-errors_test.go similarity index 74% rename from src/assistant/i18n/messages-native-errors_test.go rename to src/assistant/locale/messages-native-errors_test.go index 9bfd0ff..401cbb9 100644 --- a/src/assistant/i18n/messages-native-errors_test.go +++ b/src/assistant/locale/messages-native-errors_test.go @@ -1,4 +1,4 @@ -package i18n_test +package locale_test import ( "fmt" @@ -6,7 +6,7 @@ import ( . "github.com/onsi/ginkgo/v2" //nolint:revive // ginkgo ok . "github.com/onsi/gomega" //nolint:revive // gomega ok - "github.com/snivilised/cobrass/src/assistant/i18n" + "github.com/snivilised/cobrass/src/assistant/locale" "github.com/snivilised/cobrass/src/internal/helpers" ) @@ -30,55 +30,55 @@ var _ = Describe("MessagesNativeErrors", func() { Entry(nil, nativeEntry{ Name: "NewEnumValueValueAlreadyExistsNativeError", - Fn: i18n.NewEnumValueValueAlreadyExistsNativeError, + Fn: locale.NewEnumValueValueAlreadyExistsNativeError, Args: []any{"foo-bar", 2}, }), Entry(nil, nativeEntry{ Name: "NewIsNotValidEnumValueNativeError", - Fn: i18n.NewIsNotValidEnumValueNativeError, + Fn: locale.NewIsNotValidEnumValueNativeError, Args: []any{"foo-bar"}, }), Entry(nil, nativeEntry{ Name: "NewFailedToAddValidatorAlreadyExistsNativeError", - Fn: i18n.NewFailedToAddValidatorAlreadyExistsNativeError, + Fn: locale.NewFailedToAddValidatorAlreadyExistsNativeError, Args: []any{"foo-flag"}, }), Entry(nil, nativeEntry{ Name: "NewCommandAlreadyRegisteredNativeError", - Fn: i18n.NewCommandAlreadyRegisteredNativeError, + Fn: locale.NewCommandAlreadyRegisteredNativeError, Args: []any{"foo-name"}, }), Entry(nil, nativeEntry{ Name: "NewParentCommandNotRegisteredNativeError", - Fn: i18n.NewParentCommandNotRegisteredNativeError, + Fn: locale.NewParentCommandNotRegisteredNativeError, Args: []any{"foo-parent"}, }), Entry(nil, nativeEntry{ Name: "NewParamSetAlreadyRegisteredNativeError", - Fn: i18n.NewParamSetAlreadyRegisteredNativeError, + Fn: locale.NewParamSetAlreadyRegisteredNativeError, Args: []any{"foo-name"}, }), Entry(nil, nativeEntry{ Name: "NewParamSetObjectMustBeStructNativeError", - Fn: i18n.NewParamSetObjectMustBeStructNativeError, + Fn: locale.NewParamSetObjectMustBeStructNativeError, Args: []any{"foo-name", "foo-typ"}, }), Entry(nil, nativeEntry{ Name: "NewParamSetObjectMustBePointerNativeError", - Fn: i18n.NewParamSetObjectMustBePointerNativeError, + Fn: locale.NewParamSetObjectMustBePointerNativeError, Args: []any{"foo-pointer-name", "foo-pointer-typ"}, }), Entry(nil, nativeEntry{ Name: "NewParamSetNotFoundNativeError", - Fn: i18n.NewParamSetNotFoundNativeError, + Fn: locale.NewParamSetNotFoundNativeError, Args: []any{"foo-name"}, }), ) diff --git a/src/assistant/i18n/messages-validation-errors_test.go b/src/assistant/locale/messages-validation-errors_test.go similarity index 82% rename from src/assistant/i18n/messages-validation-errors_test.go rename to src/assistant/locale/messages-validation-errors_test.go index 844873a..d2851b8 100644 --- a/src/assistant/i18n/messages-validation-errors_test.go +++ b/src/assistant/locale/messages-validation-errors_test.go @@ -1,4 +1,4 @@ -package i18n_test +package locale_test import ( "fmt" @@ -6,7 +6,7 @@ import ( . "github.com/onsi/ginkgo/v2" //nolint:revive // ginkgo ok . "github.com/onsi/gomega" //nolint:revive // gomega ok - "github.com/snivilised/cobrass/src/assistant/i18n" + "github.com/snivilised/cobrass/src/assistant/locale" "github.com/snivilised/cobrass/src/internal/helpers" xi18n "github.com/snivilised/extendio/i18n" ) @@ -34,7 +34,7 @@ var _ = Describe("MessagesValidationErrors", Ordered, func() { from = xi18n.LoadFrom{ Path: l10nPath, Sources: xi18n.TranslationFiles{ - i18n.CobrassSourceID: xi18n.TranslationSource{Name: "test"}, + locale.CobrassSourceID: xi18n.TranslationSource{Name: "test"}, }, } @@ -59,10 +59,10 @@ var _ = Describe("MessagesValidationErrors", Ordered, func() { Entry(nil, validationEntry{ Name: "NewWithinOptValidationError", - Fn: i18n.NewWithinOptValidationError, + Fn: locale.NewWithinOptValidationError, Args: []any{"foo-flag", 1, 10, 20}, Verify: func(err error) bool { - if e, ok := err.(i18n.WithinOptValidationBehaviourQuery); ok { + if e, ok := err.(locale.WithinOptValidationBehaviourQuery); ok { return e.IsOutOfRange() } return false @@ -71,7 +71,7 @@ var _ = Describe("MessagesValidationErrors", Ordered, func() { Entry(nil, validationEntry{ Name: "NewNotWithinOptValidationError", - Fn: i18n.NewNotWithinOptValidationError, + Fn: locale.NewNotWithinOptValidationError, Args: []any{"foo-flag", 5, 10, 20}, Verify: func(_ error) bool { return true @@ -81,7 +81,7 @@ var _ = Describe("MessagesValidationErrors", Ordered, func() { Context("NewNotContainsOptValidationError", func() { It("should: create error", func() { - err := i18n.NewNotContainsOptValidationError("foo-flag", int(1), []int{2, 4, 6, 8}) + err := locale.NewNotContainsOptValidationError("foo-flag", int(1), []int{2, 4, 6, 8}) GinkgoWriter.Printf("๐Ÿ’ฅ๐Ÿ’ฅ๐Ÿ’ฅ ===> ERROR: '%v'", err) }) }) diff --git a/src/assistant/i18n/messages-validation.go b/src/assistant/locale/messages-validation.go similarity index 99% rename from src/assistant/i18n/messages-validation.go rename to src/assistant/locale/messages-validation.go index 43b1dfb..50f6d13 100644 --- a/src/assistant/i18n/messages-validation.go +++ b/src/assistant/locale/messages-validation.go @@ -1,4 +1,4 @@ -package i18n +package locale import ( "github.com/snivilised/extendio/i18n" diff --git a/src/assistant/i18n/utils.go b/src/assistant/locale/utils.go similarity index 90% rename from src/assistant/i18n/utils.go rename to src/assistant/locale/utils.go index 55a49d7..060d446 100644 --- a/src/assistant/i18n/utils.go +++ b/src/assistant/locale/utils.go @@ -1,4 +1,4 @@ -package i18n +package locale import ( "strings" diff --git a/src/assistant/option-validator-container.go b/src/assistant/option-validator-container.go index 8fe8489..604619a 100644 --- a/src/assistant/option-validator-container.go +++ b/src/assistant/option-validator-container.go @@ -1,7 +1,7 @@ package assistant import ( - "github.com/snivilised/cobrass/src/assistant/i18n" + "github.com/snivilised/cobrass/src/assistant/locale" ) type ValidatorCollection map[string]OptionValidator @@ -44,7 +44,7 @@ func NewValidatorContainer(options ...ValidatorContainerOptionFn) *ValidatorCont // already has a validator registered for it. func (container ValidatorContainer) Add(flag string, validator OptionValidator) { if _, found := container.validators[flag]; found { - panic(i18n.NewFailedToAddValidatorAlreadyExistsNativeError(flag)) + panic(locale.NewFailedToAddValidatorAlreadyExistsNativeError(flag)) } container.validators[flag] = validator diff --git a/src/assistant/param-set-binder-helpers-auto.go b/src/assistant/param-set-binder-helpers-auto.go index d918082..e398ef9 100644 --- a/src/assistant/param-set-binder-helpers-auto.go +++ b/src/assistant/param-set-binder-helpers-auto.go @@ -6,7 +6,7 @@ import ( "time" "github.com/samber/lo" - "github.com/snivilised/cobrass/src/assistant/i18n" + "github.com/snivilised/cobrass/src/assistant/locale" "github.com/spf13/pflag" ) @@ -28,7 +28,7 @@ func (params *ParamSet[N]) BindValidatedDurationWithin(info *FlagInfo, to *time. return nil } - return i18n.NewWithinOptValidationError(info.FlagName(), value, low, high) + return locale.NewWithinOptValidationError(info.FlagName(), value, low, high) }, Value: to, Flag: params.ResolveFlagSet(info).Lookup(info.Name), @@ -53,7 +53,7 @@ func (params *ParamSet[N]) BindValidatedDurationNotWithin(info *FlagInfo, to *ti return nil } - return i18n.NewNotWithinOptValidationError(info.FlagName(), value, low, high) + return locale.NewNotWithinOptValidationError(info.FlagName(), value, low, high) }, Value: to, Flag: params.ResolveFlagSet(info).Lookup(info.Name), @@ -78,7 +78,7 @@ func (params *ParamSet[N]) BindValidatedContainsDuration(info *FlagInfo, to *tim return nil } - return i18n.NewContainsOptValidationError(info.FlagName(), value, collection) + return locale.NewContainsOptValidationError(info.FlagName(), value, collection) }, Value: to, Flag: params.ResolveFlagSet(info).Lookup(info.Name), @@ -103,7 +103,7 @@ func (params *ParamSet[N]) BindValidatedNotContainsDuration(info *FlagInfo, to * return nil } - return i18n.NewNotContainsOptValidationError(info.FlagName(), value, collection) + return locale.NewNotContainsOptValidationError(info.FlagName(), value, collection) }, Value: to, Flag: params.ResolveFlagSet(info).Lookup(info.Name), @@ -128,7 +128,7 @@ func (params *ParamSet[N]) BindValidatedDurationGreaterThan(info *FlagInfo, to * return nil } - return i18n.NewGreaterThanOptValidationError(info.FlagName(), value, threshold) + return locale.NewGreaterThanOptValidationError(info.FlagName(), value, threshold) }, Value: to, Flag: params.ResolveFlagSet(info).Lookup(info.Name), @@ -153,7 +153,7 @@ func (params *ParamSet[N]) BindValidatedDurationAtLeast(info *FlagInfo, to *time return nil } - return i18n.NewAtLeastOptValidationError(info.FlagName(), value, threshold) + return locale.NewAtLeastOptValidationError(info.FlagName(), value, threshold) }, Value: to, Flag: params.ResolveFlagSet(info).Lookup(info.Name), @@ -178,7 +178,7 @@ func (params *ParamSet[N]) BindValidatedDurationLessThan(info *FlagInfo, to *tim return nil } - return i18n.NewLessThanOptValidationError(info.FlagName(), value, threshold) + return locale.NewLessThanOptValidationError(info.FlagName(), value, threshold) }, Value: to, Flag: params.ResolveFlagSet(info).Lookup(info.Name), @@ -203,7 +203,7 @@ func (params *ParamSet[N]) BindValidatedDurationAtMost(info *FlagInfo, to *time. return nil } - return i18n.NewAtMostOptValidationError(info.FlagName(), value, threshold) + return locale.NewAtMostOptValidationError(info.FlagName(), value, threshold) }, Value: to, Flag: params.ResolveFlagSet(info).Lookup(info.Name), @@ -228,7 +228,7 @@ func (params *ParamSet[N]) BindValidatedContainsEnum(info *FlagInfo, to *string, return nil } - return i18n.NewContainsOptValidationError(info.FlagName(), value, collection) + return locale.NewContainsOptValidationError(info.FlagName(), value, collection) }, Value: to, Flag: params.ResolveFlagSet(info).Lookup(info.Name), @@ -253,7 +253,7 @@ func (params *ParamSet[N]) BindValidatedNotContainsEnum(info *FlagInfo, to *stri return nil } - return i18n.NewNotContainsOptValidationError(info.FlagName(), value, collection) + return locale.NewNotContainsOptValidationError(info.FlagName(), value, collection) }, Value: to, Flag: params.ResolveFlagSet(info).Lookup(info.Name), @@ -278,7 +278,7 @@ func (params *ParamSet[N]) BindValidatedFloat32Within(info *FlagInfo, to *float3 return nil } - return i18n.NewWithinOptValidationError(info.FlagName(), value, low, high) + return locale.NewWithinOptValidationError(info.FlagName(), value, low, high) }, Value: to, Flag: params.ResolveFlagSet(info).Lookup(info.Name), @@ -303,7 +303,7 @@ func (params *ParamSet[N]) BindValidatedFloat32NotWithin(info *FlagInfo, to *flo return nil } - return i18n.NewNotWithinOptValidationError(info.FlagName(), value, low, high) + return locale.NewNotWithinOptValidationError(info.FlagName(), value, low, high) }, Value: to, Flag: params.ResolveFlagSet(info).Lookup(info.Name), @@ -328,7 +328,7 @@ func (params *ParamSet[N]) BindValidatedContainsFloat32(info *FlagInfo, to *floa return nil } - return i18n.NewContainsOptValidationError(info.FlagName(), value, collection) + return locale.NewContainsOptValidationError(info.FlagName(), value, collection) }, Value: to, Flag: params.ResolveFlagSet(info).Lookup(info.Name), @@ -353,7 +353,7 @@ func (params *ParamSet[N]) BindValidatedNotContainsFloat32(info *FlagInfo, to *f return nil } - return i18n.NewNotContainsOptValidationError(info.FlagName(), value, collection) + return locale.NewNotContainsOptValidationError(info.FlagName(), value, collection) }, Value: to, Flag: params.ResolveFlagSet(info).Lookup(info.Name), @@ -378,7 +378,7 @@ func (params *ParamSet[N]) BindValidatedFloat32GreaterThan(info *FlagInfo, to *f return nil } - return i18n.NewGreaterThanOptValidationError(info.FlagName(), value, threshold) + return locale.NewGreaterThanOptValidationError(info.FlagName(), value, threshold) }, Value: to, Flag: params.ResolveFlagSet(info).Lookup(info.Name), @@ -403,7 +403,7 @@ func (params *ParamSet[N]) BindValidatedFloat32AtLeast(info *FlagInfo, to *float return nil } - return i18n.NewAtLeastOptValidationError(info.FlagName(), value, threshold) + return locale.NewAtLeastOptValidationError(info.FlagName(), value, threshold) }, Value: to, Flag: params.ResolveFlagSet(info).Lookup(info.Name), @@ -428,7 +428,7 @@ func (params *ParamSet[N]) BindValidatedFloat32LessThan(info *FlagInfo, to *floa return nil } - return i18n.NewLessThanOptValidationError(info.FlagName(), value, threshold) + return locale.NewLessThanOptValidationError(info.FlagName(), value, threshold) }, Value: to, Flag: params.ResolveFlagSet(info).Lookup(info.Name), @@ -453,7 +453,7 @@ func (params *ParamSet[N]) BindValidatedFloat32AtMost(info *FlagInfo, to *float3 return nil } - return i18n.NewAtMostOptValidationError(info.FlagName(), value, threshold) + return locale.NewAtMostOptValidationError(info.FlagName(), value, threshold) }, Value: to, Flag: params.ResolveFlagSet(info).Lookup(info.Name), @@ -478,7 +478,7 @@ func (params *ParamSet[N]) BindValidatedFloat64Within(info *FlagInfo, to *float6 return nil } - return i18n.NewWithinOptValidationError(info.FlagName(), value, low, high) + return locale.NewWithinOptValidationError(info.FlagName(), value, low, high) }, Value: to, Flag: params.ResolveFlagSet(info).Lookup(info.Name), @@ -503,7 +503,7 @@ func (params *ParamSet[N]) BindValidatedFloat64NotWithin(info *FlagInfo, to *flo return nil } - return i18n.NewNotWithinOptValidationError(info.FlagName(), value, low, high) + return locale.NewNotWithinOptValidationError(info.FlagName(), value, low, high) }, Value: to, Flag: params.ResolveFlagSet(info).Lookup(info.Name), @@ -528,7 +528,7 @@ func (params *ParamSet[N]) BindValidatedContainsFloat64(info *FlagInfo, to *floa return nil } - return i18n.NewContainsOptValidationError(info.FlagName(), value, collection) + return locale.NewContainsOptValidationError(info.FlagName(), value, collection) }, Value: to, Flag: params.ResolveFlagSet(info).Lookup(info.Name), @@ -553,7 +553,7 @@ func (params *ParamSet[N]) BindValidatedNotContainsFloat64(info *FlagInfo, to *f return nil } - return i18n.NewNotContainsOptValidationError(info.FlagName(), value, collection) + return locale.NewNotContainsOptValidationError(info.FlagName(), value, collection) }, Value: to, Flag: params.ResolveFlagSet(info).Lookup(info.Name), @@ -578,7 +578,7 @@ func (params *ParamSet[N]) BindValidatedFloat64GreaterThan(info *FlagInfo, to *f return nil } - return i18n.NewGreaterThanOptValidationError(info.FlagName(), value, threshold) + return locale.NewGreaterThanOptValidationError(info.FlagName(), value, threshold) }, Value: to, Flag: params.ResolveFlagSet(info).Lookup(info.Name), @@ -603,7 +603,7 @@ func (params *ParamSet[N]) BindValidatedFloat64AtLeast(info *FlagInfo, to *float return nil } - return i18n.NewAtLeastOptValidationError(info.FlagName(), value, threshold) + return locale.NewAtLeastOptValidationError(info.FlagName(), value, threshold) }, Value: to, Flag: params.ResolveFlagSet(info).Lookup(info.Name), @@ -628,7 +628,7 @@ func (params *ParamSet[N]) BindValidatedFloat64LessThan(info *FlagInfo, to *floa return nil } - return i18n.NewLessThanOptValidationError(info.FlagName(), value, threshold) + return locale.NewLessThanOptValidationError(info.FlagName(), value, threshold) }, Value: to, Flag: params.ResolveFlagSet(info).Lookup(info.Name), @@ -653,7 +653,7 @@ func (params *ParamSet[N]) BindValidatedFloat64AtMost(info *FlagInfo, to *float6 return nil } - return i18n.NewAtMostOptValidationError(info.FlagName(), value, threshold) + return locale.NewAtMostOptValidationError(info.FlagName(), value, threshold) }, Value: to, Flag: params.ResolveFlagSet(info).Lookup(info.Name), @@ -678,7 +678,7 @@ func (params *ParamSet[N]) BindValidatedIntWithin(info *FlagInfo, to *int, low, return nil } - return i18n.NewWithinOptValidationError(info.FlagName(), value, low, high) + return locale.NewWithinOptValidationError(info.FlagName(), value, low, high) }, Value: to, Flag: params.ResolveFlagSet(info).Lookup(info.Name), @@ -703,7 +703,7 @@ func (params *ParamSet[N]) BindValidatedIntNotWithin(info *FlagInfo, to *int, lo return nil } - return i18n.NewNotWithinOptValidationError(info.FlagName(), value, low, high) + return locale.NewNotWithinOptValidationError(info.FlagName(), value, low, high) }, Value: to, Flag: params.ResolveFlagSet(info).Lookup(info.Name), @@ -728,7 +728,7 @@ func (params *ParamSet[N]) BindValidatedContainsInt(info *FlagInfo, to *int, col return nil } - return i18n.NewContainsOptValidationError(info.FlagName(), value, collection) + return locale.NewContainsOptValidationError(info.FlagName(), value, collection) }, Value: to, Flag: params.ResolveFlagSet(info).Lookup(info.Name), @@ -753,7 +753,7 @@ func (params *ParamSet[N]) BindValidatedNotContainsInt(info *FlagInfo, to *int, return nil } - return i18n.NewNotContainsOptValidationError(info.FlagName(), value, collection) + return locale.NewNotContainsOptValidationError(info.FlagName(), value, collection) }, Value: to, Flag: params.ResolveFlagSet(info).Lookup(info.Name), @@ -778,7 +778,7 @@ func (params *ParamSet[N]) BindValidatedIntGreaterThan(info *FlagInfo, to *int, return nil } - return i18n.NewGreaterThanOptValidationError(info.FlagName(), value, threshold) + return locale.NewGreaterThanOptValidationError(info.FlagName(), value, threshold) }, Value: to, Flag: params.ResolveFlagSet(info).Lookup(info.Name), @@ -803,7 +803,7 @@ func (params *ParamSet[N]) BindValidatedIntAtLeast(info *FlagInfo, to *int, thre return nil } - return i18n.NewAtLeastOptValidationError(info.FlagName(), value, threshold) + return locale.NewAtLeastOptValidationError(info.FlagName(), value, threshold) }, Value: to, Flag: params.ResolveFlagSet(info).Lookup(info.Name), @@ -828,7 +828,7 @@ func (params *ParamSet[N]) BindValidatedIntLessThan(info *FlagInfo, to *int, thr return nil } - return i18n.NewLessThanOptValidationError(info.FlagName(), value, threshold) + return locale.NewLessThanOptValidationError(info.FlagName(), value, threshold) }, Value: to, Flag: params.ResolveFlagSet(info).Lookup(info.Name), @@ -853,7 +853,7 @@ func (params *ParamSet[N]) BindValidatedIntAtMost(info *FlagInfo, to *int, thres return nil } - return i18n.NewAtMostOptValidationError(info.FlagName(), value, threshold) + return locale.NewAtMostOptValidationError(info.FlagName(), value, threshold) }, Value: to, Flag: params.ResolveFlagSet(info).Lookup(info.Name), @@ -878,7 +878,7 @@ func (params *ParamSet[N]) BindValidatedInt16Within(info *FlagInfo, to *int16, l return nil } - return i18n.NewWithinOptValidationError(info.FlagName(), value, low, high) + return locale.NewWithinOptValidationError(info.FlagName(), value, low, high) }, Value: to, Flag: params.ResolveFlagSet(info).Lookup(info.Name), @@ -903,7 +903,7 @@ func (params *ParamSet[N]) BindValidatedInt16NotWithin(info *FlagInfo, to *int16 return nil } - return i18n.NewNotWithinOptValidationError(info.FlagName(), value, low, high) + return locale.NewNotWithinOptValidationError(info.FlagName(), value, low, high) }, Value: to, Flag: params.ResolveFlagSet(info).Lookup(info.Name), @@ -928,7 +928,7 @@ func (params *ParamSet[N]) BindValidatedContainsInt16(info *FlagInfo, to *int16, return nil } - return i18n.NewContainsOptValidationError(info.FlagName(), value, collection) + return locale.NewContainsOptValidationError(info.FlagName(), value, collection) }, Value: to, Flag: params.ResolveFlagSet(info).Lookup(info.Name), @@ -953,7 +953,7 @@ func (params *ParamSet[N]) BindValidatedNotContainsInt16(info *FlagInfo, to *int return nil } - return i18n.NewNotContainsOptValidationError(info.FlagName(), value, collection) + return locale.NewNotContainsOptValidationError(info.FlagName(), value, collection) }, Value: to, Flag: params.ResolveFlagSet(info).Lookup(info.Name), @@ -978,7 +978,7 @@ func (params *ParamSet[N]) BindValidatedInt16GreaterThan(info *FlagInfo, to *int return nil } - return i18n.NewGreaterThanOptValidationError(info.FlagName(), value, threshold) + return locale.NewGreaterThanOptValidationError(info.FlagName(), value, threshold) }, Value: to, Flag: params.ResolveFlagSet(info).Lookup(info.Name), @@ -1003,7 +1003,7 @@ func (params *ParamSet[N]) BindValidatedInt16AtLeast(info *FlagInfo, to *int16, return nil } - return i18n.NewAtLeastOptValidationError(info.FlagName(), value, threshold) + return locale.NewAtLeastOptValidationError(info.FlagName(), value, threshold) }, Value: to, Flag: params.ResolveFlagSet(info).Lookup(info.Name), @@ -1028,7 +1028,7 @@ func (params *ParamSet[N]) BindValidatedInt16LessThan(info *FlagInfo, to *int16, return nil } - return i18n.NewLessThanOptValidationError(info.FlagName(), value, threshold) + return locale.NewLessThanOptValidationError(info.FlagName(), value, threshold) }, Value: to, Flag: params.ResolveFlagSet(info).Lookup(info.Name), @@ -1053,7 +1053,7 @@ func (params *ParamSet[N]) BindValidatedInt16AtMost(info *FlagInfo, to *int16, t return nil } - return i18n.NewAtMostOptValidationError(info.FlagName(), value, threshold) + return locale.NewAtMostOptValidationError(info.FlagName(), value, threshold) }, Value: to, Flag: params.ResolveFlagSet(info).Lookup(info.Name), @@ -1078,7 +1078,7 @@ func (params *ParamSet[N]) BindValidatedInt32Within(info *FlagInfo, to *int32, l return nil } - return i18n.NewWithinOptValidationError(info.FlagName(), value, low, high) + return locale.NewWithinOptValidationError(info.FlagName(), value, low, high) }, Value: to, Flag: params.ResolveFlagSet(info).Lookup(info.Name), @@ -1103,7 +1103,7 @@ func (params *ParamSet[N]) BindValidatedInt32NotWithin(info *FlagInfo, to *int32 return nil } - return i18n.NewNotWithinOptValidationError(info.FlagName(), value, low, high) + return locale.NewNotWithinOptValidationError(info.FlagName(), value, low, high) }, Value: to, Flag: params.ResolveFlagSet(info).Lookup(info.Name), @@ -1128,7 +1128,7 @@ func (params *ParamSet[N]) BindValidatedContainsInt32(info *FlagInfo, to *int32, return nil } - return i18n.NewContainsOptValidationError(info.FlagName(), value, collection) + return locale.NewContainsOptValidationError(info.FlagName(), value, collection) }, Value: to, Flag: params.ResolveFlagSet(info).Lookup(info.Name), @@ -1153,7 +1153,7 @@ func (params *ParamSet[N]) BindValidatedNotContainsInt32(info *FlagInfo, to *int return nil } - return i18n.NewNotContainsOptValidationError(info.FlagName(), value, collection) + return locale.NewNotContainsOptValidationError(info.FlagName(), value, collection) }, Value: to, Flag: params.ResolveFlagSet(info).Lookup(info.Name), @@ -1178,7 +1178,7 @@ func (params *ParamSet[N]) BindValidatedInt32GreaterThan(info *FlagInfo, to *int return nil } - return i18n.NewGreaterThanOptValidationError(info.FlagName(), value, threshold) + return locale.NewGreaterThanOptValidationError(info.FlagName(), value, threshold) }, Value: to, Flag: params.ResolveFlagSet(info).Lookup(info.Name), @@ -1203,7 +1203,7 @@ func (params *ParamSet[N]) BindValidatedInt32AtLeast(info *FlagInfo, to *int32, return nil } - return i18n.NewAtLeastOptValidationError(info.FlagName(), value, threshold) + return locale.NewAtLeastOptValidationError(info.FlagName(), value, threshold) }, Value: to, Flag: params.ResolveFlagSet(info).Lookup(info.Name), @@ -1228,7 +1228,7 @@ func (params *ParamSet[N]) BindValidatedInt32LessThan(info *FlagInfo, to *int32, return nil } - return i18n.NewLessThanOptValidationError(info.FlagName(), value, threshold) + return locale.NewLessThanOptValidationError(info.FlagName(), value, threshold) }, Value: to, Flag: params.ResolveFlagSet(info).Lookup(info.Name), @@ -1253,7 +1253,7 @@ func (params *ParamSet[N]) BindValidatedInt32AtMost(info *FlagInfo, to *int32, t return nil } - return i18n.NewAtMostOptValidationError(info.FlagName(), value, threshold) + return locale.NewAtMostOptValidationError(info.FlagName(), value, threshold) }, Value: to, Flag: params.ResolveFlagSet(info).Lookup(info.Name), @@ -1278,7 +1278,7 @@ func (params *ParamSet[N]) BindValidatedInt64Within(info *FlagInfo, to *int64, l return nil } - return i18n.NewWithinOptValidationError(info.FlagName(), value, low, high) + return locale.NewWithinOptValidationError(info.FlagName(), value, low, high) }, Value: to, Flag: params.ResolveFlagSet(info).Lookup(info.Name), @@ -1303,7 +1303,7 @@ func (params *ParamSet[N]) BindValidatedInt64NotWithin(info *FlagInfo, to *int64 return nil } - return i18n.NewNotWithinOptValidationError(info.FlagName(), value, low, high) + return locale.NewNotWithinOptValidationError(info.FlagName(), value, low, high) }, Value: to, Flag: params.ResolveFlagSet(info).Lookup(info.Name), @@ -1328,7 +1328,7 @@ func (params *ParamSet[N]) BindValidatedContainsInt64(info *FlagInfo, to *int64, return nil } - return i18n.NewContainsOptValidationError(info.FlagName(), value, collection) + return locale.NewContainsOptValidationError(info.FlagName(), value, collection) }, Value: to, Flag: params.ResolveFlagSet(info).Lookup(info.Name), @@ -1353,7 +1353,7 @@ func (params *ParamSet[N]) BindValidatedNotContainsInt64(info *FlagInfo, to *int return nil } - return i18n.NewNotContainsOptValidationError(info.FlagName(), value, collection) + return locale.NewNotContainsOptValidationError(info.FlagName(), value, collection) }, Value: to, Flag: params.ResolveFlagSet(info).Lookup(info.Name), @@ -1378,7 +1378,7 @@ func (params *ParamSet[N]) BindValidatedInt64GreaterThan(info *FlagInfo, to *int return nil } - return i18n.NewGreaterThanOptValidationError(info.FlagName(), value, threshold) + return locale.NewGreaterThanOptValidationError(info.FlagName(), value, threshold) }, Value: to, Flag: params.ResolveFlagSet(info).Lookup(info.Name), @@ -1403,7 +1403,7 @@ func (params *ParamSet[N]) BindValidatedInt64AtLeast(info *FlagInfo, to *int64, return nil } - return i18n.NewAtLeastOptValidationError(info.FlagName(), value, threshold) + return locale.NewAtLeastOptValidationError(info.FlagName(), value, threshold) }, Value: to, Flag: params.ResolveFlagSet(info).Lookup(info.Name), @@ -1428,7 +1428,7 @@ func (params *ParamSet[N]) BindValidatedInt64LessThan(info *FlagInfo, to *int64, return nil } - return i18n.NewLessThanOptValidationError(info.FlagName(), value, threshold) + return locale.NewLessThanOptValidationError(info.FlagName(), value, threshold) }, Value: to, Flag: params.ResolveFlagSet(info).Lookup(info.Name), @@ -1453,7 +1453,7 @@ func (params *ParamSet[N]) BindValidatedInt64AtMost(info *FlagInfo, to *int64, t return nil } - return i18n.NewAtMostOptValidationError(info.FlagName(), value, threshold) + return locale.NewAtMostOptValidationError(info.FlagName(), value, threshold) }, Value: to, Flag: params.ResolveFlagSet(info).Lookup(info.Name), @@ -1478,7 +1478,7 @@ func (params *ParamSet[N]) BindValidatedInt8Within(info *FlagInfo, to *int8, low return nil } - return i18n.NewWithinOptValidationError(info.FlagName(), value, low, high) + return locale.NewWithinOptValidationError(info.FlagName(), value, low, high) }, Value: to, Flag: params.ResolveFlagSet(info).Lookup(info.Name), @@ -1503,7 +1503,7 @@ func (params *ParamSet[N]) BindValidatedInt8NotWithin(info *FlagInfo, to *int8, return nil } - return i18n.NewNotWithinOptValidationError(info.FlagName(), value, low, high) + return locale.NewNotWithinOptValidationError(info.FlagName(), value, low, high) }, Value: to, Flag: params.ResolveFlagSet(info).Lookup(info.Name), @@ -1528,7 +1528,7 @@ func (params *ParamSet[N]) BindValidatedContainsInt8(info *FlagInfo, to *int8, c return nil } - return i18n.NewContainsOptValidationError(info.FlagName(), value, collection) + return locale.NewContainsOptValidationError(info.FlagName(), value, collection) }, Value: to, Flag: params.ResolveFlagSet(info).Lookup(info.Name), @@ -1553,7 +1553,7 @@ func (params *ParamSet[N]) BindValidatedNotContainsInt8(info *FlagInfo, to *int8 return nil } - return i18n.NewNotContainsOptValidationError(info.FlagName(), value, collection) + return locale.NewNotContainsOptValidationError(info.FlagName(), value, collection) }, Value: to, Flag: params.ResolveFlagSet(info).Lookup(info.Name), @@ -1578,7 +1578,7 @@ func (params *ParamSet[N]) BindValidatedInt8GreaterThan(info *FlagInfo, to *int8 return nil } - return i18n.NewGreaterThanOptValidationError(info.FlagName(), value, threshold) + return locale.NewGreaterThanOptValidationError(info.FlagName(), value, threshold) }, Value: to, Flag: params.ResolveFlagSet(info).Lookup(info.Name), @@ -1603,7 +1603,7 @@ func (params *ParamSet[N]) BindValidatedInt8AtLeast(info *FlagInfo, to *int8, th return nil } - return i18n.NewAtLeastOptValidationError(info.FlagName(), value, threshold) + return locale.NewAtLeastOptValidationError(info.FlagName(), value, threshold) }, Value: to, Flag: params.ResolveFlagSet(info).Lookup(info.Name), @@ -1628,7 +1628,7 @@ func (params *ParamSet[N]) BindValidatedInt8LessThan(info *FlagInfo, to *int8, t return nil } - return i18n.NewLessThanOptValidationError(info.FlagName(), value, threshold) + return locale.NewLessThanOptValidationError(info.FlagName(), value, threshold) }, Value: to, Flag: params.ResolveFlagSet(info).Lookup(info.Name), @@ -1653,7 +1653,7 @@ func (params *ParamSet[N]) BindValidatedInt8AtMost(info *FlagInfo, to *int8, thr return nil } - return i18n.NewAtMostOptValidationError(info.FlagName(), value, threshold) + return locale.NewAtMostOptValidationError(info.FlagName(), value, threshold) }, Value: to, Flag: params.ResolveFlagSet(info).Lookup(info.Name), @@ -1678,7 +1678,7 @@ func (params *ParamSet[N]) BindValidatedStringWithin(info *FlagInfo, to *string, return nil } - return i18n.NewWithinOptValidationError(info.FlagName(), value, low, high) + return locale.NewWithinOptValidationError(info.FlagName(), value, low, high) }, Value: to, Flag: params.ResolveFlagSet(info).Lookup(info.Name), @@ -1703,7 +1703,7 @@ func (params *ParamSet[N]) BindValidatedStringNotWithin(info *FlagInfo, to *stri return nil } - return i18n.NewNotWithinOptValidationError(info.FlagName(), value, low, high) + return locale.NewNotWithinOptValidationError(info.FlagName(), value, low, high) }, Value: to, Flag: params.ResolveFlagSet(info).Lookup(info.Name), @@ -1728,7 +1728,7 @@ func (params *ParamSet[N]) BindValidatedContainsString(info *FlagInfo, to *strin return nil } - return i18n.NewContainsOptValidationError(info.FlagName(), value, collection) + return locale.NewContainsOptValidationError(info.FlagName(), value, collection) }, Value: to, Flag: params.ResolveFlagSet(info).Lookup(info.Name), @@ -1753,7 +1753,7 @@ func (params *ParamSet[N]) BindValidatedNotContainsString(info *FlagInfo, to *st return nil } - return i18n.NewNotContainsOptValidationError(info.FlagName(), value, collection) + return locale.NewNotContainsOptValidationError(info.FlagName(), value, collection) }, Value: to, Flag: params.ResolveFlagSet(info).Lookup(info.Name), @@ -1778,7 +1778,7 @@ func (params *ParamSet[N]) BindValidatedStringIsMatch(info *FlagInfo, to *string return nil } - return i18n.NewMatchOptValidationError(info.FlagName(), value, pattern) + return locale.NewMatchOptValidationError(info.FlagName(), value, pattern) }, Value: to, Flag: params.ResolveFlagSet(info).Lookup(info.Name), @@ -1803,7 +1803,7 @@ func (params *ParamSet[N]) BindValidatedStringIsNotMatch(info *FlagInfo, to *str return nil } - return i18n.NewNotMatchOptValidationError(info.FlagName(), value, pattern) + return locale.NewNotMatchOptValidationError(info.FlagName(), value, pattern) }, Value: to, Flag: params.ResolveFlagSet(info).Lookup(info.Name), @@ -1828,7 +1828,7 @@ func (params *ParamSet[N]) BindValidatedStringGreaterThan(info *FlagInfo, to *st return nil } - return i18n.NewGreaterThanOptValidationError(info.FlagName(), value, threshold) + return locale.NewGreaterThanOptValidationError(info.FlagName(), value, threshold) }, Value: to, Flag: params.ResolveFlagSet(info).Lookup(info.Name), @@ -1853,7 +1853,7 @@ func (params *ParamSet[N]) BindValidatedStringAtLeast(info *FlagInfo, to *string return nil } - return i18n.NewAtLeastOptValidationError(info.FlagName(), value, threshold) + return locale.NewAtLeastOptValidationError(info.FlagName(), value, threshold) }, Value: to, Flag: params.ResolveFlagSet(info).Lookup(info.Name), @@ -1878,7 +1878,7 @@ func (params *ParamSet[N]) BindValidatedStringLessThan(info *FlagInfo, to *strin return nil } - return i18n.NewLessThanOptValidationError(info.FlagName(), value, threshold) + return locale.NewLessThanOptValidationError(info.FlagName(), value, threshold) }, Value: to, Flag: params.ResolveFlagSet(info).Lookup(info.Name), @@ -1903,7 +1903,7 @@ func (params *ParamSet[N]) BindValidatedStringAtMost(info *FlagInfo, to *string, return nil } - return i18n.NewAtMostOptValidationError(info.FlagName(), value, threshold) + return locale.NewAtMostOptValidationError(info.FlagName(), value, threshold) }, Value: to, Flag: params.ResolveFlagSet(info).Lookup(info.Name), @@ -1928,7 +1928,7 @@ func (params *ParamSet[N]) BindValidatedUint16Within(info *FlagInfo, to *uint16, return nil } - return i18n.NewWithinOptValidationError(info.FlagName(), value, low, high) + return locale.NewWithinOptValidationError(info.FlagName(), value, low, high) }, Value: to, Flag: params.ResolveFlagSet(info).Lookup(info.Name), @@ -1953,7 +1953,7 @@ func (params *ParamSet[N]) BindValidatedUint16NotWithin(info *FlagInfo, to *uint return nil } - return i18n.NewNotWithinOptValidationError(info.FlagName(), value, low, high) + return locale.NewNotWithinOptValidationError(info.FlagName(), value, low, high) }, Value: to, Flag: params.ResolveFlagSet(info).Lookup(info.Name), @@ -1978,7 +1978,7 @@ func (params *ParamSet[N]) BindValidatedContainsUint16(info *FlagInfo, to *uint1 return nil } - return i18n.NewContainsOptValidationError(info.FlagName(), value, collection) + return locale.NewContainsOptValidationError(info.FlagName(), value, collection) }, Value: to, Flag: params.ResolveFlagSet(info).Lookup(info.Name), @@ -2003,7 +2003,7 @@ func (params *ParamSet[N]) BindValidatedNotContainsUint16(info *FlagInfo, to *ui return nil } - return i18n.NewNotContainsOptValidationError(info.FlagName(), value, collection) + return locale.NewNotContainsOptValidationError(info.FlagName(), value, collection) }, Value: to, Flag: params.ResolveFlagSet(info).Lookup(info.Name), @@ -2028,7 +2028,7 @@ func (params *ParamSet[N]) BindValidatedUint16GreaterThan(info *FlagInfo, to *ui return nil } - return i18n.NewGreaterThanOptValidationError(info.FlagName(), value, threshold) + return locale.NewGreaterThanOptValidationError(info.FlagName(), value, threshold) }, Value: to, Flag: params.ResolveFlagSet(info).Lookup(info.Name), @@ -2053,7 +2053,7 @@ func (params *ParamSet[N]) BindValidatedUint16AtLeast(info *FlagInfo, to *uint16 return nil } - return i18n.NewAtLeastOptValidationError(info.FlagName(), value, threshold) + return locale.NewAtLeastOptValidationError(info.FlagName(), value, threshold) }, Value: to, Flag: params.ResolveFlagSet(info).Lookup(info.Name), @@ -2078,7 +2078,7 @@ func (params *ParamSet[N]) BindValidatedUint16LessThan(info *FlagInfo, to *uint1 return nil } - return i18n.NewLessThanOptValidationError(info.FlagName(), value, threshold) + return locale.NewLessThanOptValidationError(info.FlagName(), value, threshold) }, Value: to, Flag: params.ResolveFlagSet(info).Lookup(info.Name), @@ -2103,7 +2103,7 @@ func (params *ParamSet[N]) BindValidatedUint16AtMost(info *FlagInfo, to *uint16, return nil } - return i18n.NewAtMostOptValidationError(info.FlagName(), value, threshold) + return locale.NewAtMostOptValidationError(info.FlagName(), value, threshold) }, Value: to, Flag: params.ResolveFlagSet(info).Lookup(info.Name), @@ -2128,7 +2128,7 @@ func (params *ParamSet[N]) BindValidatedUint32Within(info *FlagInfo, to *uint32, return nil } - return i18n.NewWithinOptValidationError(info.FlagName(), value, low, high) + return locale.NewWithinOptValidationError(info.FlagName(), value, low, high) }, Value: to, Flag: params.ResolveFlagSet(info).Lookup(info.Name), @@ -2153,7 +2153,7 @@ func (params *ParamSet[N]) BindValidatedUint32NotWithin(info *FlagInfo, to *uint return nil } - return i18n.NewNotWithinOptValidationError(info.FlagName(), value, low, high) + return locale.NewNotWithinOptValidationError(info.FlagName(), value, low, high) }, Value: to, Flag: params.ResolveFlagSet(info).Lookup(info.Name), @@ -2178,7 +2178,7 @@ func (params *ParamSet[N]) BindValidatedContainsUint32(info *FlagInfo, to *uint3 return nil } - return i18n.NewContainsOptValidationError(info.FlagName(), value, collection) + return locale.NewContainsOptValidationError(info.FlagName(), value, collection) }, Value: to, Flag: params.ResolveFlagSet(info).Lookup(info.Name), @@ -2203,7 +2203,7 @@ func (params *ParamSet[N]) BindValidatedNotContainsUint32(info *FlagInfo, to *ui return nil } - return i18n.NewNotContainsOptValidationError(info.FlagName(), value, collection) + return locale.NewNotContainsOptValidationError(info.FlagName(), value, collection) }, Value: to, Flag: params.ResolveFlagSet(info).Lookup(info.Name), @@ -2228,7 +2228,7 @@ func (params *ParamSet[N]) BindValidatedUint32GreaterThan(info *FlagInfo, to *ui return nil } - return i18n.NewGreaterThanOptValidationError(info.FlagName(), value, threshold) + return locale.NewGreaterThanOptValidationError(info.FlagName(), value, threshold) }, Value: to, Flag: params.ResolveFlagSet(info).Lookup(info.Name), @@ -2253,7 +2253,7 @@ func (params *ParamSet[N]) BindValidatedUint32AtLeast(info *FlagInfo, to *uint32 return nil } - return i18n.NewAtLeastOptValidationError(info.FlagName(), value, threshold) + return locale.NewAtLeastOptValidationError(info.FlagName(), value, threshold) }, Value: to, Flag: params.ResolveFlagSet(info).Lookup(info.Name), @@ -2278,7 +2278,7 @@ func (params *ParamSet[N]) BindValidatedUint32LessThan(info *FlagInfo, to *uint3 return nil } - return i18n.NewLessThanOptValidationError(info.FlagName(), value, threshold) + return locale.NewLessThanOptValidationError(info.FlagName(), value, threshold) }, Value: to, Flag: params.ResolveFlagSet(info).Lookup(info.Name), @@ -2303,7 +2303,7 @@ func (params *ParamSet[N]) BindValidatedUint32AtMost(info *FlagInfo, to *uint32, return nil } - return i18n.NewAtMostOptValidationError(info.FlagName(), value, threshold) + return locale.NewAtMostOptValidationError(info.FlagName(), value, threshold) }, Value: to, Flag: params.ResolveFlagSet(info).Lookup(info.Name), @@ -2328,7 +2328,7 @@ func (params *ParamSet[N]) BindValidatedUint64Within(info *FlagInfo, to *uint64, return nil } - return i18n.NewWithinOptValidationError(info.FlagName(), value, low, high) + return locale.NewWithinOptValidationError(info.FlagName(), value, low, high) }, Value: to, Flag: params.ResolveFlagSet(info).Lookup(info.Name), @@ -2353,7 +2353,7 @@ func (params *ParamSet[N]) BindValidatedUint64NotWithin(info *FlagInfo, to *uint return nil } - return i18n.NewNotWithinOptValidationError(info.FlagName(), value, low, high) + return locale.NewNotWithinOptValidationError(info.FlagName(), value, low, high) }, Value: to, Flag: params.ResolveFlagSet(info).Lookup(info.Name), @@ -2378,7 +2378,7 @@ func (params *ParamSet[N]) BindValidatedContainsUint64(info *FlagInfo, to *uint6 return nil } - return i18n.NewContainsOptValidationError(info.FlagName(), value, collection) + return locale.NewContainsOptValidationError(info.FlagName(), value, collection) }, Value: to, Flag: params.ResolveFlagSet(info).Lookup(info.Name), @@ -2403,7 +2403,7 @@ func (params *ParamSet[N]) BindValidatedNotContainsUint64(info *FlagInfo, to *ui return nil } - return i18n.NewNotContainsOptValidationError(info.FlagName(), value, collection) + return locale.NewNotContainsOptValidationError(info.FlagName(), value, collection) }, Value: to, Flag: params.ResolveFlagSet(info).Lookup(info.Name), @@ -2428,7 +2428,7 @@ func (params *ParamSet[N]) BindValidatedUint64GreaterThan(info *FlagInfo, to *ui return nil } - return i18n.NewGreaterThanOptValidationError(info.FlagName(), value, threshold) + return locale.NewGreaterThanOptValidationError(info.FlagName(), value, threshold) }, Value: to, Flag: params.ResolveFlagSet(info).Lookup(info.Name), @@ -2453,7 +2453,7 @@ func (params *ParamSet[N]) BindValidatedUint64AtLeast(info *FlagInfo, to *uint64 return nil } - return i18n.NewAtLeastOptValidationError(info.FlagName(), value, threshold) + return locale.NewAtLeastOptValidationError(info.FlagName(), value, threshold) }, Value: to, Flag: params.ResolveFlagSet(info).Lookup(info.Name), @@ -2478,7 +2478,7 @@ func (params *ParamSet[N]) BindValidatedUint64LessThan(info *FlagInfo, to *uint6 return nil } - return i18n.NewLessThanOptValidationError(info.FlagName(), value, threshold) + return locale.NewLessThanOptValidationError(info.FlagName(), value, threshold) }, Value: to, Flag: params.ResolveFlagSet(info).Lookup(info.Name), @@ -2503,7 +2503,7 @@ func (params *ParamSet[N]) BindValidatedUint64AtMost(info *FlagInfo, to *uint64, return nil } - return i18n.NewAtMostOptValidationError(info.FlagName(), value, threshold) + return locale.NewAtMostOptValidationError(info.FlagName(), value, threshold) }, Value: to, Flag: params.ResolveFlagSet(info).Lookup(info.Name), @@ -2528,7 +2528,7 @@ func (params *ParamSet[N]) BindValidatedUint8Within(info *FlagInfo, to *uint8, l return nil } - return i18n.NewWithinOptValidationError(info.FlagName(), value, low, high) + return locale.NewWithinOptValidationError(info.FlagName(), value, low, high) }, Value: to, Flag: params.ResolveFlagSet(info).Lookup(info.Name), @@ -2553,7 +2553,7 @@ func (params *ParamSet[N]) BindValidatedUint8NotWithin(info *FlagInfo, to *uint8 return nil } - return i18n.NewNotWithinOptValidationError(info.FlagName(), value, low, high) + return locale.NewNotWithinOptValidationError(info.FlagName(), value, low, high) }, Value: to, Flag: params.ResolveFlagSet(info).Lookup(info.Name), @@ -2578,7 +2578,7 @@ func (params *ParamSet[N]) BindValidatedContainsUint8(info *FlagInfo, to *uint8, return nil } - return i18n.NewContainsOptValidationError(info.FlagName(), value, collection) + return locale.NewContainsOptValidationError(info.FlagName(), value, collection) }, Value: to, Flag: params.ResolveFlagSet(info).Lookup(info.Name), @@ -2603,7 +2603,7 @@ func (params *ParamSet[N]) BindValidatedNotContainsUint8(info *FlagInfo, to *uin return nil } - return i18n.NewNotContainsOptValidationError(info.FlagName(), value, collection) + return locale.NewNotContainsOptValidationError(info.FlagName(), value, collection) }, Value: to, Flag: params.ResolveFlagSet(info).Lookup(info.Name), @@ -2628,7 +2628,7 @@ func (params *ParamSet[N]) BindValidatedUint8GreaterThan(info *FlagInfo, to *uin return nil } - return i18n.NewGreaterThanOptValidationError(info.FlagName(), value, threshold) + return locale.NewGreaterThanOptValidationError(info.FlagName(), value, threshold) }, Value: to, Flag: params.ResolveFlagSet(info).Lookup(info.Name), @@ -2653,7 +2653,7 @@ func (params *ParamSet[N]) BindValidatedUint8AtLeast(info *FlagInfo, to *uint8, return nil } - return i18n.NewAtLeastOptValidationError(info.FlagName(), value, threshold) + return locale.NewAtLeastOptValidationError(info.FlagName(), value, threshold) }, Value: to, Flag: params.ResolveFlagSet(info).Lookup(info.Name), @@ -2678,7 +2678,7 @@ func (params *ParamSet[N]) BindValidatedUint8LessThan(info *FlagInfo, to *uint8, return nil } - return i18n.NewLessThanOptValidationError(info.FlagName(), value, threshold) + return locale.NewLessThanOptValidationError(info.FlagName(), value, threshold) }, Value: to, Flag: params.ResolveFlagSet(info).Lookup(info.Name), @@ -2703,7 +2703,7 @@ func (params *ParamSet[N]) BindValidatedUint8AtMost(info *FlagInfo, to *uint8, t return nil } - return i18n.NewAtMostOptValidationError(info.FlagName(), value, threshold) + return locale.NewAtMostOptValidationError(info.FlagName(), value, threshold) }, Value: to, Flag: params.ResolveFlagSet(info).Lookup(info.Name), @@ -2728,7 +2728,7 @@ func (params *ParamSet[N]) BindValidatedUintWithin(info *FlagInfo, to *uint, low return nil } - return i18n.NewWithinOptValidationError(info.FlagName(), value, low, high) + return locale.NewWithinOptValidationError(info.FlagName(), value, low, high) }, Value: to, Flag: params.ResolveFlagSet(info).Lookup(info.Name), @@ -2753,7 +2753,7 @@ func (params *ParamSet[N]) BindValidatedUintNotWithin(info *FlagInfo, to *uint, return nil } - return i18n.NewNotWithinOptValidationError(info.FlagName(), value, low, high) + return locale.NewNotWithinOptValidationError(info.FlagName(), value, low, high) }, Value: to, Flag: params.ResolveFlagSet(info).Lookup(info.Name), @@ -2778,7 +2778,7 @@ func (params *ParamSet[N]) BindValidatedContainsUint(info *FlagInfo, to *uint, c return nil } - return i18n.NewContainsOptValidationError(info.FlagName(), value, collection) + return locale.NewContainsOptValidationError(info.FlagName(), value, collection) }, Value: to, Flag: params.ResolveFlagSet(info).Lookup(info.Name), @@ -2803,7 +2803,7 @@ func (params *ParamSet[N]) BindValidatedNotContainsUint(info *FlagInfo, to *uint return nil } - return i18n.NewNotContainsOptValidationError(info.FlagName(), value, collection) + return locale.NewNotContainsOptValidationError(info.FlagName(), value, collection) }, Value: to, Flag: params.ResolveFlagSet(info).Lookup(info.Name), @@ -2828,7 +2828,7 @@ func (params *ParamSet[N]) BindValidatedUintGreaterThan(info *FlagInfo, to *uint return nil } - return i18n.NewGreaterThanOptValidationError(info.FlagName(), value, threshold) + return locale.NewGreaterThanOptValidationError(info.FlagName(), value, threshold) }, Value: to, Flag: params.ResolveFlagSet(info).Lookup(info.Name), @@ -2853,7 +2853,7 @@ func (params *ParamSet[N]) BindValidatedUintAtLeast(info *FlagInfo, to *uint, th return nil } - return i18n.NewAtLeastOptValidationError(info.FlagName(), value, threshold) + return locale.NewAtLeastOptValidationError(info.FlagName(), value, threshold) }, Value: to, Flag: params.ResolveFlagSet(info).Lookup(info.Name), @@ -2878,7 +2878,7 @@ func (params *ParamSet[N]) BindValidatedUintLessThan(info *FlagInfo, to *uint, t return nil } - return i18n.NewLessThanOptValidationError(info.FlagName(), value, threshold) + return locale.NewLessThanOptValidationError(info.FlagName(), value, threshold) }, Value: to, Flag: params.ResolveFlagSet(info).Lookup(info.Name), @@ -2903,7 +2903,7 @@ func (params *ParamSet[N]) BindValidatedUintAtMost(info *FlagInfo, to *uint, thr return nil } - return i18n.NewAtMostOptValidationError(info.FlagName(), value, threshold) + return locale.NewAtMostOptValidationError(info.FlagName(), value, threshold) }, Value: to, Flag: params.ResolveFlagSet(info).Lookup(info.Name), diff --git a/src/assistant/param-set.go b/src/assistant/param-set.go index 5fdf5ae..7759b61 100644 --- a/src/assistant/param-set.go +++ b/src/assistant/param-set.go @@ -5,7 +5,7 @@ import ( "strings" "github.com/samber/lo" - "github.com/snivilised/cobrass/src/assistant/i18n" + "github.com/snivilised/cobrass/src/assistant/locale" "github.com/spf13/cobra" "github.com/spf13/pflag" ) @@ -150,7 +150,7 @@ func NewParamSet[N any](command *cobra.Command) (ps *ParamSet[N]) { typeName := reflect.TypeOf(*ps.Native).Name() panic( - i18n.NewParamSetObjectMustBeStructNativeError(command.Name(), typeName), + locale.NewParamSetObjectMustBeStructNativeError(command.Name(), typeName), ) } diff --git a/src/store/families_test.go b/src/store/families_test.go index 9aacba9..0195875 100644 --- a/src/store/families_test.go +++ b/src/store/families_test.go @@ -8,7 +8,7 @@ import ( "github.com/spf13/cobra" "github.com/snivilised/cobrass/src/assistant" - "github.com/snivilised/cobrass/src/assistant/i18n" + "github.com/snivilised/cobrass/src/assistant/locale" "github.com/snivilised/cobrass/src/internal/helpers" "github.com/snivilised/cobrass/src/store" xi18n "github.com/snivilised/extendio/i18n" @@ -50,7 +50,7 @@ var _ = Describe("Families", Ordered, func() { from = xi18n.LoadFrom{ Path: l10nPath, Sources: xi18n.TranslationFiles{ - i18n.CobrassSourceID: xi18n.TranslationSource{Name: "test"}, + locale.CobrassSourceID: xi18n.TranslationSource{Name: "test"}, }, } diff --git a/src/store/family-cascade.go b/src/store/family-cascade.go index 7b537e3..f0b078a 100644 --- a/src/store/family-cascade.go +++ b/src/store/family-cascade.go @@ -2,7 +2,7 @@ package store import ( "github.com/snivilised/cobrass/src/assistant" - "github.com/snivilised/cobrass/src/assistant/i18n" + "github.com/snivilised/cobrass/src/assistant/locale" xi18n "github.com/snivilised/extendio/i18n" "github.com/spf13/pflag" ) @@ -24,7 +24,7 @@ func (f *CascadeParameterSet) BindAll( parent.BindUint( resolveNewFlagInfo( - xi18n.Text(i18n.CascadeDepthParamUsageTemplData{}), + xi18n.Text(locale.CascadeDepthParamUsageTemplData{}), defaultDepth, flagSet..., ), @@ -39,7 +39,7 @@ func (f *CascadeParameterSet) BindAll( parent.BindBool( resolveNewFlagInfo( - xi18n.Text(i18n.CascadeNoRecurseParamUsageTemplData{}), + xi18n.Text(locale.CascadeNoRecurseParamUsageTemplData{}), defaultNoRecurse, flagSet..., ), diff --git a/src/store/family-filter.go b/src/store/family-filter.go index aa59501..2b7779d 100644 --- a/src/store/family-filter.go +++ b/src/store/family-filter.go @@ -4,7 +4,7 @@ import ( "regexp" "github.com/snivilised/cobrass/src/assistant" - "github.com/snivilised/cobrass/src/assistant/i18n" + "github.com/snivilised/cobrass/src/assistant/locale" xi18n "github.com/snivilised/extendio/i18n" "github.com/spf13/pflag" ) @@ -50,7 +50,7 @@ func (f *FilesFilterParameterSet) BindAll( // parent.BindString( resolveNewFlagInfo( - xi18n.Text(i18n.FilesExGlobParamUsageTemplData{}), + xi18n.Text(locale.FilesExGlobParamUsageTemplData{}), defaultFilterValue, flagSet..., ), @@ -61,7 +61,7 @@ func (f *FilesFilterParameterSet) BindAll( // parent.BindString( resolveNewFlagInfo( - xi18n.Text(i18n.FilesGlobParamUsageTemplData{}), + xi18n.Text(locale.FilesGlobParamUsageTemplData{}), defaultFilterValue, flagSet..., ), @@ -72,7 +72,7 @@ func (f *FilesFilterParameterSet) BindAll( // parent.BindValidatedString( resolveNewFlagInfo( - xi18n.Text(i18n.FilesRegExParamUsageTemplData{}), + xi18n.Text(locale.FilesRegExParamUsageTemplData{}), defaultFilterValue, flagSet..., ), @@ -103,7 +103,7 @@ func (f *FoldersFilterParameterSet) BindAll( // parent.BindString( resolveNewFlagInfo( - xi18n.Text(i18n.FoldersGlobParamUsageTemplData{}), + xi18n.Text(locale.FoldersGlobParamUsageTemplData{}), defaultFilterValue, flagSet..., ), @@ -114,7 +114,7 @@ func (f *FoldersFilterParameterSet) BindAll( // parent.BindValidatedString( resolveNewFlagInfo( - xi18n.Text(i18n.FoldersRexExParamUsageTemplData{}), + xi18n.Text(locale.FoldersRexExParamUsageTemplData{}), defaultFilterValue, flagSet..., ), @@ -147,7 +147,7 @@ func (f *PolyFilterParameterSet) BindAll( // parent.BindString( resolveNewFlagInfo( - xi18n.Text(i18n.FilesExGlobParamUsageTemplData{}), + xi18n.Text(locale.FilesExGlobParamUsageTemplData{}), defaultFilterValue, flagSet..., ), @@ -158,7 +158,7 @@ func (f *PolyFilterParameterSet) BindAll( // parent.BindValidatedString( resolveNewFlagInfo( - xi18n.Text(i18n.FilesRegExParamUsageTemplData{}), + xi18n.Text(locale.FilesRegExParamUsageTemplData{}), defaultFilterValue, flagSet..., ), @@ -173,7 +173,7 @@ func (f *PolyFilterParameterSet) BindAll( // parent.BindString( resolveNewFlagInfo( - xi18n.Text(i18n.FoldersGlobParamUsageTemplData{}), + xi18n.Text(locale.FoldersGlobParamUsageTemplData{}), defaultFilterValue, flagSet..., ), @@ -184,7 +184,7 @@ func (f *PolyFilterParameterSet) BindAll( // parent.BindValidatedString( resolveNewFlagInfo( - xi18n.Text(i18n.FoldersRexExParamUsageTemplData{}), + xi18n.Text(locale.FoldersRexExParamUsageTemplData{}), defaultFilterValue, flagSet..., ), @@ -215,7 +215,7 @@ func (f *AlloyFilterParameterSet) BindAll( // parent.BindString( resolveNewFlagInfo( - xi18n.Text(i18n.FilesExGlobParamUsageTemplData{}), + xi18n.Text(locale.FilesExGlobParamUsageTemplData{}), defaultFilterValue, flagSet..., ), @@ -226,7 +226,7 @@ func (f *AlloyFilterParameterSet) BindAll( // parent.BindString( resolveNewFlagInfo( - xi18n.Text(i18n.FoldersGlobParamUsageTemplData{}), + xi18n.Text(locale.FoldersGlobParamUsageTemplData{}), defaultFilterValue, flagSet..., ), diff --git a/src/store/family-i18n.go b/src/store/family-i18n.go index 5849de4..380602f 100644 --- a/src/store/family-i18n.go +++ b/src/store/family-i18n.go @@ -2,7 +2,7 @@ package store import ( "github.com/snivilised/cobrass/src/assistant" - "github.com/snivilised/cobrass/src/assistant/i18n" + "github.com/snivilised/cobrass/src/assistant/locale" xi18n "github.com/snivilised/extendio/i18n" "github.com/spf13/pflag" "golang.org/x/text/language" @@ -24,7 +24,7 @@ func (f *I18nParameterSet) BindAll( parent.BindValidatedString( resolveNewFlagInfo( - xi18n.Text(i18n.LanguageParamUsageTemplData{}), + xi18n.Text(locale.LanguageParamUsageTemplData{}), defaultLanguage, flagSet..., ), diff --git a/src/store/family-interactions.go b/src/store/family-interactions.go index 782db25..f2fb4f3 100644 --- a/src/store/family-interactions.go +++ b/src/store/family-interactions.go @@ -2,7 +2,7 @@ package store import ( "github.com/snivilised/cobrass/src/assistant" - "github.com/snivilised/cobrass/src/assistant/i18n" + "github.com/snivilised/cobrass/src/assistant/locale" xi18n "github.com/snivilised/extendio/i18n" "github.com/spf13/pflag" ) @@ -23,7 +23,7 @@ func (f *TextualInteractionParameterSet) BindAll( parent.BindBool( resolveNewFlagInfo( - xi18n.Text(i18n.TextualInteractionIsNoTUIUsageTemplData{}), + xi18n.Text(locale.TextualInteractionIsNoTUIUsageTemplData{}), defNoTUI, flagSet..., ), @@ -47,7 +47,7 @@ func (f *CliInteractionParameterSet) BindAll( parent.BindBool( resolveNewFlagInfo( - xi18n.Text(i18n.CliInteractionIsTUIUsageTemplData{}), + xi18n.Text(locale.CliInteractionIsTUIUsageTemplData{}), defIsTUI, flagSet..., ), diff --git a/src/store/family-preview.go b/src/store/family-preview.go index 6818b32..73aa058 100644 --- a/src/store/family-preview.go +++ b/src/store/family-preview.go @@ -2,7 +2,7 @@ package store import ( "github.com/snivilised/cobrass/src/assistant" - "github.com/snivilised/cobrass/src/assistant/i18n" + "github.com/snivilised/cobrass/src/assistant/locale" xi18n "github.com/snivilised/extendio/i18n" "github.com/spf13/pflag" ) @@ -23,7 +23,7 @@ func (f *PreviewParameterSet) BindAll( parent.BindBool( resolveNewFlagInfo( - xi18n.Text(i18n.DryRunParamUsageTemplData{}), + xi18n.Text(locale.DryRunParamUsageTemplData{}), defaultDryRun, flagSet..., ), diff --git a/src/store/family-profile.go b/src/store/family-profile.go index e91adf2..553a8ff 100644 --- a/src/store/family-profile.go +++ b/src/store/family-profile.go @@ -2,7 +2,7 @@ package store import ( "github.com/snivilised/cobrass/src/assistant" - "github.com/snivilised/cobrass/src/assistant/i18n" + "github.com/snivilised/cobrass/src/assistant/locale" xi18n "github.com/snivilised/extendio/i18n" "github.com/spf13/pflag" ) @@ -24,7 +24,7 @@ func (f *ProfileParameterSet) BindAll( parent.BindValidatedStringIsMatch( resolveNewFlagInfo( - xi18n.Text(i18n.ProfileParamUsageTemplData{}), + xi18n.Text(locale.ProfileParamUsageTemplData{}), defaultProfile, flagSet..., ), @@ -40,7 +40,7 @@ func (f *ProfileParameterSet) BindAll( parent.BindString( resolveNewFlagInfo( - xi18n.Text(i18n.SchemeParamUsageTemplData{}), + xi18n.Text(locale.SchemeParamUsageTemplData{}), defaultScheme, flagSet..., ), diff --git a/src/store/family-sampling.go b/src/store/family-sampling.go index abcf15c..3c68949 100644 --- a/src/store/family-sampling.go +++ b/src/store/family-sampling.go @@ -2,7 +2,7 @@ package store import ( "github.com/snivilised/cobrass/src/assistant" - "github.com/snivilised/cobrass/src/assistant/i18n" + "github.com/snivilised/cobrass/src/assistant/locale" xi18n "github.com/snivilised/extendio/i18n" "github.com/spf13/pflag" ) @@ -26,7 +26,7 @@ func (f *SamplingParameterSet) BindAll( // parent.BindBool( resolveNewFlagInfo( - xi18n.Text(i18n.SamplingSampleUsageTemplData{}), + xi18n.Text(locale.SamplingSampleUsageTemplData{}), defIsSampling, flagSet..., ), @@ -43,7 +43,7 @@ func (f *SamplingParameterSet) BindAll( // parent.BindValidatedUintWithin( resolveNewFlagInfo( - xi18n.Text(i18n.SamplingNoFilesUsageTemplData{}), + xi18n.Text(locale.SamplingNoFilesUsageTemplData{}), defFSItems, flagSet..., ), @@ -56,7 +56,7 @@ func (f *SamplingParameterSet) BindAll( // parent.BindValidatedUintWithin( resolveNewFlagInfo( - xi18n.Text(i18n.SamplingNoFoldersUsageTemplData{}), + xi18n.Text(locale.SamplingNoFoldersUsageTemplData{}), defFSItems, flagSet..., ), @@ -73,7 +73,7 @@ func (f *SamplingParameterSet) BindAll( // parent.BindBool( resolveNewFlagInfo( - xi18n.Text(i18n.SamplingLastUsageTemplData{}), + xi18n.Text(locale.SamplingLastUsageTemplData{}), defIsLast, flagSet..., ), diff --git a/src/store/family-worker-pool.go b/src/store/family-worker-pool.go index c5746d6..b5d4b41 100644 --- a/src/store/family-worker-pool.go +++ b/src/store/family-worker-pool.go @@ -2,7 +2,7 @@ package store import ( "github.com/snivilised/cobrass/src/assistant" - "github.com/snivilised/cobrass/src/assistant/i18n" + "github.com/snivilised/cobrass/src/assistant/locale" xi18n "github.com/snivilised/extendio/i18n" "github.com/spf13/pflag" ) @@ -24,7 +24,7 @@ func (f *WorkerPoolParameterSet) BindAll( parent.BindBool( resolveNewFlagInfo( - xi18n.Text(i18n.WorkerPoolCPUParamUsageTemplData{}), + xi18n.Text(locale.WorkerPoolCPUParamUsageTemplData{}), defaultCPU, flagSet..., ), @@ -41,7 +41,7 @@ func (f *WorkerPoolParameterSet) BindAll( parent.BindValidatedIntWithin( resolveNewFlagInfo( - xi18n.Text(i18n.WorkerPoolNoWParamUsageTemplData{}), + xi18n.Text(locale.WorkerPoolNoWParamUsageTemplData{}), defaultNoW, flagSet..., ), From 74c01a78e403f352aae8a3aa00183f34e825ba75 Mon Sep 17 00:00:00 2001 From: plastikfan Date: Thu, 24 Oct 2024 17:31:17 +0100 Subject: [PATCH 3/8] ref: use go-i18n message defs directly (#310) --- ..._suite_test.go => assistant-suite_test.go} | 0 src/assistant/cobra-container_test.go | 4 +- src/assistant/locale/i18n-defs.go | 6 -- src/assistant/locale/messages-command.go | 84 ++++++++++--------- src/assistant/locale/messages-validation.go | 47 ++++++----- 5 files changed, 70 insertions(+), 71 deletions(-) rename src/assistant/{assistant_suite_test.go => assistant-suite_test.go} (100%) diff --git a/src/assistant/assistant_suite_test.go b/src/assistant/assistant-suite_test.go similarity index 100% rename from src/assistant/assistant_suite_test.go rename to src/assistant/assistant-suite_test.go diff --git a/src/assistant/cobra-container_test.go b/src/assistant/cobra-container_test.go index b73b1bd..f654186 100644 --- a/src/assistant/cobra-container_test.go +++ b/src/assistant/cobra-container_test.go @@ -115,7 +115,7 @@ var _ = Describe("CobraContainer", func() { }) When("requested command NOT previously registered", func() { - It("๐Ÿงช should: register requesyted command ok", func() { + It("๐Ÿงช should: register requested command ok", func() { name := DummyCommand.Name() parent := ParentCommand.Name() Container.MustRegisterRootedCommand(ParentCommand) @@ -136,7 +136,7 @@ var _ = Describe("CobraContainer", func() { }() Container.MustRegisterCommand("foo", DummyCommand) - Fail("โŒ expected panic due to parent not being regsitered") + Fail("โŒ expected panic due to parent not being registered") }) }) }) diff --git a/src/assistant/locale/i18n-defs.go b/src/assistant/locale/i18n-defs.go index b9af377..c41d65d 100644 --- a/src/assistant/locale/i18n-defs.go +++ b/src/assistant/locale/i18n-defs.go @@ -1,9 +1,5 @@ package locale -import ( - "github.com/nicksnyder/go-i18n/v2/i18n" -) - const CobrassSourceID = "github.com/snivilised/cobrass" // These definitions are in support of extendio's Localisable @@ -14,5 +10,3 @@ type CobrassTemplData struct{} func (td CobrassTemplData) SourceID() string { return CobrassSourceID } - -type Message = i18n.Message diff --git a/src/assistant/locale/messages-command.go b/src/assistant/locale/messages-command.go index 0c4f9d5..6c0181d 100644 --- a/src/assistant/locale/messages-command.go +++ b/src/assistant/locale/messages-command.go @@ -1,13 +1,17 @@ package locale +import ( + "github.com/nicksnyder/go-i18n/v2/i18n" +) + // FilesGlobParamUsageTemplData // ๐ŸงŠ type FilesGlobParamUsageTemplData struct { CobrassTemplData } -func (td FilesGlobParamUsageTemplData) Message() *Message { - return &Message{ +func (td FilesGlobParamUsageTemplData) Message() *i18n.Message { + return &i18n.Message{ ID: "files-glob-filter.param-usage", Description: "files glob filter (negate-able with leading !)", Other: "files-gb files glob filter (negate-able with leading !)", @@ -20,8 +24,8 @@ type FilesRegExParamUsageTemplData struct { CobrassTemplData } -func (td FilesRegExParamUsageTemplData) Message() *Message { - return &Message{ +func (td FilesRegExParamUsageTemplData) Message() *i18n.Message { + return &i18n.Message{ ID: "files-regex-filter.param-usage", Description: "files regex filter (negate-able with leading !)", Other: "files-rx folder regular expression filter (negate-able with leading !)", @@ -34,8 +38,8 @@ type FilesExGlobParamUsageTemplData struct { CobrassTemplData } -func (td FilesExGlobParamUsageTemplData) Message() *Message { - return &Message{ +func (td FilesExGlobParamUsageTemplData) Message() *i18n.Message { + return &i18n.Message{ ID: "files-ex-glob-filter.param-usage", Description: "files extended glob filter (negate-able with leading !)", Other: "files extended glob filter: | (negate-able with leading !)", @@ -48,8 +52,8 @@ type FoldersExGlobParamUsageTemplData struct { CobrassTemplData } -func (td FoldersExGlobParamUsageTemplData) Message() *Message { - return &Message{ +func (td FoldersExGlobParamUsageTemplData) Message() *i18n.Message { + return &i18n.Message{ ID: "folders-ex-glob-filter.param-usage", Description: "folders extended glob filter (negate-able with leading !)", Other: "folders extended glob filter: (negate-able with leading !)", @@ -62,8 +66,8 @@ type FoldersGlobParamUsageTemplData struct { CobrassTemplData } -func (td FoldersGlobParamUsageTemplData) Message() *Message { - return &Message{ +func (td FoldersGlobParamUsageTemplData) Message() *i18n.Message { + return &i18n.Message{ ID: "folders-glob-filter.param-usage", Description: "folders glob (negate-able with leading !)", Other: "folders-gb folder glob filter (negate-able with leading !)", @@ -76,8 +80,8 @@ type FoldersRexExParamUsageTemplData struct { CobrassTemplData } -func (td FoldersRexExParamUsageTemplData) Message() *Message { - return &Message{ +func (td FoldersRexExParamUsageTemplData) Message() *i18n.Message { + return &i18n.Message{ ID: "folders-regex-filter.param-usage", Description: "folders regex filter (negate-able with leading !)", Other: "folders-rx folder regular expression filter (negate-able with leading !)", @@ -90,8 +94,8 @@ type WorkerPoolCPUParamUsageTemplData struct { CobrassTemplData } -func (td WorkerPoolCPUParamUsageTemplData) Message() *Message { - return &Message{ +func (td WorkerPoolCPUParamUsageTemplData) Message() *i18n.Message { + return &i18n.Message{ ID: "worker-pool-cpu.param-usage", Description: "run with the number of workers in pool set to number of CPUs available", Other: "cpu denotes parallel execution with all available processors", @@ -104,8 +108,8 @@ type WorkerPoolNoWParamUsageTemplData struct { CobrassTemplData } -func (td WorkerPoolNoWParamUsageTemplData) Message() *Message { - return &Message{ +func (td WorkerPoolNoWParamUsageTemplData) Message() *i18n.Message { + return &i18n.Message{ ID: "worker-pool-cpu.param-usage", Description: "run with the number of workers in pool set to this number", Other: "now denotes parallel execution with this number of workers in pool", @@ -118,8 +122,8 @@ type ProfileParamUsageTemplData struct { CobrassTemplData } -func (td ProfileParamUsageTemplData) Message() *Message { - return &Message{ +func (td ProfileParamUsageTemplData) Message() *i18n.Message { + return &i18n.Message{ ID: "profile.param-usage", Description: "pre-defined flag/option list in config file", Other: "profile specifies which set of flags/options to load from config", @@ -132,8 +136,8 @@ type SchemeParamUsageTemplData struct { CobrassTemplData } -func (td SchemeParamUsageTemplData) Message() *Message { - return &Message{ +func (td SchemeParamUsageTemplData) Message() *i18n.Message { + return &i18n.Message{ ID: "scheme.param-usage", Description: "scheme is a collection of profiles, typically to repeat an operation over", Other: "scheme is a collection of profiles, typically to repeat an operation over", @@ -146,8 +150,8 @@ type DryRunParamUsageTemplData struct { CobrassTemplData } -func (td DryRunParamUsageTemplData) Message() *Message { - return &Message{ +func (td DryRunParamUsageTemplData) Message() *i18n.Message { + return &i18n.Message{ ID: "dry-run.param-usage", Description: "allows the user to preview the effects of a command without running it", Other: "dry-run allows the user to see the effects of a command without running it", @@ -160,8 +164,8 @@ type LanguageParamUsageTemplData struct { CobrassTemplData } -func (td LanguageParamUsageTemplData) Message() *Message { - return &Message{ +func (td LanguageParamUsageTemplData) Message() *i18n.Message { + return &i18n.Message{ ID: "language.param-usage", Description: "language allows the user to override the language the app runs in", Other: "language allows the user to override the language the app runs in", @@ -174,8 +178,8 @@ type CascadeDepthParamUsageTemplData struct { CobrassTemplData } -func (td CascadeDepthParamUsageTemplData) Message() *Message { - return &Message{ +func (td CascadeDepthParamUsageTemplData) Message() *i18n.Message { + return &i18n.Message{ ID: "cascade-depth.param-usage", Description: "limits the number of sub directories navigated", Other: "depth denotes the number of sub directories to navigate", @@ -188,8 +192,8 @@ type CascadeNoRecurseParamUsageTemplData struct { CobrassTemplData } -func (td CascadeNoRecurseParamUsageTemplData) Message() *Message { - return &Message{ +func (td CascadeNoRecurseParamUsageTemplData) Message() *i18n.Message { + return &i18n.Message{ ID: "cascade-no-recurse.param-usage", Description: "sets the navigator to not descend into sub directories", Other: "no-recurse sets the navigator to not descend into sub directories", @@ -202,8 +206,8 @@ type SamplingSampleUsageTemplData struct { CobrassTemplData } -func (td SamplingSampleUsageTemplData) Message() *Message { - return &Message{ +func (td SamplingSampleUsageTemplData) Message() *i18n.Message { + return &i18n.Message{ ID: "sampling-sample.param-usage", Description: "sampling sample usage; activates sampling", Other: "sample is a flag that activates sampling", @@ -216,8 +220,8 @@ type SamplingNoFilesUsageTemplData struct { CobrassTemplData } -func (td SamplingNoFilesUsageTemplData) Message() *Message { - return &Message{ +func (td SamplingNoFilesUsageTemplData) Message() *i18n.Message { + return &i18n.Message{ ID: "sampling-no-files.param-usage", Description: "sampling files usage; no of files in sample set", Other: "no-files specifies the number of files to sample", @@ -230,8 +234,8 @@ type SamplingNoFoldersUsageTemplData struct { CobrassTemplData } -func (td SamplingNoFoldersUsageTemplData) Message() *Message { - return &Message{ +func (td SamplingNoFoldersUsageTemplData) Message() *i18n.Message { + return &i18n.Message{ ID: "sampling-no-folders.param-usage", Description: "sampling folders usage; no of folders in sample set", Other: "no-folders specifies the number of folders to sample", @@ -244,8 +248,8 @@ type SamplingLastUsageTemplData struct { CobrassTemplData } -func (td SamplingLastUsageTemplData) Message() *Message { - return &Message{ +func (td SamplingLastUsageTemplData) Message() *i18n.Message { + return &i18n.Message{ ID: "sampling-last.param-usage", Description: "sampling last usage; indicates which n items are to be sampled", Other: "last is a flag that indicates last n items are to be sampled instead of the first", @@ -258,8 +262,8 @@ type TextualInteractionIsNoTUIUsageTemplData struct { CobrassTemplData } -func (td TextualInteractionIsNoTUIUsageTemplData) Message() *Message { - return &Message{ +func (td TextualInteractionIsNoTUIUsageTemplData) Message() *i18n.Message { + return &i18n.Message{ ID: "textual-interaction-is-no-tui.param-usage", Description: "textual interaction is no-tui usage; deactivates tui mode", Other: "no-tui is a flag that turns off tui mode", @@ -272,8 +276,8 @@ type CliInteractionIsTUIUsageTemplData struct { CobrassTemplData } -func (td CliInteractionIsTUIUsageTemplData) Message() *Message { - return &Message{ +func (td CliInteractionIsTUIUsageTemplData) Message() *i18n.Message { + return &i18n.Message{ ID: "cli-interaction-is-tui.param-usage", Description: "tui interaction is tui usage; activates tui mode", Other: "tui is a flag that enables tui mode", diff --git a/src/assistant/locale/messages-validation.go b/src/assistant/locale/messages-validation.go index 50f6d13..66d674f 100644 --- a/src/assistant/locale/messages-validation.go +++ b/src/assistant/locale/messages-validation.go @@ -1,7 +1,8 @@ package locale import ( - "github.com/snivilised/extendio/i18n" + "github.com/nicksnyder/go-i18n/v2/i18n" + xi18n "github.com/snivilised/extendio/i18n" ) // The code for these messages needs to be generated not hand coded. We @@ -42,7 +43,7 @@ type WithinOptValidationBehaviourQuery interface { } type WithinOptValidation struct { - i18n.LocalisableError + xi18n.LocalisableError } func (e WithinOptValidation) IsOutOfRange() bool { @@ -51,7 +52,7 @@ func (e WithinOptValidation) IsOutOfRange() bool { func NewWithinOptValidationError(flag string, value, low, high any) WithinOptValidationBehaviourQuery { return &WithinOptValidation{ - LocalisableError: i18n.LocalisableError{ + LocalisableError: xi18n.LocalisableError{ Data: WithinOptValidationTemplData{ OutOfRangeOV: OutOfRangeOV{ Flag: flag, @@ -85,7 +86,7 @@ type NotWithinOptValidationBehaviourQuery interface { } type NotWithinOptValidation struct { - i18n.LocalisableError + xi18n.LocalisableError } func (e NotWithinOptValidation) IsInsideOfRange() bool { @@ -94,7 +95,7 @@ func (e NotWithinOptValidation) IsInsideOfRange() bool { func NewNotWithinOptValidationError(flag string, value, low, high any) NotWithinOptValidationBehaviourQuery { return &NotWithinOptValidation{ - LocalisableError: i18n.LocalisableError{ + LocalisableError: xi18n.LocalisableError{ Data: NotWithinOptValidationTemplData{ OutOfRangeOV: OutOfRangeOV{ Flag: flag, @@ -138,7 +139,7 @@ type ContainsOptValidationBehaviourQuery[T any] interface { } type ContainsOptValidation[T any] struct { - i18n.LocalisableError + xi18n.LocalisableError } func (e ContainsOptValidation[T]) IsAMemberOf() bool { @@ -147,7 +148,7 @@ func (e ContainsOptValidation[T]) IsAMemberOf() bool { func NewContainsOptValidationError[T any](flag string, value any, collection []T) ContainsOptValidationBehaviourQuery[T] { return &ContainsOptValidation[T]{ - LocalisableError: i18n.LocalisableError{ + LocalisableError: xi18n.LocalisableError{ Data: ContainsOptValidationTemplData[T]{ ContainmentOV: ContainmentOV[T]{ Flag: flag, @@ -180,7 +181,7 @@ type NotContainsOptValidationBehaviourQuery[T any] interface { } type NotContainsOptValidation[T any] struct { - i18n.LocalisableError + xi18n.LocalisableError } func (e NotContainsOptValidation[T]) IsNotAMemberOf() bool { @@ -189,7 +190,7 @@ func (e NotContainsOptValidation[T]) IsNotAMemberOf() bool { func NewNotContainsOptValidationError[T any](flag string, value any, collection []T) NotContainsOptValidationBehaviourQuery[T] { return &NotContainsOptValidation[T]{ - LocalisableError: i18n.LocalisableError{ + LocalisableError: xi18n.LocalisableError{ Data: NotContainsOptValidationTemplData[T]{ ContainmentOV: ContainmentOV[T]{ Flag: flag, @@ -232,7 +233,7 @@ type MatchOptValidationBehaviourQuery interface { } type MatchOptValidation struct { - i18n.LocalisableError + xi18n.LocalisableError } func (e MatchOptValidation) IsMatch() bool { @@ -241,7 +242,7 @@ func (e MatchOptValidation) IsMatch() bool { func NewMatchOptValidationError(flag, value, pattern string) MatchOptValidationBehaviourQuery { return &MatchOptValidation{ - LocalisableError: i18n.LocalisableError{ + LocalisableError: xi18n.LocalisableError{ Data: MatchOptValidationTemplData{ MatchOV: MatchOV{ Flag: flag, @@ -274,7 +275,7 @@ type NotMatchOptValidationBehaviourQuery interface { } type NotMatchOptValidation struct { - i18n.LocalisableError + xi18n.LocalisableError } func (e NotMatchOptValidation) IsNotMatch() bool { @@ -283,7 +284,7 @@ func (e NotMatchOptValidation) IsNotMatch() bool { func NewNotMatchOptValidationError(flag, value, pattern string) NotMatchOptValidationBehaviourQuery { return &NotMatchOptValidation{ - LocalisableError: i18n.LocalisableError{ + LocalisableError: xi18n.LocalisableError{ Data: NotMatchOptValidationTemplData{ MatchOV: MatchOV{ Flag: flag, @@ -324,7 +325,7 @@ type GreaterThanOptValidationBehaviourQuery interface { } type GreaterThanOptValidation struct { - i18n.LocalisableError + xi18n.LocalisableError } func (e GreaterThanOptValidation) IsGreaterThan() bool { @@ -333,7 +334,7 @@ func (e GreaterThanOptValidation) IsGreaterThan() bool { func NewGreaterThanOptValidationError(flag string, value, threshold any) GreaterThanOptValidationBehaviourQuery { return &GreaterThanOptValidation{ - LocalisableError: i18n.LocalisableError{ + LocalisableError: xi18n.LocalisableError{ Data: GreaterThanOptValidationTemplData{ RelationalOV: RelationalOV{ Flag: flag, @@ -366,7 +367,7 @@ type AtLeastOptValidationBehaviourQuery interface { } type AtLeastOptValidation struct { - i18n.LocalisableError + xi18n.LocalisableError } func (e AtLeastOptValidation) IsAtLeast() bool { @@ -375,7 +376,7 @@ func (e AtLeastOptValidation) IsAtLeast() bool { func NewAtLeastOptValidationError(flag string, value, threshold any) AtLeastOptValidationBehaviourQuery { return &AtLeastOptValidation{ - LocalisableError: i18n.LocalisableError{ + LocalisableError: xi18n.LocalisableError{ Data: AtLeastOptValidationTemplData{ RelationalOV: RelationalOV{ Flag: flag, @@ -408,7 +409,7 @@ type LessThanOptValidationBehaviourQuery interface { } type LessThanOptValidation struct { - i18n.LocalisableError + xi18n.LocalisableError } func (e LessThanOptValidation) IsLessThan() bool { @@ -417,7 +418,7 @@ func (e LessThanOptValidation) IsLessThan() bool { func NewLessThanOptValidationError(flag string, value, threshold any) LessThanOptValidationBehaviourQuery { return &LessThanOptValidation{ - LocalisableError: i18n.LocalisableError{ + LocalisableError: xi18n.LocalisableError{ Data: AtLeastOptValidationTemplData{ RelationalOV: RelationalOV{ Flag: flag, @@ -450,7 +451,7 @@ type AtMostOptValidationBehaviourQuery interface { } type AtMostOptValidation struct { - i18n.LocalisableError + xi18n.LocalisableError } func (e AtMostOptValidation) IsAtMost() bool { @@ -459,7 +460,7 @@ func (e AtMostOptValidation) IsAtMost() bool { func NewAtMostOptValidationError(flag string, value, threshold any) AtMostOptValidationBehaviourQuery { return &AtMostOptValidation{ - LocalisableError: i18n.LocalisableError{ + LocalisableError: xi18n.LocalisableError{ Data: AtMostOptValidationTemplData{ RelationalOV: RelationalOV{ Flag: flag, @@ -493,7 +494,7 @@ type InvalidExtendedGlobFilterBehaviourQuery interface { } type InvalidExtendedGlobFilterValidation struct { - i18n.LocalisableError + xi18n.LocalisableError } func (e InvalidExtendedGlobFilterValidation) IsInvalidExtendedGlobFilter() bool { @@ -502,7 +503,7 @@ func (e InvalidExtendedGlobFilterValidation) IsInvalidExtendedGlobFilter() bool func NewInvalidExtendedGlobFilterValidationError(delimiter string) InvalidExtendedGlobFilterBehaviourQuery { return &InvalidExtendedGlobFilterValidation{ - LocalisableError: i18n.LocalisableError{ + LocalisableError: xi18n.LocalisableError{ Data: InvalidExtendedGlobFilterTemplData{ Delimiter: delimiter, }, From bfa6f87ada2b233935c2bc6dfc9473f7c2fa4e73 Mon Sep 17 00:00:00 2001 From: plastikfan Date: Thu, 24 Oct 2024 17:41:09 +0100 Subject: [PATCH 4/8] ref: use li18ngo (#310) --- go.mod | 11 +++-- go.sum | 32 +++++-------- src/assistant/get-third-party-cl_test.go | 12 ++--- src/assistant/locale/i18n-defs.go | 2 +- src/assistant/locale/i18n.go | 6 +-- .../locale/messages-validation-errors_test.go | 12 ++--- src/assistant/locale/messages-validation.go | 46 +++++++++---------- src/store/families_test.go | 12 ++--- src/store/family-cascade.go | 7 +-- src/store/family-filter.go | 28 +++++------ src/store/family-i18n.go | 4 +- src/store/family-interactions.go | 6 +-- src/store/family-preview.go | 4 +- src/store/family-profile.go | 6 +-- src/store/family-sampling.go | 10 ++-- src/store/family-worker-pool.go | 6 +-- 16 files changed, 99 insertions(+), 105 deletions(-) diff --git a/go.mod b/go.mod index 7ce9b7f..a57f571 100644 --- a/go.mod +++ b/go.mod @@ -6,6 +6,7 @@ require ( github.com/avfs/avfs v0.33.0 github.com/onsi/ginkgo/v2 v2.20.2 github.com/onsi/gomega v1.34.2 + github.com/snivilised/li18ngo v0.1.7 github.com/spf13/cobra v1.8.1 github.com/spf13/pflag v1.0.5 go.uber.org/mock v0.5.0 @@ -24,13 +25,14 @@ require ( github.com/pkg/errors v0.9.1 // indirect github.com/sagikazarmark/locafero v0.4.0 // indirect github.com/sagikazarmark/slog-shim v0.1.0 // indirect + github.com/snivilised/nefilim v0.1.4 // indirect github.com/sourcegraph/conc v0.3.0 // indirect github.com/spf13/afero v1.11.0 // indirect github.com/spf13/cast v1.6.0 // indirect github.com/subosito/gotenv v1.6.0 // indirect go.uber.org/multierr v1.11.0 // indirect - golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 // indirect - golang.org/x/tools v0.24.0 // indirect + golang.org/x/exp v0.0.0-20241009180824-f66d83c29e7c // indirect + golang.org/x/tools v0.26.0 // indirect gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) @@ -39,9 +41,8 @@ require ( github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/nicksnyder/go-i18n/v2 v2.4.1 github.com/samber/lo v1.47.0 - github.com/snivilised/extendio v0.7.0 github.com/spf13/viper v1.19.0 - golang.org/x/net v0.28.0 // indirect - golang.org/x/sys v0.24.0 // indirect + golang.org/x/net v0.30.0 // indirect + golang.org/x/sys v0.26.0 // indirect golang.org/x/text v0.19.0 ) diff --git a/go.sum b/go.sum index 3c4baf9..9ae047e 100644 --- a/go.sum +++ b/go.sum @@ -19,8 +19,6 @@ github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/pprof v0.0.0-20240827171923-fa2c70bbbfe5 h1:5iH8iuqE5apketRbSFBy+X1V0o+l+8NF1avt4HWl7cA= github.com/google/pprof v0.0.0-20240827171923-fa2c70bbbfe5/go.mod h1:vavhavw2zAxS5dIdcRluK6cSGGPlZynqzFM8NdvU144= -github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= -github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= @@ -33,8 +31,6 @@ github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0V github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0= github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= -github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 h1:RWengNIwukTxcDr9M+97sNutRR1RKhG96O6jWumTTnw= -github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf+YrPgl8= github.com/nicksnyder/go-i18n/v2 v2.4.1 h1:zwzjtX4uYyiaU02K5Ia3zSkpJZrByARkRB4V3YPrr0g= github.com/nicksnyder/go-i18n/v2 v2.4.1/go.mod h1:++Pl70FR6Cki7hdzZRnEEqdc2dJt+SAGotyFg/SvZMk= github.com/onsi/ginkgo/v2 v2.20.2 h1:7NVCeyIWROIAheY21RLS+3j2bb52W0W82tkberYytp4= @@ -57,10 +53,10 @@ github.com/sagikazarmark/slog-shim v0.1.0 h1:diDBnUNK9N/354PgrxMywXnAwEr1QZcOr6g github.com/sagikazarmark/slog-shim v0.1.0/go.mod h1:SrcSrq8aKtyuqEI1uvTDTK1arOWRIczQRv+GVI1AkeQ= github.com/samber/lo v1.47.0 h1:z7RynLwP5nbyRscyvcD043DWYoOcYRv3mV8lBeqOCLc= github.com/samber/lo v1.47.0/go.mod h1:RmDH9Ct32Qy3gduHQuKJ3gW1fMHAnE/fAzQuf6He5cU= -github.com/snivilised/extendio v0.7.0 h1:MY6w9qCK5wVEvP2WpMT5ywJwpDJe97WHDGuwrsTLpek= -github.com/snivilised/extendio v0.7.0/go.mod h1:l8MwJOy9ojMQYJrSKRbQS3WfDylevnRtBp/zwAmFEKc= -github.com/snivilised/lorax v0.5.2 h1:iReIJl63tydiPSSD0YzsNQFX1CctmvMkYx0aSxoZJKo= -github.com/snivilised/lorax v0.5.2/go.mod h1:7H1JPgSn4h4p8NSqfl64raacYefdm/FiFkfcZ51PVHY= +github.com/snivilised/li18ngo v0.1.7 h1:XRYpmP7jSAxzRyg5WH0PViFb9ycWGFcDkQQqd2GsjzQ= +github.com/snivilised/li18ngo v0.1.7/go.mod h1:NVOexqt/aIhnenNPQDqbJchLNte92io87j5o2l+HNqs= +github.com/snivilised/nefilim v0.1.4 h1:bhiENDl/T6ZQO146eF8UnxtXLQenSzEyjwuTeWScImw= +github.com/snivilised/nefilim v0.1.4/go.mod h1:+4/hKxgfvE8eNjLMJC+3ropEZSQuiR/NqfPtIuw7ZMw= github.com/sourcegraph/conc v0.3.0 h1:OQTbbt6P72L20UqAkXXuLOj79LfEanQ+YQFNpLA9ySo= github.com/sourcegraph/conc v0.3.0/go.mod h1:Sdozi7LEKbFPqYX2/J+iBAM6HpqSLTASQIKqDmF7Mt0= github.com/spf13/afero v1.11.0 h1:WJQKhtpdm3v2IzqG8VMqrr6Rf3UYpEF239Jy9wNepM8= @@ -88,20 +84,16 @@ go.uber.org/mock v0.5.0 h1:KAMbZvZPyBPWgD14IrIQ38QCyjwpvVVV6K/bHl1IwQU= go.uber.org/mock v0.5.0/go.mod h1:ge71pBPLYDk7QIi1LupWxdAykm7KIEFchiOqd6z7qMM= go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0= go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y= -go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8= -go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E= -go.uber.org/zap/exp v0.2.0 h1:FtGenNNeCATRB3CmB/yEUnjEFeJWpB/pMcy7e2bKPYs= -go.uber.org/zap/exp v0.2.0/go.mod h1:t0gqAIdh1MfKv9EwN/dLwfZnJxe9ITAZN78HEWPFWDQ= -golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 h1:2dVuKD2vS7b0QIHQbpyTISPd0LeHDbnYEryqj5Q1ug8= -golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56/go.mod h1:M4RDyNAINzryxdtnbRXRL/OHtkFuWGRjvuhBJpk2IlY= -golang.org/x/net v0.28.0 h1:a9JDOJc5GMUJ0+UDqmLT86WiEy7iWyIhz8gz8E4e5hE= -golang.org/x/net v0.28.0/go.mod h1:yqtgsTWOOnlGLG9GFRrK3++bGOUEkNBoHZc8MEDWPNg= -golang.org/x/sys v0.24.0 h1:Twjiwq9dn6R1fQcyiK+wQyHWfaz/BJB+YIpzU/Cv3Xg= -golang.org/x/sys v0.24.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/exp v0.0.0-20241009180824-f66d83c29e7c h1:7dEasQXItcW1xKJ2+gg5VOiBnqWrJc+rq0DPKyvvdbY= +golang.org/x/exp v0.0.0-20241009180824-f66d83c29e7c/go.mod h1:NQtJDoLvd6faHhE7m4T/1IY708gDefGGjR/iUW8yQQ8= +golang.org/x/net v0.30.0 h1:AcW1SDZMkb8IpzCdQUaIq2sP4sZ4zw+55h6ynffypl4= +golang.org/x/net v0.30.0/go.mod h1:2wGyMJ5iFasEhkwi13ChkO/t1ECNC4X4eBKkVFyYFlU= +golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo= +golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM= golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= -golang.org/x/tools v0.24.0 h1:J1shsA93PJUEVaUSaay7UXAyE8aimq3GW0pjlolpa24= -golang.org/x/tools v0.24.0/go.mod h1:YhNqVBIfWHdzvTLs0d8LCuMhkKUgSUKldakyV7W/WDQ= +golang.org/x/tools v0.26.0 h1:v/60pFQmzmT9ExmjDv2gGIfi3OqfKoEP6I5+umXlbnQ= +golang.org/x/tools v0.26.0/go.mod h1:TPVVj70c7JJ3WCazhD8OdXcZg/og+b9+tH/KxylGwH0= google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFWg= google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/src/assistant/get-third-party-cl_test.go b/src/assistant/get-third-party-cl_test.go index 0e339cc..00e6f8a 100644 --- a/src/assistant/get-third-party-cl_test.go +++ b/src/assistant/get-third-party-cl_test.go @@ -13,7 +13,7 @@ import ( "github.com/snivilised/cobrass/src/clif" "github.com/snivilised/cobrass/src/internal/helpers" "github.com/snivilised/cobrass/src/store" - xi18n "github.com/snivilised/extendio/i18n" + "github.com/snivilised/li18ngo" ) type baseTE struct { @@ -33,7 +33,7 @@ var _ = Describe("GetThirdPartyCL", Ordered, func() { repo string l10nPath string - from xi18n.LoadFrom + from li18ngo.LoadFrom rootCommand *cobra.Command paramSet *assistant.ParamSet[store.ProfileParameterSet] @@ -44,14 +44,14 @@ var _ = Describe("GetThirdPartyCL", Ordered, func() { repo = helpers.Repo("../..") l10nPath = helpers.Path(repo, "Test/data/l10n") - from = xi18n.LoadFrom{ + from = li18ngo.LoadFrom{ Path: l10nPath, - Sources: xi18n.TranslationFiles{ - locale.CobrassSourceID: xi18n.TranslationSource{Name: "test"}, + Sources: li18ngo.TranslationFiles{ + locale.CobrassSourceID: li18ngo.TranslationSource{Name: "test"}, }, } - if err := xi18n.Use(func(o *xi18n.UseOptions) { + if err := li18ngo.Use(func(o *li18ngo.UseOptions) { o.From = from }); err != nil { Fail(err.Error()) diff --git a/src/assistant/locale/i18n-defs.go b/src/assistant/locale/i18n-defs.go index c41d65d..ae7ae94 100644 --- a/src/assistant/locale/i18n-defs.go +++ b/src/assistant/locale/i18n-defs.go @@ -2,7 +2,7 @@ package locale const CobrassSourceID = "github.com/snivilised/cobrass" -// These definitions are in support of extendio's Localisable +// These definitions are in support of li18ngo's Localisable // interface and other i18n related definitions. type CobrassTemplData struct{} diff --git a/src/assistant/locale/i18n.go b/src/assistant/locale/i18n.go index f7e0f89..beb1e3d 100644 --- a/src/assistant/locale/i18n.go +++ b/src/assistant/locale/i18n.go @@ -1,9 +1,9 @@ package locale import ( - xi18n "github.com/snivilised/extendio/i18n" + "github.com/snivilised/li18ngo" ) -func Use(options ...xi18n.UseOptionFn) error { - return xi18n.Use(options...) +func Use(options ...li18ngo.UseOptionFn) error { + return li18ngo.Use(options...) } diff --git a/src/assistant/locale/messages-validation-errors_test.go b/src/assistant/locale/messages-validation-errors_test.go index d2851b8..297e69d 100644 --- a/src/assistant/locale/messages-validation-errors_test.go +++ b/src/assistant/locale/messages-validation-errors_test.go @@ -8,7 +8,7 @@ import ( "github.com/snivilised/cobrass/src/assistant/locale" "github.com/snivilised/cobrass/src/internal/helpers" - xi18n "github.com/snivilised/extendio/i18n" + "github.com/snivilised/li18ngo" ) type validationEntry struct { @@ -24,21 +24,21 @@ var _ = Describe("MessagesValidationErrors", Ordered, func() { repo string l10nPath string - from xi18n.LoadFrom + from li18ngo.LoadFrom ) BeforeAll(func() { repo = helpers.Repo("../..") l10nPath = helpers.Path(repo, "Test/data/l10n") - from = xi18n.LoadFrom{ + from = li18ngo.LoadFrom{ Path: l10nPath, - Sources: xi18n.TranslationFiles{ - locale.CobrassSourceID: xi18n.TranslationSource{Name: "test"}, + Sources: li18ngo.TranslationFiles{ + locale.CobrassSourceID: li18ngo.TranslationSource{Name: "test"}, }, } - if err := xi18n.Use(func(o *xi18n.UseOptions) { + if err := li18ngo.Use(func(o *li18ngo.UseOptions) { o.From = from }); err != nil { Fail(err.Error()) diff --git a/src/assistant/locale/messages-validation.go b/src/assistant/locale/messages-validation.go index 66d674f..9025ee4 100644 --- a/src/assistant/locale/messages-validation.go +++ b/src/assistant/locale/messages-validation.go @@ -2,7 +2,7 @@ package locale import ( "github.com/nicksnyder/go-i18n/v2/i18n" - xi18n "github.com/snivilised/extendio/i18n" + "github.com/snivilised/li18ngo" ) // The code for these messages needs to be generated not hand coded. We @@ -43,7 +43,7 @@ type WithinOptValidationBehaviourQuery interface { } type WithinOptValidation struct { - xi18n.LocalisableError + li18ngo.LocalisableError } func (e WithinOptValidation) IsOutOfRange() bool { @@ -52,7 +52,7 @@ func (e WithinOptValidation) IsOutOfRange() bool { func NewWithinOptValidationError(flag string, value, low, high any) WithinOptValidationBehaviourQuery { return &WithinOptValidation{ - LocalisableError: xi18n.LocalisableError{ + LocalisableError: li18ngo.LocalisableError{ Data: WithinOptValidationTemplData{ OutOfRangeOV: OutOfRangeOV{ Flag: flag, @@ -86,7 +86,7 @@ type NotWithinOptValidationBehaviourQuery interface { } type NotWithinOptValidation struct { - xi18n.LocalisableError + li18ngo.LocalisableError } func (e NotWithinOptValidation) IsInsideOfRange() bool { @@ -95,7 +95,7 @@ func (e NotWithinOptValidation) IsInsideOfRange() bool { func NewNotWithinOptValidationError(flag string, value, low, high any) NotWithinOptValidationBehaviourQuery { return &NotWithinOptValidation{ - LocalisableError: xi18n.LocalisableError{ + LocalisableError: li18ngo.LocalisableError{ Data: NotWithinOptValidationTemplData{ OutOfRangeOV: OutOfRangeOV{ Flag: flag, @@ -139,7 +139,7 @@ type ContainsOptValidationBehaviourQuery[T any] interface { } type ContainsOptValidation[T any] struct { - xi18n.LocalisableError + li18ngo.LocalisableError } func (e ContainsOptValidation[T]) IsAMemberOf() bool { @@ -148,7 +148,7 @@ func (e ContainsOptValidation[T]) IsAMemberOf() bool { func NewContainsOptValidationError[T any](flag string, value any, collection []T) ContainsOptValidationBehaviourQuery[T] { return &ContainsOptValidation[T]{ - LocalisableError: xi18n.LocalisableError{ + LocalisableError: li18ngo.LocalisableError{ Data: ContainsOptValidationTemplData[T]{ ContainmentOV: ContainmentOV[T]{ Flag: flag, @@ -181,7 +181,7 @@ type NotContainsOptValidationBehaviourQuery[T any] interface { } type NotContainsOptValidation[T any] struct { - xi18n.LocalisableError + li18ngo.LocalisableError } func (e NotContainsOptValidation[T]) IsNotAMemberOf() bool { @@ -190,7 +190,7 @@ func (e NotContainsOptValidation[T]) IsNotAMemberOf() bool { func NewNotContainsOptValidationError[T any](flag string, value any, collection []T) NotContainsOptValidationBehaviourQuery[T] { return &NotContainsOptValidation[T]{ - LocalisableError: xi18n.LocalisableError{ + LocalisableError: li18ngo.LocalisableError{ Data: NotContainsOptValidationTemplData[T]{ ContainmentOV: ContainmentOV[T]{ Flag: flag, @@ -233,7 +233,7 @@ type MatchOptValidationBehaviourQuery interface { } type MatchOptValidation struct { - xi18n.LocalisableError + li18ngo.LocalisableError } func (e MatchOptValidation) IsMatch() bool { @@ -242,7 +242,7 @@ func (e MatchOptValidation) IsMatch() bool { func NewMatchOptValidationError(flag, value, pattern string) MatchOptValidationBehaviourQuery { return &MatchOptValidation{ - LocalisableError: xi18n.LocalisableError{ + LocalisableError: li18ngo.LocalisableError{ Data: MatchOptValidationTemplData{ MatchOV: MatchOV{ Flag: flag, @@ -275,7 +275,7 @@ type NotMatchOptValidationBehaviourQuery interface { } type NotMatchOptValidation struct { - xi18n.LocalisableError + li18ngo.LocalisableError } func (e NotMatchOptValidation) IsNotMatch() bool { @@ -284,7 +284,7 @@ func (e NotMatchOptValidation) IsNotMatch() bool { func NewNotMatchOptValidationError(flag, value, pattern string) NotMatchOptValidationBehaviourQuery { return &NotMatchOptValidation{ - LocalisableError: xi18n.LocalisableError{ + LocalisableError: li18ngo.LocalisableError{ Data: NotMatchOptValidationTemplData{ MatchOV: MatchOV{ Flag: flag, @@ -325,7 +325,7 @@ type GreaterThanOptValidationBehaviourQuery interface { } type GreaterThanOptValidation struct { - xi18n.LocalisableError + li18ngo.LocalisableError } func (e GreaterThanOptValidation) IsGreaterThan() bool { @@ -334,7 +334,7 @@ func (e GreaterThanOptValidation) IsGreaterThan() bool { func NewGreaterThanOptValidationError(flag string, value, threshold any) GreaterThanOptValidationBehaviourQuery { return &GreaterThanOptValidation{ - LocalisableError: xi18n.LocalisableError{ + LocalisableError: li18ngo.LocalisableError{ Data: GreaterThanOptValidationTemplData{ RelationalOV: RelationalOV{ Flag: flag, @@ -367,7 +367,7 @@ type AtLeastOptValidationBehaviourQuery interface { } type AtLeastOptValidation struct { - xi18n.LocalisableError + li18ngo.LocalisableError } func (e AtLeastOptValidation) IsAtLeast() bool { @@ -376,7 +376,7 @@ func (e AtLeastOptValidation) IsAtLeast() bool { func NewAtLeastOptValidationError(flag string, value, threshold any) AtLeastOptValidationBehaviourQuery { return &AtLeastOptValidation{ - LocalisableError: xi18n.LocalisableError{ + LocalisableError: li18ngo.LocalisableError{ Data: AtLeastOptValidationTemplData{ RelationalOV: RelationalOV{ Flag: flag, @@ -409,7 +409,7 @@ type LessThanOptValidationBehaviourQuery interface { } type LessThanOptValidation struct { - xi18n.LocalisableError + li18ngo.LocalisableError } func (e LessThanOptValidation) IsLessThan() bool { @@ -418,7 +418,7 @@ func (e LessThanOptValidation) IsLessThan() bool { func NewLessThanOptValidationError(flag string, value, threshold any) LessThanOptValidationBehaviourQuery { return &LessThanOptValidation{ - LocalisableError: xi18n.LocalisableError{ + LocalisableError: li18ngo.LocalisableError{ Data: AtLeastOptValidationTemplData{ RelationalOV: RelationalOV{ Flag: flag, @@ -451,7 +451,7 @@ type AtMostOptValidationBehaviourQuery interface { } type AtMostOptValidation struct { - xi18n.LocalisableError + li18ngo.LocalisableError } func (e AtMostOptValidation) IsAtMost() bool { @@ -460,7 +460,7 @@ func (e AtMostOptValidation) IsAtMost() bool { func NewAtMostOptValidationError(flag string, value, threshold any) AtMostOptValidationBehaviourQuery { return &AtMostOptValidation{ - LocalisableError: xi18n.LocalisableError{ + LocalisableError: li18ngo.LocalisableError{ Data: AtMostOptValidationTemplData{ RelationalOV: RelationalOV{ Flag: flag, @@ -494,7 +494,7 @@ type InvalidExtendedGlobFilterBehaviourQuery interface { } type InvalidExtendedGlobFilterValidation struct { - xi18n.LocalisableError + li18ngo.LocalisableError } func (e InvalidExtendedGlobFilterValidation) IsInvalidExtendedGlobFilter() bool { @@ -503,7 +503,7 @@ func (e InvalidExtendedGlobFilterValidation) IsInvalidExtendedGlobFilter() bool func NewInvalidExtendedGlobFilterValidationError(delimiter string) InvalidExtendedGlobFilterBehaviourQuery { return &InvalidExtendedGlobFilterValidation{ - LocalisableError: xi18n.LocalisableError{ + LocalisableError: li18ngo.LocalisableError{ Data: InvalidExtendedGlobFilterTemplData{ Delimiter: delimiter, }, diff --git a/src/store/families_test.go b/src/store/families_test.go index 0195875..66a43ee 100644 --- a/src/store/families_test.go +++ b/src/store/families_test.go @@ -11,7 +11,7 @@ import ( "github.com/snivilised/cobrass/src/assistant/locale" "github.com/snivilised/cobrass/src/internal/helpers" "github.com/snivilised/cobrass/src/store" - xi18n "github.com/snivilised/extendio/i18n" + "github.com/snivilised/li18ngo" ) func reason(binder string, err error) string { @@ -38,7 +38,7 @@ var _ = Describe("Families", Ordered, func() { repo string l10nPath string - from xi18n.LoadFrom + from li18ngo.LoadFrom rootCommand *cobra.Command execute func(args []string) ) @@ -47,14 +47,14 @@ var _ = Describe("Families", Ordered, func() { repo = helpers.Repo("../..") l10nPath = helpers.Path(repo, "Test/data/l10n") - from = xi18n.LoadFrom{ + from = li18ngo.LoadFrom{ Path: l10nPath, - Sources: xi18n.TranslationFiles{ - locale.CobrassSourceID: xi18n.TranslationSource{Name: "test"}, + Sources: li18ngo.TranslationFiles{ + locale.CobrassSourceID: li18ngo.TranslationSource{Name: "test"}, }, } - if err := xi18n.Use(func(o *xi18n.UseOptions) { + if err := li18ngo.Use(func(o *li18ngo.UseOptions) { o.From = from }); err != nil { Fail(err.Error()) diff --git a/src/store/family-cascade.go b/src/store/family-cascade.go index f0b078a..be18021 100644 --- a/src/store/family-cascade.go +++ b/src/store/family-cascade.go @@ -3,7 +3,8 @@ package store import ( "github.com/snivilised/cobrass/src/assistant" "github.com/snivilised/cobrass/src/assistant/locale" - xi18n "github.com/snivilised/extendio/i18n" + "github.com/snivilised/li18ngo" + "github.com/spf13/pflag" ) @@ -24,7 +25,7 @@ func (f *CascadeParameterSet) BindAll( parent.BindUint( resolveNewFlagInfo( - xi18n.Text(locale.CascadeDepthParamUsageTemplData{}), + li18ngo.Text(locale.CascadeDepthParamUsageTemplData{}), defaultDepth, flagSet..., ), @@ -39,7 +40,7 @@ func (f *CascadeParameterSet) BindAll( parent.BindBool( resolveNewFlagInfo( - xi18n.Text(locale.CascadeNoRecurseParamUsageTemplData{}), + li18ngo.Text(locale.CascadeNoRecurseParamUsageTemplData{}), defaultNoRecurse, flagSet..., ), diff --git a/src/store/family-filter.go b/src/store/family-filter.go index 2b7779d..336b606 100644 --- a/src/store/family-filter.go +++ b/src/store/family-filter.go @@ -5,7 +5,7 @@ import ( "github.com/snivilised/cobrass/src/assistant" "github.com/snivilised/cobrass/src/assistant/locale" - xi18n "github.com/snivilised/extendio/i18n" + "github.com/snivilised/li18ngo" "github.com/spf13/pflag" ) @@ -18,12 +18,12 @@ const ( // Therefore, for compound filters typically used when we want to filter // file system nodes by file name and directory name, we forego the // ability to specify compound file names (when using the navigator -// in extendio with the FoldersWithFiles subscription type) with a +// in traverse with the FoldersWithFiles subscription type) with a // short code, as this is seen as a niche feature. The more common // scenarios would be to either filter files, directories or both // by using an 'any' scope. With this compromise, the user would // always have to spell the compound file filter in it full form: -// --files-rx or --files-gb. When using extendio nav, the folders +// --files-rx or --files-gb. When using traverse nav, the folders // with files subscription would have to be used, ie there is no // standalone file file, so --files-rx and --files-gb are both free // to use without ambiguity. @@ -50,7 +50,7 @@ func (f *FilesFilterParameterSet) BindAll( // parent.BindString( resolveNewFlagInfo( - xi18n.Text(locale.FilesExGlobParamUsageTemplData{}), + li18ngo.Text(locale.FilesExGlobParamUsageTemplData{}), defaultFilterValue, flagSet..., ), @@ -61,7 +61,7 @@ func (f *FilesFilterParameterSet) BindAll( // parent.BindString( resolveNewFlagInfo( - xi18n.Text(locale.FilesGlobParamUsageTemplData{}), + li18ngo.Text(locale.FilesGlobParamUsageTemplData{}), defaultFilterValue, flagSet..., ), @@ -72,7 +72,7 @@ func (f *FilesFilterParameterSet) BindAll( // parent.BindValidatedString( resolveNewFlagInfo( - xi18n.Text(locale.FilesRegExParamUsageTemplData{}), + li18ngo.Text(locale.FilesRegExParamUsageTemplData{}), defaultFilterValue, flagSet..., ), @@ -103,7 +103,7 @@ func (f *FoldersFilterParameterSet) BindAll( // parent.BindString( resolveNewFlagInfo( - xi18n.Text(locale.FoldersGlobParamUsageTemplData{}), + li18ngo.Text(locale.FoldersGlobParamUsageTemplData{}), defaultFilterValue, flagSet..., ), @@ -114,7 +114,7 @@ func (f *FoldersFilterParameterSet) BindAll( // parent.BindValidatedString( resolveNewFlagInfo( - xi18n.Text(locale.FoldersRexExParamUsageTemplData{}), + li18ngo.Text(locale.FoldersRexExParamUsageTemplData{}), defaultFilterValue, flagSet..., ), @@ -147,7 +147,7 @@ func (f *PolyFilterParameterSet) BindAll( // parent.BindString( resolveNewFlagInfo( - xi18n.Text(locale.FilesExGlobParamUsageTemplData{}), + li18ngo.Text(locale.FilesExGlobParamUsageTemplData{}), defaultFilterValue, flagSet..., ), @@ -158,7 +158,7 @@ func (f *PolyFilterParameterSet) BindAll( // parent.BindValidatedString( resolveNewFlagInfo( - xi18n.Text(locale.FilesRegExParamUsageTemplData{}), + li18ngo.Text(locale.FilesRegExParamUsageTemplData{}), defaultFilterValue, flagSet..., ), @@ -173,7 +173,7 @@ func (f *PolyFilterParameterSet) BindAll( // parent.BindString( resolveNewFlagInfo( - xi18n.Text(locale.FoldersGlobParamUsageTemplData{}), + li18ngo.Text(locale.FoldersGlobParamUsageTemplData{}), defaultFilterValue, flagSet..., ), @@ -184,7 +184,7 @@ func (f *PolyFilterParameterSet) BindAll( // parent.BindValidatedString( resolveNewFlagInfo( - xi18n.Text(locale.FoldersRexExParamUsageTemplData{}), + li18ngo.Text(locale.FoldersRexExParamUsageTemplData{}), defaultFilterValue, flagSet..., ), @@ -215,7 +215,7 @@ func (f *AlloyFilterParameterSet) BindAll( // parent.BindString( resolveNewFlagInfo( - xi18n.Text(locale.FilesExGlobParamUsageTemplData{}), + li18ngo.Text(locale.FilesExGlobParamUsageTemplData{}), defaultFilterValue, flagSet..., ), @@ -226,7 +226,7 @@ func (f *AlloyFilterParameterSet) BindAll( // parent.BindString( resolveNewFlagInfo( - xi18n.Text(locale.FoldersGlobParamUsageTemplData{}), + li18ngo.Text(locale.FoldersGlobParamUsageTemplData{}), defaultFilterValue, flagSet..., ), diff --git a/src/store/family-i18n.go b/src/store/family-i18n.go index 380602f..07f685b 100644 --- a/src/store/family-i18n.go +++ b/src/store/family-i18n.go @@ -3,7 +3,7 @@ package store import ( "github.com/snivilised/cobrass/src/assistant" "github.com/snivilised/cobrass/src/assistant/locale" - xi18n "github.com/snivilised/extendio/i18n" + "github.com/snivilised/li18ngo" "github.com/spf13/pflag" "golang.org/x/text/language" ) @@ -24,7 +24,7 @@ func (f *I18nParameterSet) BindAll( parent.BindValidatedString( resolveNewFlagInfo( - xi18n.Text(locale.LanguageParamUsageTemplData{}), + li18ngo.Text(locale.LanguageParamUsageTemplData{}), defaultLanguage, flagSet..., ), diff --git a/src/store/family-interactions.go b/src/store/family-interactions.go index f2fb4f3..f8cb752 100644 --- a/src/store/family-interactions.go +++ b/src/store/family-interactions.go @@ -3,7 +3,7 @@ package store import ( "github.com/snivilised/cobrass/src/assistant" "github.com/snivilised/cobrass/src/assistant/locale" - xi18n "github.com/snivilised/extendio/i18n" + "github.com/snivilised/li18ngo" "github.com/spf13/pflag" ) @@ -23,7 +23,7 @@ func (f *TextualInteractionParameterSet) BindAll( parent.BindBool( resolveNewFlagInfo( - xi18n.Text(locale.TextualInteractionIsNoTUIUsageTemplData{}), + li18ngo.Text(locale.TextualInteractionIsNoTUIUsageTemplData{}), defNoTUI, flagSet..., ), @@ -47,7 +47,7 @@ func (f *CliInteractionParameterSet) BindAll( parent.BindBool( resolveNewFlagInfo( - xi18n.Text(locale.CliInteractionIsTUIUsageTemplData{}), + li18ngo.Text(locale.CliInteractionIsTUIUsageTemplData{}), defIsTUI, flagSet..., ), diff --git a/src/store/family-preview.go b/src/store/family-preview.go index 73aa058..8986672 100644 --- a/src/store/family-preview.go +++ b/src/store/family-preview.go @@ -3,7 +3,7 @@ package store import ( "github.com/snivilised/cobrass/src/assistant" "github.com/snivilised/cobrass/src/assistant/locale" - xi18n "github.com/snivilised/extendio/i18n" + "github.com/snivilised/li18ngo" "github.com/spf13/pflag" ) @@ -23,7 +23,7 @@ func (f *PreviewParameterSet) BindAll( parent.BindBool( resolveNewFlagInfo( - xi18n.Text(locale.DryRunParamUsageTemplData{}), + li18ngo.Text(locale.DryRunParamUsageTemplData{}), defaultDryRun, flagSet..., ), diff --git a/src/store/family-profile.go b/src/store/family-profile.go index 553a8ff..867568e 100644 --- a/src/store/family-profile.go +++ b/src/store/family-profile.go @@ -3,7 +3,7 @@ package store import ( "github.com/snivilised/cobrass/src/assistant" "github.com/snivilised/cobrass/src/assistant/locale" - xi18n "github.com/snivilised/extendio/i18n" + "github.com/snivilised/li18ngo" "github.com/spf13/pflag" ) @@ -24,7 +24,7 @@ func (f *ProfileParameterSet) BindAll( parent.BindValidatedStringIsMatch( resolveNewFlagInfo( - xi18n.Text(locale.ProfileParamUsageTemplData{}), + li18ngo.Text(locale.ProfileParamUsageTemplData{}), defaultProfile, flagSet..., ), @@ -40,7 +40,7 @@ func (f *ProfileParameterSet) BindAll( parent.BindString( resolveNewFlagInfo( - xi18n.Text(locale.SchemeParamUsageTemplData{}), + li18ngo.Text(locale.SchemeParamUsageTemplData{}), defaultScheme, flagSet..., ), diff --git a/src/store/family-sampling.go b/src/store/family-sampling.go index 3c68949..6871acb 100644 --- a/src/store/family-sampling.go +++ b/src/store/family-sampling.go @@ -3,7 +3,7 @@ package store import ( "github.com/snivilised/cobrass/src/assistant" "github.com/snivilised/cobrass/src/assistant/locale" - xi18n "github.com/snivilised/extendio/i18n" + "github.com/snivilised/li18ngo" "github.com/spf13/pflag" ) @@ -26,7 +26,7 @@ func (f *SamplingParameterSet) BindAll( // parent.BindBool( resolveNewFlagInfo( - xi18n.Text(locale.SamplingSampleUsageTemplData{}), + li18ngo.Text(locale.SamplingSampleUsageTemplData{}), defIsSampling, flagSet..., ), @@ -43,7 +43,7 @@ func (f *SamplingParameterSet) BindAll( // parent.BindValidatedUintWithin( resolveNewFlagInfo( - xi18n.Text(locale.SamplingNoFilesUsageTemplData{}), + li18ngo.Text(locale.SamplingNoFilesUsageTemplData{}), defFSItems, flagSet..., ), @@ -56,7 +56,7 @@ func (f *SamplingParameterSet) BindAll( // parent.BindValidatedUintWithin( resolveNewFlagInfo( - xi18n.Text(locale.SamplingNoFoldersUsageTemplData{}), + li18ngo.Text(locale.SamplingNoFoldersUsageTemplData{}), defFSItems, flagSet..., ), @@ -73,7 +73,7 @@ func (f *SamplingParameterSet) BindAll( // parent.BindBool( resolveNewFlagInfo( - xi18n.Text(locale.SamplingLastUsageTemplData{}), + li18ngo.Text(locale.SamplingLastUsageTemplData{}), defIsLast, flagSet..., ), diff --git a/src/store/family-worker-pool.go b/src/store/family-worker-pool.go index b5d4b41..5a34084 100644 --- a/src/store/family-worker-pool.go +++ b/src/store/family-worker-pool.go @@ -3,7 +3,7 @@ package store import ( "github.com/snivilised/cobrass/src/assistant" "github.com/snivilised/cobrass/src/assistant/locale" - xi18n "github.com/snivilised/extendio/i18n" + "github.com/snivilised/li18ngo" "github.com/spf13/pflag" ) @@ -24,7 +24,7 @@ func (f *WorkerPoolParameterSet) BindAll( parent.BindBool( resolveNewFlagInfo( - xi18n.Text(locale.WorkerPoolCPUParamUsageTemplData{}), + li18ngo.Text(locale.WorkerPoolCPUParamUsageTemplData{}), defaultCPU, flagSet..., ), @@ -41,7 +41,7 @@ func (f *WorkerPoolParameterSet) BindAll( parent.BindValidatedIntWithin( resolveNewFlagInfo( - xi18n.Text(locale.WorkerPoolNoWParamUsageTemplData{}), + li18ngo.Text(locale.WorkerPoolNoWParamUsageTemplData{}), defaultNoW, flagSet..., ), From 24b7da239cecdc48c953e52ef53a32d87a2dfd50 Mon Sep 17 00:00:00 2001 From: plastikfan Date: Thu, 24 Oct 2024 18:21:34 +0100 Subject: [PATCH 5/8] ref: replace storage with nefilim (#310) --- generators/gola/content-parser.go | 8 +-- generators/gola/gen/main.go | 16 +++--- ...{gola_suite_test.go => gola-suite_test.go} | 0 generators/gola/gomega-matchers_test.go | 6 +-- generators/gola/internal/storage/mem-fs.go | 53 ------------------- generators/gola/internal/storage/native-fs.go | 49 ----------------- .../gola/internal/storage/storage-defs.go | 46 ---------------- generators/gola/signature_test.go | 22 ++++---- generators/gola/source-code-container.go | 6 +-- generators/gola/source-code-data.go | 11 ++-- generators/gola/source-code-data_test.go | 12 ++--- generators/gola/source-code-generator.go | 6 +-- generators/gola/source-code-generator_test.go | 8 +-- go.mod | 3 +- go.sum | 2 - 15 files changed, 49 insertions(+), 199 deletions(-) rename generators/gola/{gola_suite_test.go => gola-suite_test.go} (100%) delete mode 100644 generators/gola/internal/storage/mem-fs.go delete mode 100644 generators/gola/internal/storage/native-fs.go delete mode 100644 generators/gola/internal/storage/storage-defs.go diff --git a/generators/gola/content-parser.go b/generators/gola/content-parser.go index 724ab9f..1d71172 100644 --- a/generators/gola/content-parser.go +++ b/generators/gola/content-parser.go @@ -9,7 +9,7 @@ import ( "strings" "github.com/samber/lo" - "github.com/snivilised/cobrass/generators/gola/internal/storage" + nef "github.com/snivilised/nefilim" ) // parseInline does not need to use the filesystem to acquire @@ -20,7 +20,7 @@ func parseInline(contents CodeContent) (*SignatureResult, error) { } // parseFromFS parses content acquired from the filesystem. -func parseFromFS(vfs storage.VirtualFS, directoryPath string) (*SignatureResult, error) { +func parseFromFS(vfs nef.ReaderFS, directoryPath string) (*SignatureResult, error) { var ( entries []fs.DirEntry contents CodeContent @@ -38,7 +38,7 @@ func parseFromFS(vfs storage.VirtualFS, directoryPath string) (*SignatureResult, return parseContents(contents) } -func readEntries(vfs storage.VirtualFS, directoryPath string) ([]fs.DirEntry, error) { +func readEntries(vfs nef.ReaderFS, directoryPath string) ([]fs.DirEntry, error) { entries, err := vfs.ReadDir(directoryPath) if err != nil { @@ -64,7 +64,7 @@ func readEntries(vfs storage.VirtualFS, directoryPath string) ([]fs.DirEntry, er return entries, nil } -func acquire(vfs storage.VirtualFS, directoryPath string, entries []fs.DirEntry) (CodeContent, error) { +func acquire(vfs nef.ReaderFS, directoryPath string, entries []fs.DirEntry) (CodeContent, error) { contents := make(CodeContent, len(entries)) for _, entry := range entries { diff --git a/generators/gola/gen/main.go b/generators/gola/gen/main.go index 7f2cc9c..a3e2d4b 100644 --- a/generators/gola/gen/main.go +++ b/generators/gola/gen/main.go @@ -9,7 +9,7 @@ import ( "github.com/samber/lo" "github.com/snivilised/cobrass/generators/gola" - "github.com/snivilised/cobrass/generators/gola/internal/storage" + nef "github.com/snivilised/nefilim" ) const ( @@ -33,7 +33,7 @@ func main() { flag.Parse() outputPath := lo.Ternary(*testFlag, testPath, sourcePath) - nativeFS := storage.UseNativeFS() + nativeFS := nef.NewUniversalABS() if *signFlag { sign(nativeFS, outputPath) @@ -62,7 +62,7 @@ func fail(reason string, callback ...func()) { os.Exit(outputPathNotFoundExitCode) } -func gen(vfs storage.VirtualFS, outputPath string) { +func gen(fS nef.UniversalFS, outputPath string) { if *cwdFlag == "" { fail("๐Ÿ”ฅ current working directory not specified") } @@ -70,7 +70,7 @@ func gen(vfs storage.VirtualFS, outputPath string) { absolutePath, _ := filepath.Abs(*cwdFlag) absolutePath = filepath.Join(absolutePath, outputPath) - if !vfs.DirectoryExists(absolutePath) { + if !fS.DirectoryExists(absolutePath) { callback := func() { fmt.Printf("๐Ÿ’ฅ ---> CWD: '%v' \n", *cwdFlag) fmt.Printf("๐Ÿ’ฅ ---> OUTPUT: '%v' \n", outputPath) @@ -81,7 +81,7 @@ func gen(vfs storage.VirtualFS, outputPath string) { return } - sourceCode := gola.NewSourceCodeContainer(vfs, absolutePath, *templatesSubPathFlag) + sourceCode := gola.NewSourceCodeContainer(fS, absolutePath, *templatesSubPathFlag) mode := lo.Ternary(*testFlag, "๐Ÿงช Test", "๐ŸŽ Source") fmt.Printf("โ˜‘๏ธ ---> CWD: '%v' \n", *cwdFlag) @@ -92,7 +92,7 @@ func gen(vfs storage.VirtualFS, outputPath string) { if !*testFlag { if sourceCode.AnyMissing() { sourceCode.Verify(func(entry *gola.SourceCodeData) { - exists := vfs.FileExists(entry.FullPath()) + exists := fS.FileExists(entry.FullPath()) indicator := lo.Ternary(exists, "โœ”๏ธ", "โŒ") status := lo.Ternary(exists, "exists", "missing") path := entry.FullPath() @@ -114,10 +114,10 @@ func gen(vfs storage.VirtualFS, outputPath string) { show(result) } -func sign(vfs storage.VirtualFS, sourcePath string) { +func sign(fS nef.UniversalFS, sourcePath string) { templatesSubPath := "" - sourceCode := gola.NewSourceCodeContainer(vfs, sourcePath, templatesSubPath) + sourceCode := gola.NewSourceCodeContainer(fS, sourcePath, templatesSubPath) result, err := sourceCode.Signature() if err != nil { diff --git a/generators/gola/gola_suite_test.go b/generators/gola/gola-suite_test.go similarity index 100% rename from generators/gola/gola_suite_test.go rename to generators/gola/gola-suite_test.go diff --git a/generators/gola/gomega-matchers_test.go b/generators/gola/gomega-matchers_test.go index 483e5e2..fc1f9c4 100644 --- a/generators/gola/gomega-matchers_test.go +++ b/generators/gola/gomega-matchers_test.go @@ -6,20 +6,20 @@ import ( "github.com/samber/lo" "github.com/snivilised/cobrass/generators/gola" - "github.com/snivilised/cobrass/generators/gola/internal/storage" + nef "github.com/snivilised/nefilim" . "github.com/onsi/gomega/types" //nolint:revive // gomega ok ) type ( AreAllSourceCodeFilesPresentMatcher struct { - fs storage.VirtualFS + fs nef.UniversalFS directory string } ) // ContainAllSourceCodeFilesAt -func ContainAllSourceCodeFilesAt(fs storage.VirtualFS, directory string) GomegaMatcher { +func ContainAllSourceCodeFilesAt(fs nef.UniversalFS, directory string) GomegaMatcher { return &AreAllSourceCodeFilesPresentMatcher{ fs: fs, directory: directory, diff --git a/generators/gola/internal/storage/mem-fs.go b/generators/gola/internal/storage/mem-fs.go deleted file mode 100644 index 5347440..0000000 --- a/generators/gola/internal/storage/mem-fs.go +++ /dev/null @@ -1,53 +0,0 @@ -package storage - -import ( - "os" - - "github.com/avfs/avfs/vfs/memfs" -) - -type memFS struct { - backend VirtualBackend - mfs *memfs.MemFS -} - -func UseMemFS() VirtualFS { - return &memFS{ - backend: "mem", - mfs: memfs.New(), - } -} - -func (fs *memFS) FileExists(path string) bool { - result := false - if info, err := fs.mfs.Lstat(path); err == nil { - result = !info.IsDir() - } - - return result -} - -func (fs *memFS) DirectoryExists(path string) bool { - result := false - if info, err := fs.mfs.Lstat(path); err == nil { - result = info.IsDir() - } - - return result -} - -func (fs *memFS) MkdirAll(path string, perm os.FileMode) error { - return fs.mfs.MkdirAll(path, perm) -} - -func (fs *memFS) WriteFile(name string, data []byte, perm os.FileMode) error { - return fs.mfs.WriteFile(name, data, perm) -} - -func (fs *memFS) ReadFile(name string) ([]byte, error) { - return fs.mfs.ReadFile(name) -} - -func (fs *memFS) ReadDir(name string) ([]os.DirEntry, error) { - return fs.mfs.ReadDir(name) -} diff --git a/generators/gola/internal/storage/native-fs.go b/generators/gola/internal/storage/native-fs.go deleted file mode 100644 index 365869b..0000000 --- a/generators/gola/internal/storage/native-fs.go +++ /dev/null @@ -1,49 +0,0 @@ -package storage - -import ( - "os" -) - -type nativeFS struct { - backend VirtualBackend -} - -func UseNativeFS() VirtualFS { - return &nativeFS{ - backend: "native", - } -} - -func (fs *nativeFS) FileExists(path string) bool { - result := false - if info, err := os.Lstat(path); err == nil { - result = !info.IsDir() - } - - return result -} - -func (fs *nativeFS) DirectoryExists(path string) bool { - result := false - if info, err := os.Lstat(path); err == nil { - result = info.IsDir() - } - - return result -} - -func (fs *nativeFS) MkdirAll(path string, perm os.FileMode) error { - return os.MkdirAll(path, perm) -} - -func (fs *nativeFS) WriteFile(name string, data []byte, perm os.FileMode) error { - return os.WriteFile(name, data, perm) -} - -func (fs *nativeFS) ReadFile(name string) ([]byte, error) { - return os.ReadFile(name) -} - -func (fs *nativeFS) ReadDir(name string) ([]os.DirEntry, error) { - return os.ReadDir(name) -} diff --git a/generators/gola/internal/storage/storage-defs.go b/generators/gola/internal/storage/storage-defs.go deleted file mode 100644 index d0e2aa3..0000000 --- a/generators/gola/internal/storage/storage-defs.go +++ /dev/null @@ -1,46 +0,0 @@ -package storage - -import ( - "os" -) - -type filepathAPI interface { - // Intended only for those filepath methods that actually affect the - // filesystem. Eg: there is no point in replicating methods like - // filepath.Join here they are just path helpers that do not read/write - // to the filesystem. - // Currently, there is no requirement for using any filepath methods - // with the golang generator, hence nothing is defined here. We may - // want to replicate this filesystem model in other contexts, so this - // will serve as a reminder in the intended use of this interface. -} - -type ExistsInFS interface { - FileExists(path string) bool - DirectoryExists(path string) bool -} - -type ReadFromFS interface { - ReadFile(name string) ([]byte, error) - ReadDir(name string) ([]os.DirEntry, error) -} - -type WriteToFS interface { - MkdirAll(path string, perm os.FileMode) error - WriteFile(name string, data []byte, perm os.FileMode) error -} - -type ReadOnlyVirtualFS interface { - filepathAPI - ExistsInFS - ReadFromFS -} - -type VirtualFS interface { - filepathAPI - ExistsInFS - ReadFromFS - WriteToFS -} - -type VirtualBackend string diff --git a/generators/gola/signature_test.go b/generators/gola/signature_test.go index 3b52f16..d28e36b 100644 --- a/generators/gola/signature_test.go +++ b/generators/gola/signature_test.go @@ -6,10 +6,10 @@ import ( "os" "path/filepath" - . "github.com/onsi/ginkgo/v2" //nolint:revive // ginkgo ok - . "github.com/onsi/gomega" //nolint:revive // gpmega ok + . "github.com/onsi/ginkgo/v2" //nolint:revive // ok + . "github.com/onsi/gomega" //nolint:revive // ok "github.com/snivilised/cobrass/generators/gola" - "github.com/snivilised/cobrass/generators/gola/internal/storage" + nef "github.com/snivilised/nefilim" ) var ( @@ -22,8 +22,8 @@ type setupFile struct { data []byte } -func setup(fs storage.VirtualFS, directoryPath string, files ...setupFile) { - if e := fs.MkdirAll(directoryPath, faydeaudeau); e != nil { +func setup(fs nef.UniversalFS, directoryPath string, files ...setupFile) { + if e := fs.MakeDirAll(directoryPath, faydeaudeau); e != nil { Fail(e.Error()) } @@ -43,7 +43,7 @@ func setup(fs storage.VirtualFS, directoryPath string, files ...setupFile) { // having to over-write the source code. Only when the new defined generated code // is deemed to be correct, the existing code can be overridden. -var _ = Describe("Signature", Ordered, func() { +var _ = XDescribe("Signature", Ordered, func() { var ( repo, testPath, @@ -62,7 +62,9 @@ var _ = Describe("Signature", Ordered, func() { Context("and: Test mode", func() { Context("and: without write", func() { It("๐Ÿงช should: return hash result of newly generated content", func() { - mfs := storage.UseMemFS() + // use mapFile + // + mfs := nef.NewUniversalABS() templatesSubPath := "" outputPath = filepath.Join(repo, testPath) @@ -97,7 +99,7 @@ var _ = Describe("Signature", Ordered, func() { Context("and: Source mode", func() { Context("and: without write", func() { It("๐Ÿงช should: return hash result of src/assistant/*auto*.go", func() { - nfs := storage.UseNativeFS() + nfs := nef.NewUniversalABS() // TODO: check templatesSubPath := "" outputPath = filepath.Join(repo, sourcePath) @@ -119,7 +121,7 @@ var _ = Describe("Signature", Ordered, func() { Context("and: Test mode", func() { Context("and: without write", func() { It("๐Ÿงช should: return hash result of parsed contents sources", func() { - nfs := storage.UseNativeFS() + nfs := nef.NewUniversalABS() templatesSubPath := "" outputPath = filepath.Join(repo, testPath) sourceCode := gola.NewSourceCodeContainer(nfs, outputPath, templatesSubPath) @@ -134,7 +136,7 @@ var _ = Describe("Signature", Ordered, func() { Context("and: with write", func() { It("๐Ÿงช should: return hash result of generators/gola/out/assistant/*auto*.go", func() { - mfs := storage.UseMemFS() + mfs := nef.NewUniversalABS() // use mapFS templatesSubPath := "" outputPath = filepath.Join(repo, testPath) diff --git a/generators/gola/source-code-container.go b/generators/gola/source-code-container.go index 2eec25c..0f3b530 100644 --- a/generators/gola/source-code-container.go +++ b/generators/gola/source-code-container.go @@ -8,13 +8,13 @@ import ( "github.com/samber/lo" "github.com/snivilised/cobrass/generators/gola/internal/collections" - "github.com/snivilised/cobrass/generators/gola/internal/storage" + nef "github.com/snivilised/nefilim" ) type sourceCodeDataCollection = collections.OrderedKeysMap[CodeFileName, *SourceCodeData] type SourceCodeContainer struct { - vfs storage.VirtualFS + vfs nef.UniversalFS absolutePath string templatesSubPath string collection sourceCodeDataCollection @@ -166,7 +166,7 @@ func (d *SourceCodeContainer) Signature() (*SignatureResult, error) { } func NewSourceCodeContainer( - vfs storage.VirtualFS, + vfs nef.UniversalFS, absolutePath string, templatesSubPath string, ) *SourceCodeContainer { diff --git a/generators/gola/source-code-data.go b/generators/gola/source-code-data.go index 5106da6..d94bce1 100644 --- a/generators/gola/source-code-data.go +++ b/generators/gola/source-code-data.go @@ -12,12 +12,11 @@ import ( type CodeFileName string type SourceCodeData struct { - name CodeFileName - active bool // THIS IS JUST TEMPORARY - directory string - rootContent string - templ *template.Template - funcs map[string]any + name CodeFileName + active bool // THIS IS JUST TEMPORARY + directory string + templ *template.Template + funcs map[string]any } func (d *SourceCodeData) OutputFileName() string { diff --git a/generators/gola/source-code-data_test.go b/generators/gola/source-code-data_test.go index d434860..680ad5f 100644 --- a/generators/gola/source-code-data_test.go +++ b/generators/gola/source-code-data_test.go @@ -9,7 +9,7 @@ import ( . "github.com/onsi/gomega" //nolint:revive // gomega ok "github.com/snivilised/cobrass/generators/gola" - "github.com/snivilised/cobrass/generators/gola/internal/storage" + nef "github.com/snivilised/nefilim" ) func Path(parent, relative string) string { @@ -25,27 +25,27 @@ func Repo(relative string) string { var _ = Describe("SourceCodeData", Ordered, func() { var ( repo, testPath, sourcePath string - fs storage.VirtualFS + fS nef.UniversalFS ) BeforeAll(func() { repo = Repo("../..") testPath = filepath.Join("generators", "gola", "out", "assistant") sourcePath = filepath.Join("src", "assistant") - fs = storage.UseNativeFS() + fS = nef.NewUniversalABS() _ = testPath }) Context("AnyMissing", func() { When("source mode", func() { - It("๐Ÿงช should: find all source code files are present", func() { + XIt("๐Ÿงช should: find all source code files are present", func() { outputPath := filepath.Join(repo, sourcePath) templatesSubPath := "" - sourceContainer := gola.NewSourceCodeContainer(fs, outputPath, templatesSubPath) + sourceContainer := gola.NewSourceCodeContainer(fS, outputPath, templatesSubPath) Expect(sourceContainer).To(ContainAllSourceCodeFilesAt( - fs, outputPath, + fS, outputPath, )) }) }) diff --git a/generators/gola/source-code-generator.go b/generators/gola/source-code-generator.go index 9c0c9ce..f76a12c 100644 --- a/generators/gola/source-code-generator.go +++ b/generators/gola/source-code-generator.go @@ -7,7 +7,7 @@ import ( "path" "github.com/samber/lo" - "github.com/snivilised/cobrass/generators/gola/internal/storage" + nef "github.com/snivilised/nefilim" ) var ( @@ -17,7 +17,7 @@ var ( ) type SourceCodeGenerator struct { - vfs storage.VirtualFS + vfs nef.UniversalFS sourceCodeCollection sourceCodeDataCollection types typeCollection operators operatorCollection @@ -157,7 +157,7 @@ func (g *SourceCodeGenerator) flush(outputPath string, yield *generatedYield) er faydeaudeau := 0o777 directory := path.Dir(outputPath) - if err := g.vfs.MkdirAll(directory, os.FileMode(faydeaudeau)); err != nil { + if err := g.vfs.MakeDirAll(directory, os.FileMode(faydeaudeau)); err != nil { return fmt.Errorf("failed to ensure parent directory '%v' exists (%v)", directory, err) } diff --git a/generators/gola/source-code-generator_test.go b/generators/gola/source-code-generator_test.go index b40dce8..06bb59a 100644 --- a/generators/gola/source-code-generator_test.go +++ b/generators/gola/source-code-generator_test.go @@ -7,27 +7,27 @@ import ( . "github.com/onsi/gomega" //nolint:revive // gomega ok "github.com/snivilised/cobrass/generators/gola" - "github.com/snivilised/cobrass/generators/gola/internal/storage" + nef "github.com/snivilised/nefilim" ) var _ = Describe("SourceCodeGenerator", Ordered, func() { var ( repo, testPath, sourcePath string - fs storage.VirtualFS + fs nef.UniversalFS ) BeforeAll(func() { repo = Repo("../..") testPath = filepath.Join("generators", "gola", "out", "assistant") sourcePath = filepath.Join("src", "assistant") - fs = storage.UseMemFS() + fs = nef.NewUniversalABS() // use mapFS _ = sourcePath }) Context("AnyMissing", func() { When("test mode", func() { - It("should: find all source code files are present", func() { + XIt("should: find all source code files are present", func() { outputPath := filepath.Join(repo, testPath) templatesSubPath := "" codeContainer := gola.NewSourceCodeContainer(fs, outputPath, templatesSubPath) diff --git a/go.mod b/go.mod index a57f571..d7d9355 100644 --- a/go.mod +++ b/go.mod @@ -3,10 +3,10 @@ module github.com/snivilised/cobrass go 1.23.0 require ( - github.com/avfs/avfs v0.33.0 github.com/onsi/ginkgo/v2 v2.20.2 github.com/onsi/gomega v1.34.2 github.com/snivilised/li18ngo v0.1.7 + github.com/snivilised/nefilim v0.1.4 github.com/spf13/cobra v1.8.1 github.com/spf13/pflag v1.0.5 go.uber.org/mock v0.5.0 @@ -25,7 +25,6 @@ require ( github.com/pkg/errors v0.9.1 // indirect github.com/sagikazarmark/locafero v0.4.0 // indirect github.com/sagikazarmark/slog-shim v0.1.0 // indirect - github.com/snivilised/nefilim v0.1.4 // indirect github.com/sourcegraph/conc v0.3.0 // indirect github.com/spf13/afero v1.11.0 // indirect github.com/spf13/cast v1.6.0 // indirect diff --git a/go.sum b/go.sum index 9ae047e..6d7390a 100644 --- a/go.sum +++ b/go.sum @@ -1,7 +1,5 @@ github.com/BurntSushi/toml v1.4.0 h1:kuoIxZQy2WRRk1pttg9asf+WVv6tWQuBNVmK8+nqPr0= github.com/BurntSushi/toml v1.4.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho= -github.com/avfs/avfs v0.33.0 h1:5WQXbUbr6VS7aani39ZN2Vrd/s3wLnyih1Sc4ExWTxs= -github.com/avfs/avfs v0.33.0/go.mod h1:Q59flcFRYe9KYkNMfrLUJney3yeKGQpcWRyxsDBW7vI= github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= From 08060921461944f23bfc518504fb6e91d264744d Mon Sep 17 00:00:00 2001 From: plastikfan Date: Thu, 24 Oct 2024 18:53:58 +0100 Subject: [PATCH 6/8] ref: minor renames (#310) --- generators/gola/content-parser.go | 14 ++++++------ generators/gola/signature_test.go | 15 +++++++++---- generators/gola/source-code-container.go | 12 +++++------ generators/gola/source-code-generator.go | 27 ++++++++++++++++++------ 4 files changed, 44 insertions(+), 24 deletions(-) diff --git a/generators/gola/content-parser.go b/generators/gola/content-parser.go index 1d71172..2ef8834 100644 --- a/generators/gola/content-parser.go +++ b/generators/gola/content-parser.go @@ -20,26 +20,26 @@ func parseInline(contents CodeContent) (*SignatureResult, error) { } // parseFromFS parses content acquired from the filesystem. -func parseFromFS(vfs nef.ReaderFS, directoryPath string) (*SignatureResult, error) { +func parseFromFS(fS nef.ReaderFS, directoryPath string) (*SignatureResult, error) { var ( entries []fs.DirEntry contents CodeContent readErr, acqErr error ) - if entries, readErr = readEntries(vfs, directoryPath); readErr != nil { + if entries, readErr = readEntries(fS, directoryPath); readErr != nil { return nil, readErr } - if contents, acqErr = acquire(vfs, directoryPath, entries); acqErr != nil { + if contents, acqErr = acquire(fS, directoryPath, entries); acqErr != nil { return nil, acqErr } return parseContents(contents) } -func readEntries(vfs nef.ReaderFS, directoryPath string) ([]fs.DirEntry, error) { - entries, err := vfs.ReadDir(directoryPath) +func readEntries(fS nef.ReaderFS, directoryPath string) ([]fs.DirEntry, error) { + entries, err := fS.ReadDir(directoryPath) if err != nil { return nil, err @@ -64,13 +64,13 @@ func readEntries(vfs nef.ReaderFS, directoryPath string) ([]fs.DirEntry, error) return entries, nil } -func acquire(vfs nef.ReaderFS, directoryPath string, entries []fs.DirEntry) (CodeContent, error) { +func acquire(fS nef.ReaderFS, directoryPath string, entries []fs.DirEntry) (CodeContent, error) { contents := make(CodeContent, len(entries)) for _, entry := range entries { name := entry.Name() sourcePath := filepath.Join(directoryPath, name) - c, err := vfs.ReadFile(sourcePath) + c, err := fS.ReadFile(sourcePath) if err != nil { return nil, err diff --git a/generators/gola/signature_test.go b/generators/gola/signature_test.go index d28e36b..4fc8c90 100644 --- a/generators/gola/signature_test.go +++ b/generators/gola/signature_test.go @@ -3,6 +3,7 @@ package gola_test import ( _ "embed" "fmt" + "io/fs" "os" "path/filepath" @@ -13,8 +14,14 @@ import ( ) var ( - faydeaudeau = os.FileMode(0o777) - beezledub = os.FileMode(0o666) + // to go into a lab + Perms = struct { + File fs.FileMode + Dir fs.FileMode + }{ + File: 0o666, //nolint:mnd // ok (pedantic) + Dir: 0o777, //nolint:mnd // ok (pedantic) + } ) type setupFile struct { @@ -23,12 +30,12 @@ type setupFile struct { } func setup(fs nef.UniversalFS, directoryPath string, files ...setupFile) { - if e := fs.MakeDirAll(directoryPath, faydeaudeau); e != nil { + if e := fs.MakeDirAll(directoryPath, Perms.Dir); e != nil { Fail(e.Error()) } for _, f := range files { - if e := fs.WriteFile(f.path, f.data, beezledub); e != nil { + if e := fs.WriteFile(f.path, f.data, Perms.File); e != nil { Fail(e.Error()) } } diff --git a/generators/gola/source-code-container.go b/generators/gola/source-code-container.go index 0f3b530..8c4dcf9 100644 --- a/generators/gola/source-code-container.go +++ b/generators/gola/source-code-container.go @@ -14,7 +14,7 @@ import ( type sourceCodeDataCollection = collections.OrderedKeysMap[CodeFileName, *SourceCodeData] type SourceCodeContainer struct { - vfs nef.UniversalFS + fS nef.UniversalFS absolutePath string templatesSubPath string collection sourceCodeDataCollection @@ -107,7 +107,7 @@ func (d *SourceCodeContainer) contentPath() string { func (d *SourceCodeContainer) AnyMissing() bool { return d.ForEachUntil(func(data *SourceCodeData) bool { - return !d.vfs.FileExists(data.FullPath()) + return !d.fS.FileExists(data.FullPath()) }) } @@ -148,7 +148,7 @@ func (d *SourceCodeContainer) Generator( doWrite bool, ) *SourceCodeGenerator { generator := &SourceCodeGenerator{ - vfs: d.vfs, + fS: d.fS, doWrite: doWrite, sourceCodeCollection: d.collection, } @@ -162,16 +162,16 @@ func (d *SourceCodeContainer) Generator( // Signature used to compose the SHA256 hash of // pre-generated source code. func (d *SourceCodeContainer) Signature() (*SignatureResult, error) { - return parseFromFS(d.vfs, d.contentPath()) + return parseFromFS(d.fS, d.contentPath()) } func NewSourceCodeContainer( - vfs nef.UniversalFS, + fS nef.UniversalFS, absolutePath string, templatesSubPath string, ) *SourceCodeContainer { container := &SourceCodeContainer{ - vfs: vfs, + fS: fS, absolutePath: absolutePath, templatesSubPath: templatesSubPath, } diff --git a/generators/gola/source-code-generator.go b/generators/gola/source-code-generator.go index f76a12c..b20adcb 100644 --- a/generators/gola/source-code-generator.go +++ b/generators/gola/source-code-generator.go @@ -3,6 +3,7 @@ package gola import ( _ "embed" "fmt" + "io/fs" "os" "path" @@ -14,10 +15,18 @@ var ( noData = struct{}{} //go:embed signature.GO-HASH.txt RegisteredHash string + + Perms = struct { + File fs.FileMode + Dir fs.FileMode + }{ + File: 0o666, //nolint:mnd // ok (pedantic) + Dir: 0o777, //nolint:mnd // ok (pedantic) + } ) type SourceCodeGenerator struct { - vfs nef.UniversalFS + fS nef.UniversalFS sourceCodeCollection sourceCodeDataCollection types typeCollection operators operatorCollection @@ -56,7 +65,7 @@ func (g *SourceCodeGenerator) Run() (*SignatureResult, error) { for _, k := range g.sourceCodeCollection.Keys() { page := g.sourceCodeCollection[k] yield := &generatedYield{} - overwrite := lo.Ternary(g.vfs.FileExists(page.FullPath()), "โ™ป๏ธ overwrite", "โœจ new") + overwrite := lo.Ternary(g.fS.FileExists(page.FullPath()), "โ™ป๏ธ overwrite", "โœจ new") if !page.active { fmt.Printf("===> ๐Ÿ“› (%v) SKIPPING generation of code to '%v' (%v)\n", @@ -154,16 +163,20 @@ func (g *SourceCodeGenerator) signature(content CodeContent) (*SignatureResult, } func (g *SourceCodeGenerator) flush(outputPath string, yield *generatedYield) error { - faydeaudeau := 0o777 directory := path.Dir(outputPath) - if err := g.vfs.MakeDirAll(directory, os.FileMode(faydeaudeau)); err != nil { + if err := g.fS.MakeDirAll( + directory, + os.FileMode(Perms.Dir), + ); err != nil { return fmt.Errorf("failed to ensure parent directory '%v' exists (%v)", directory, err) } - beezledub := 0o666 - - if err := g.vfs.WriteFile(outputPath, yield.buffer.Bytes(), os.FileMode(beezledub)); err != nil { + if err := g.fS.WriteFile( + outputPath, + yield.buffer.Bytes(), + os.FileMode(Perms.File), + ); err != nil { return fmt.Errorf("failed to write generated code to '%v' (%v)", outputPath, err) } From db03b4496b5643570d77e87c2617a15c9033f14b Mon Sep 17 00:00:00 2001 From: plastikfan Date: Thu, 24 Oct 2024 19:03:47 +0100 Subject: [PATCH 7/8] ref: rename helpers pkg to lab (#310) --- .golangci.yml | 3 +++ generators/gola/signature_test.go | 10 +++++----- generators/gola/source-code-generator.go | 5 ++--- src/assistant/enum_test.go | 7 +++---- src/assistant/get-third-party-cl_test.go | 8 ++++---- .../locale/messages-native-errors_test.go | 4 ++-- .../locale/messages-validation-errors_test.go | 8 ++++---- src/assistant/param-set-auto_test.go | 7 +++---- src/assistant/param-set_test.go | 15 +++++++-------- src/internal/{helpers => lab}/call.go | 2 +- src/internal/{helpers => lab}/execute-command.go | 2 +- .../{helpers => lab}/execute-command_test.go | 6 +++--- .../helpers-suite_test.go} | 2 +- src/internal/{helpers => lab}/test-utilities.go | 2 +- src/store/families_test.go | 10 +++++----- 15 files changed, 45 insertions(+), 46 deletions(-) rename src/internal/{helpers => lab}/call.go (97%) rename src/internal/{helpers => lab}/execute-command.go (96%) rename src/internal/{helpers => lab}/execute-command_test.go (88%) rename src/internal/{helpers/helpers_suite_test.go => lab/helpers-suite_test.go} (91%) rename src/internal/{helpers => lab}/test-utilities.go (95%) diff --git a/.golangci.yml b/.golangci.yml index 7ac922c..4bf0e90 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -66,6 +66,9 @@ issues: fix: true exclude: - "cuddle" + exclude-files: + - ".*-auto\\.go$" + - ".*-auto_test\\.go$" run: issues-exit-code: 1 diff --git a/generators/gola/signature_test.go b/generators/gola/signature_test.go index 4fc8c90..35b1136 100644 --- a/generators/gola/signature_test.go +++ b/generators/gola/signature_test.go @@ -19,8 +19,8 @@ var ( File fs.FileMode Dir fs.FileMode }{ - File: 0o666, //nolint:mnd // ok (pedantic) - Dir: 0o777, //nolint:mnd // ok (pedantic) + File: 0o666, + Dir: 0o777, } ) @@ -29,13 +29,13 @@ type setupFile struct { data []byte } -func setup(fs nef.UniversalFS, directoryPath string, files ...setupFile) { - if e := fs.MakeDirAll(directoryPath, Perms.Dir); e != nil { +func setup(fS nef.UniversalFS, directoryPath string, files ...setupFile) { + if e := fS.MakeDirAll(directoryPath, Perms.Dir); e != nil { Fail(e.Error()) } for _, f := range files { - if e := fs.WriteFile(f.path, f.data, Perms.File); e != nil { + if e := fS.WriteFile(f.path, f.data, Perms.File); e != nil { Fail(e.Error()) } } diff --git a/generators/gola/source-code-generator.go b/generators/gola/source-code-generator.go index b20adcb..c4e5de6 100644 --- a/generators/gola/source-code-generator.go +++ b/generators/gola/source-code-generator.go @@ -4,7 +4,6 @@ import ( _ "embed" "fmt" "io/fs" - "os" "path" "github.com/samber/lo" @@ -167,7 +166,7 @@ func (g *SourceCodeGenerator) flush(outputPath string, yield *generatedYield) er if err := g.fS.MakeDirAll( directory, - os.FileMode(Perms.Dir), + Perms.Dir, ); err != nil { return fmt.Errorf("failed to ensure parent directory '%v' exists (%v)", directory, err) } @@ -175,7 +174,7 @@ func (g *SourceCodeGenerator) flush(outputPath string, yield *generatedYield) er if err := g.fS.WriteFile( outputPath, yield.buffer.Bytes(), - os.FileMode(Perms.File), + Perms.File, ); err != nil { return fmt.Errorf("failed to write generated code to '%v' (%v)", outputPath, err) } diff --git a/src/assistant/enum_test.go b/src/assistant/enum_test.go index ecde1c3..3473656 100644 --- a/src/assistant/enum_test.go +++ b/src/assistant/enum_test.go @@ -9,11 +9,10 @@ import ( . "github.com/onsi/ginkgo/v2" //nolint:revive // ginkgo ok . "github.com/onsi/gomega" //nolint:revive // gomega ok "github.com/samber/lo" + "github.com/snivilised/cobrass/src/assistant" + "github.com/snivilised/cobrass/src/internal/lab" "github.com/spf13/cobra" "github.com/spf13/pflag" - - "github.com/snivilised/cobrass/src/assistant" - "github.com/snivilised/cobrass/src/internal/helpers" ) var _ = Describe("Enum", func() { @@ -231,7 +230,7 @@ var _ = Describe("Enum", func() { &outputFormatEnum.Source, ) - _, _ = helpers.ExecuteCommand( + _, _ = lab.ExecuteCommand( rootCommand, "widget", "/usr/fuse/home/music", "--format=xml", ) diff --git a/src/assistant/get-third-party-cl_test.go b/src/assistant/get-third-party-cl_test.go index 00e6f8a..b3e0ebf 100644 --- a/src/assistant/get-third-party-cl_test.go +++ b/src/assistant/get-third-party-cl_test.go @@ -11,7 +11,7 @@ import ( "github.com/snivilised/cobrass/src/assistant" "github.com/snivilised/cobrass/src/assistant/locale" "github.com/snivilised/cobrass/src/clif" - "github.com/snivilised/cobrass/src/internal/helpers" + "github.com/snivilised/cobrass/src/internal/lab" "github.com/snivilised/cobrass/src/store" "github.com/snivilised/li18ngo" ) @@ -41,8 +41,8 @@ var _ = Describe("GetThirdPartyCL", Ordered, func() { ) BeforeAll(func() { - repo = helpers.Repo("../..") - l10nPath = helpers.Path(repo, "Test/data/l10n") + repo = lab.Repo("../..") + l10nPath = lab.Path(repo, "Test/data/l10n") from = li18ngo.LoadFrom{ Path: l10nPath, @@ -84,7 +84,7 @@ var _ = Describe("GetThirdPartyCL", Ordered, func() { paramSet = assistant.NewParamSet[store.ProfileParameterSet](rootCommand) paramSet.Native.BindAll(paramSet, rootCommand.PersistentFlags()) - _, err := helpers.ExecuteCommand( + _, err := lab.ExecuteCommand( rootCommand, args..., ) diff --git a/src/assistant/locale/messages-native-errors_test.go b/src/assistant/locale/messages-native-errors_test.go index 401cbb9..e2a61f6 100644 --- a/src/assistant/locale/messages-native-errors_test.go +++ b/src/assistant/locale/messages-native-errors_test.go @@ -7,7 +7,7 @@ import ( . "github.com/onsi/gomega" //nolint:revive // gomega ok "github.com/snivilised/cobrass/src/assistant/locale" - "github.com/snivilised/cobrass/src/internal/helpers" + "github.com/snivilised/cobrass/src/internal/lab" ) type nativeEntry struct { @@ -20,7 +20,7 @@ var _ = Describe("MessagesNativeErrors", func() { DescribeTable("Native Errors", func(entry nativeEntry) { - err := helpers.CallE(entry.Fn, entry.Args) + err := lab.CallE(entry.Fn, entry.Args) GinkgoWriter.Printf("โš ๏ธ NATIVE-ERROR-RESULT: %v", err) Expect(err).Error().NotTo(BeNil()) }, diff --git a/src/assistant/locale/messages-validation-errors_test.go b/src/assistant/locale/messages-validation-errors_test.go index 297e69d..bbf0214 100644 --- a/src/assistant/locale/messages-validation-errors_test.go +++ b/src/assistant/locale/messages-validation-errors_test.go @@ -7,7 +7,7 @@ import ( . "github.com/onsi/gomega" //nolint:revive // gomega ok "github.com/snivilised/cobrass/src/assistant/locale" - "github.com/snivilised/cobrass/src/internal/helpers" + "github.com/snivilised/cobrass/src/internal/lab" "github.com/snivilised/li18ngo" ) @@ -28,8 +28,8 @@ var _ = Describe("MessagesValidationErrors", Ordered, func() { ) BeforeAll(func() { - repo = helpers.Repo("../..") - l10nPath = helpers.Path(repo, "Test/data/l10n") + repo = lab.Repo("../..") + l10nPath = lab.Path(repo, "Test/data/l10n") from = li18ngo.LoadFrom{ Path: l10nPath, @@ -48,7 +48,7 @@ var _ = Describe("MessagesValidationErrors", Ordered, func() { // these tests may not be required, because they may be able to be generated DescribeTable("Native Errors", func(entry validationEntry) { - err := helpers.CallE(entry.Fn, entry.Args) + err := lab.CallE(entry.Fn, entry.Args) GinkgoWriter.Printf("VALIDATION-ERROR-RESULT: %v", err) fmt.Printf("โš ๏ธ VALIDATION-ERROR-RESULT(%v): '%v'\n", entry.Name, err) Expect(err).Error().NotTo(BeNil()) diff --git a/src/assistant/param-set-auto_test.go b/src/assistant/param-set-auto_test.go index 314b51e..f71ba48 100644 --- a/src/assistant/param-set-auto_test.go +++ b/src/assistant/param-set-auto_test.go @@ -6,10 +6,9 @@ import ( . "github.com/onsi/ginkgo/v2" //nolint:revive // ginkgo ok . "github.com/onsi/gomega" //nolint:revive // gomega ok - "github.com/spf13/cobra" - "github.com/snivilised/cobrass/src/assistant" - "github.com/snivilised/cobrass/src/internal/helpers" + "github.com/snivilised/cobrass/src/internal/lab" + "github.com/spf13/cobra" ) // the auto version of param-set_test.go @@ -62,7 +61,7 @@ var _ = Describe("ParamSet (auto)", func() { func(entry TcEntry) { entry.Binder() - _, _ = helpers.ExecuteCommand( + _, _ = lab.ExecuteCommand( rootCommand, "widget", "/usr/fuse/home/music", entry.CommandLine, ) entry.Assert() diff --git a/src/assistant/param-set_test.go b/src/assistant/param-set_test.go index 9666b38..579e3a4 100644 --- a/src/assistant/param-set_test.go +++ b/src/assistant/param-set_test.go @@ -7,10 +7,9 @@ import ( . "github.com/onsi/ginkgo/v2" //nolint:revive // ginkgo ok . "github.com/onsi/gomega" //nolint:revive // gomega ok "github.com/samber/lo" - "github.com/spf13/cobra" - "github.com/snivilised/cobrass/src/assistant" - "github.com/snivilised/cobrass/src/internal/helpers" + "github.com/snivilised/cobrass/src/internal/lab" + "github.com/spf13/cobra" ) type TcEntry struct { @@ -76,7 +75,7 @@ var _ = Describe("ParamSet (manual)", func() { entry.Binder() GinkgoWriter.Printf("๐Ÿง๐Ÿง๐Ÿง ABOUT TO RUN ...\n") - _, _ = helpers.ExecuteCommand( + _, _ = lab.ExecuteCommand( rootCommand, "widget", "/usr/fuse/home/music", entry.CommandLine, ) GinkgoWriter.Printf("๐Ÿง๐Ÿง๐Ÿง AFTER RUN\n") @@ -137,7 +136,7 @@ var _ = Describe("ParamSet (manual)", func() { container.MustRegisterParamSet(psname, paramSet) commandLine := "--format xml --pattern cakewalk" - _, _ = helpers.ExecuteCommand( + _, _ = lab.ExecuteCommand( rootCommand, "widget", "/usr/fuse/home/music", commandLine, ) paramSet.Native.Format = outputFormatEnum.Value() @@ -165,7 +164,7 @@ var _ = Describe("ParamSet (manual)", func() { container.MustRegisterParamSet(psname, paramSet) commandLine := "--format xml --pattern cakewalk" - _, _ = helpers.ExecuteCommand( + _, _ = lab.ExecuteCommand( rootCommand, "widget", "/usr/fuse/home/music", commandLine, ) paramSet.Native.Format = outputFormatEnum.Value() @@ -185,7 +184,7 @@ var _ = Describe("ParamSet (manual)", func() { It("๐Ÿงช should: be able get registered param set", func() { container.MustRegisterParamSet(psname, paramSet) - _, _ = helpers.ExecuteCommand( + _, _ = lab.ExecuteCommand( rootCommand, cname, "/usr/fuse/home/cache", ) @@ -263,7 +262,7 @@ var _ = Describe("ParamSet (manual)", func() { widgetCommand.PersistentFlags()), ¶mSet.Native.Pattern, ) commandLine := "--pattern=*music.infex*" - _, _ = helpers.ExecuteCommand( + _, _ = lab.ExecuteCommand( rootCommand, "widget", "/usr/fuse/home/music", commandLine, ) Expect(paramSet.Native.Pattern).To(Equal("*music.infex*")) diff --git a/src/internal/helpers/call.go b/src/internal/lab/call.go similarity index 97% rename from src/internal/helpers/call.go rename to src/internal/lab/call.go index 44666b9..3e4cacc 100644 --- a/src/internal/helpers/call.go +++ b/src/internal/lab/call.go @@ -1,4 +1,4 @@ -package helpers +package lab import ( "fmt" diff --git a/src/internal/helpers/execute-command.go b/src/internal/lab/execute-command.go similarity index 96% rename from src/internal/helpers/execute-command.go rename to src/internal/lab/execute-command.go index fbd02fd..c876c1e 100644 --- a/src/internal/helpers/execute-command.go +++ b/src/internal/lab/execute-command.go @@ -1,4 +1,4 @@ -package helpers +package lab import ( "bytes" diff --git a/src/internal/helpers/execute-command_test.go b/src/internal/lab/execute-command_test.go similarity index 88% rename from src/internal/helpers/execute-command_test.go rename to src/internal/lab/execute-command_test.go index 2a40ddc..05584fc 100644 --- a/src/internal/helpers/execute-command_test.go +++ b/src/internal/lab/execute-command_test.go @@ -1,4 +1,4 @@ -package helpers_test +package lab_test import ( "fmt" @@ -8,7 +8,7 @@ import ( . "github.com/onsi/gomega" //nolint:revive // gomega ok "github.com/spf13/cobra" - "github.com/snivilised/cobrass/src/internal/helpers" + "github.com/snivilised/cobrass/src/internal/lab" ) func emptyRun(*cobra.Command, []string) {} @@ -30,7 +30,7 @@ var _ = Describe("Execute", func() { aCmd := &cobra.Command{Use: "a", Args: cobra.NoArgs, Run: emptyRun} bCmd := &cobra.Command{Use: "b", Args: cobra.NoArgs, Run: emptyRun} rootCmd.AddCommand(aCmd, bCmd) - output, err := helpers.ExecuteCommand(rootCmd, "one", "two") + output, err := lab.ExecuteCommand(rootCmd, "one", "two") Expect(output).To(Equal(""), fmt.Sprintf( "โŒ Unexpected output '%v'", output, diff --git a/src/internal/helpers/helpers_suite_test.go b/src/internal/lab/helpers-suite_test.go similarity index 91% rename from src/internal/helpers/helpers_suite_test.go rename to src/internal/lab/helpers-suite_test.go index 480ce03..2422adb 100644 --- a/src/internal/helpers/helpers_suite_test.go +++ b/src/internal/lab/helpers-suite_test.go @@ -1,4 +1,4 @@ -package helpers_test +package lab_test import ( "testing" diff --git a/src/internal/helpers/test-utilities.go b/src/internal/lab/test-utilities.go similarity index 95% rename from src/internal/helpers/test-utilities.go rename to src/internal/lab/test-utilities.go index 8259569..8ff597e 100644 --- a/src/internal/helpers/test-utilities.go +++ b/src/internal/lab/test-utilities.go @@ -1,4 +1,4 @@ -package helpers +package lab import ( "path/filepath" diff --git a/src/store/families_test.go b/src/store/families_test.go index 66a43ee..a9c4fc9 100644 --- a/src/store/families_test.go +++ b/src/store/families_test.go @@ -9,7 +9,7 @@ import ( "github.com/snivilised/cobrass/src/assistant" "github.com/snivilised/cobrass/src/assistant/locale" - "github.com/snivilised/cobrass/src/internal/helpers" + "github.com/snivilised/cobrass/src/internal/lab" "github.com/snivilised/cobrass/src/store" "github.com/snivilised/li18ngo" ) @@ -44,8 +44,8 @@ var _ = Describe("Families", Ordered, func() { ) BeforeAll(func() { - repo = helpers.Repo("../..") - l10nPath = helpers.Path(repo, "Test/data/l10n") + repo = lab.Repo("../..") + l10nPath = lab.Path(repo, "Test/data/l10n") from = li18ngo.LoadFrom{ Path: l10nPath, @@ -61,7 +61,7 @@ var _ = Describe("Families", Ordered, func() { } execute = func(args []string) { - _, err := helpers.ExecuteCommand( + _, err := lab.ExecuteCommand( rootCommand, args..., ) Expect(err).Error().To(BeNil(), reason("BindAll", err)) @@ -409,7 +409,7 @@ var _ = Describe("Families", Ordered, func() { previewPS.Native.BindAll(previewPS) // commandLine := []string{"scorch", "--help"} - _, err := helpers.ExecuteCommand( + _, err := lab.ExecuteCommand( rootCommand, commandLine..., ) Expect(err).Error().To(BeNil(), reason("BindAll", err)) From dc22512911528b65ebd4070d9549057b0d61c9be Mon Sep 17 00:00:00 2001 From: plastikfan Date: Thu, 24 Oct 2024 21:29:36 +0100 Subject: [PATCH 8/8] ref: fix up unit tests with memory-fs (#310) --- generators/gola/hyper-gen_test.go | 4 +- generators/gola/mem-fs_test.go | 140 ++++++++++++++++++ generators/gola/signature_test.go | 53 +++---- generators/gola/source-code-data_test.go | 2 +- generators/gola/source-code-generator_test.go | 13 +- 5 files changed, 176 insertions(+), 36 deletions(-) create mode 100644 generators/gola/mem-fs_test.go diff --git a/generators/gola/hyper-gen_test.go b/generators/gola/hyper-gen_test.go index ae7f1f0..aa64910 100644 --- a/generators/gola/hyper-gen_test.go +++ b/generators/gola/hyper-gen_test.go @@ -253,8 +253,8 @@ var _ = Describe("HyperGen", Ordered, func() { } }) - Context("generate", func() { - XIt("types ...", func() { + Context("generate code", func() { + XIt("show types in console...", func() { for _, ot := range orderedTypes { if spec, ok := types[ot]; ok { generate(spec, "") diff --git a/generators/gola/mem-fs_test.go b/generators/gola/mem-fs_test.go new file mode 100644 index 0000000..d25d540 --- /dev/null +++ b/generators/gola/mem-fs_test.go @@ -0,0 +1,140 @@ +package gola_test + +import ( + "io/fs" + "os" + "strings" + "testing/fstest" + + "github.com/samber/lo" + nef "github.com/snivilised/nefilim" +) + +// nefilim should export this struct for us, so we dont have to re-implement +type TestMemFS struct { + fstest.MapFS +} + +func NewTestMemFS() *TestMemFS { + return &TestMemFS{ + MapFS: fstest.MapFS{}, + } +} + +func (f *TestMemFS) FileExists(name string) bool { + if mapFile, found := f.MapFS[name]; found && !mapFile.Mode.IsDir() { + return true + } + + return false +} + +func (f *TestMemFS) DirectoryExists(name string) bool { + if mapFile, found := f.MapFS[name]; found && mapFile.Mode.IsDir() { + return true + } + + return false +} + +func (f *TestMemFS) Create(name string) (*os.File, error) { + if _, err := f.Stat(name); err == nil { + return nil, fs.ErrExist + } + + file := &fstest.MapFile{ + Mode: Perms.File, + } + + f.MapFS[name] = file + // TODO: this needs a resolution using a file interface + // rather than using os.File which is a struct not an + // interface + dummy := &os.File{} + + return dummy, nil +} + +func (f *TestMemFS) MakeDir(name string, perm os.FileMode) error { + if !fs.ValidPath(name) { + return nef.NewInvalidPathError("MakeDir", name) + } + + if _, found := f.MapFS[name]; !found { + f.MapFS[name] = &fstest.MapFile{ + Mode: perm | os.ModeDir, + } + } + + return nil +} + +func (f *TestMemFS) MakeDirAll(name string, perm os.FileMode) error { + if !fs.ValidPath(name) { + return nef.NewInvalidPathError("MakeDirAll", name) + } + + segments := strings.Split(name, "/") + + _ = lo.Reduce(segments, + func(acc []string, s string, _ int) []string { + acc = append(acc, s) + path := strings.Join(acc, "/") + + if _, found := f.MapFS[path]; !found { + f.MapFS[path] = &fstest.MapFile{ + Mode: perm | os.ModeDir, + } + } + + return acc + }, []string{}, + ) + + return nil +} + +func (f *TestMemFS) WriteFile(name string, data []byte, perm os.FileMode) error { + if _, err := f.Stat(name); err == nil { + return fs.ErrExist + } + + f.MapFS[name] = &fstest.MapFile{ + Data: data, + Mode: perm, + } + + return nil +} + +func (f *TestMemFS) Change(_, _ string) error { + panic("NOT-IMPL: TestMemFS.Change") +} + +func (f *TestMemFS) Copy(_, _ string) error { + panic("NOT-IMPL: TestMemFS.Copy") +} + +func (f *TestMemFS) CopyFS(_ string, _ fs.FS) error { + panic("NOT-IMPL: TestMemFS.CopyFS") +} + +func (f *TestMemFS) Ensure(_ nef.PathAs) (string, error) { + panic("NOT-IMPL: TestMemFS.Ensure") +} + +func (f *TestMemFS) Move(_, _ string) error { + panic("NOT-IMPL: TestMemFS.Move") +} + +func (f *TestMemFS) Remove(_ string) error { + panic("NOT-IMPL: TestMemFS.Remove") +} + +func (f *TestMemFS) RemoveAll(_ string) error { + panic("NOT-IMPL: TestMemFS.RemoveAll") +} + +func (f *TestMemFS) Rename(_, _ string) error { + panic("NOT-IMPL: TestMemFS.Rename") +} diff --git a/generators/gola/signature_test.go b/generators/gola/signature_test.go index 35b1136..c6b16ff 100644 --- a/generators/gola/signature_test.go +++ b/generators/gola/signature_test.go @@ -14,7 +14,6 @@ import ( ) var ( - // to go into a lab Perms = struct { File fs.FileMode Dir fs.FileMode @@ -31,12 +30,12 @@ type setupFile struct { func setup(fS nef.UniversalFS, directoryPath string, files ...setupFile) { if e := fS.MakeDirAll(directoryPath, Perms.Dir); e != nil { - Fail(e.Error()) + Fail(fmt.Sprintf("%q, path: %q", e.Error(), directoryPath)) } for _, f := range files { if e := fS.WriteFile(f.path, f.data, Perms.File); e != nil { - Fail(e.Error()) + Fail(fmt.Sprintf("%q, path: %q", e.Error(), f.path)) } } } @@ -50,7 +49,7 @@ func setup(fS nef.UniversalFS, directoryPath string, files ...setupFile) { // having to over-write the source code. Only when the new defined generated code // is deemed to be correct, the existing code can be overridden. -var _ = XDescribe("Signature", Ordered, func() { +var _ = Describe("Signature", Ordered, func() { var ( repo, testPath, @@ -69,32 +68,30 @@ var _ = XDescribe("Signature", Ordered, func() { Context("and: Test mode", func() { Context("and: without write", func() { It("๐Ÿงช should: return hash result of newly generated content", func() { - // use mapFile - // - mfs := nef.NewUniversalABS() + fS := NewTestMemFS() templatesSubPath := "" outputPath = filepath.Join(repo, testPath) - // โ˜ข๏ธ TODO: !! what about the other files?; this is short term and will + // ๐Ÿ‘ป TODO: !! what about the other files?; this is short term and will // need to accommodate the other source files. // - path := filepath.Join(outputPath, "option-validator-auto.go") + path := filepath.Join(testPath, "option-validator-auto.go") if data, err := os.ReadFile(path); err != nil { - setup(mfs, outputPath, setupFile{ + setup(fS, testPath, setupFile{ path: path, data: data, }) } - Expect(mfs.FileExists(path)).To(BeTrue()) + Expect(fS.FileExists(path)).To(BeTrue()) - sourceCode := gola.NewSourceCodeContainer(mfs, outputPath, templatesSubPath) + sourceCode := gola.NewSourceCodeContainer(fS, testPath, templatesSubPath) result, err := sourceCode.Signature() Expect(err).Error().To(BeNil()) Expect(result.Hash).NotTo(BeEmpty()) - // โš ๏ธ Can't expect this to match yet, since the registered hash is + // ๐Ÿ‘ป Can't expect this to match yet, since the registered hash is // generated from all 3 sources, but only the generation of // option-validator-auto.go has been implemented so far // @@ -106,11 +103,11 @@ var _ = XDescribe("Signature", Ordered, func() { Context("and: Source mode", func() { Context("and: without write", func() { It("๐Ÿงช should: return hash result of src/assistant/*auto*.go", func() { - nfs := nef.NewUniversalABS() // TODO: check + fS := nef.NewUniversalABS() templatesSubPath := "" outputPath = filepath.Join(repo, sourcePath) - sourceCode := gola.NewSourceCodeContainer(nfs, outputPath, templatesSubPath) + sourceCode := gola.NewSourceCodeContainer(fS, outputPath, templatesSubPath) result, err := sourceCode.Signature() fmt.Printf("===> [๐Ÿ‘พ] REGISTERED-HASH: '%v'\n", gola.RegisteredHash) @@ -128,31 +125,37 @@ var _ = XDescribe("Signature", Ordered, func() { Context("and: Test mode", func() { Context("and: without write", func() { It("๐Ÿงช should: return hash result of parsed contents sources", func() { - nfs := nef.NewUniversalABS() + const ( + doWrite = false + ) + fS := nef.NewUniversalABS() templatesSubPath := "" outputPath = filepath.Join(repo, testPath) - sourceCode := gola.NewSourceCodeContainer(nfs, outputPath, templatesSubPath) - doWrite := false + sourceCode := gola.NewSourceCodeContainer(fS, outputPath, templatesSubPath) result, err := sourceCode.Generator(doWrite).Run() Expect(err).Error().To(BeNil()) Expect(result.Output).NotTo(BeEmpty()) - Expect(result.Hash).NotTo(MatchRegisteredHash(gola.RegisteredHash)) // โš ๏ธ + Expect(result.Hash).NotTo(MatchRegisteredHash(gola.RegisteredHash)) // ๐Ÿ‘ป }) }) Context("and: with write", func() { It("๐Ÿงช should: return hash result of generators/gola/out/assistant/*auto*.go", func() { - mfs := nef.NewUniversalABS() // use mapFS + const ( + doWrite = true + ) + + fS := NewTestMemFS() templatesSubPath := "" outputPath = filepath.Join(repo, testPath) - sourceCode := gola.NewSourceCodeContainer(mfs, outputPath, templatesSubPath) - doWrite := true + // only use testPath as this is relative and required when using mapFS + sourceCode := gola.NewSourceCodeContainer(fS, testPath, templatesSubPath) result, err := sourceCode.Generator(doWrite).Run() - path := filepath.Join(outputPath, "option-validator-auto.go") // โ˜ข๏ธ + path := filepath.Join(testPath, "option-validator-auto.go") // โ˜ข๏ธ - Expect(mfs.FileExists(path)).To(BeTrue(), + Expect(fS.FileExists(path)).To(BeTrue(), fmt.Sprintf("โ›”โ›”โ›” generated file '%v' not found\n", path), ) @@ -161,7 +164,7 @@ var _ = XDescribe("Signature", Ordered, func() { Expect(err).Error().To(BeNil()) Expect(result.Output).NotTo(BeEmpty()) - Expect(result.Hash).NotTo(MatchRegisteredHash(gola.RegisteredHash)) // โš ๏ธ + Expect(result.Hash).NotTo(MatchRegisteredHash(gola.RegisteredHash)) // ๐Ÿ‘ป }) }) }) diff --git a/generators/gola/source-code-data_test.go b/generators/gola/source-code-data_test.go index 680ad5f..c2d4b2e 100644 --- a/generators/gola/source-code-data_test.go +++ b/generators/gola/source-code-data_test.go @@ -39,7 +39,7 @@ var _ = Describe("SourceCodeData", Ordered, func() { Context("AnyMissing", func() { When("source mode", func() { - XIt("๐Ÿงช should: find all source code files are present", func() { + It("๐Ÿงช should: find all source code files are present", func() { outputPath := filepath.Join(repo, sourcePath) templatesSubPath := "" sourceContainer := gola.NewSourceCodeContainer(fS, outputPath, templatesSubPath) diff --git a/generators/gola/source-code-generator_test.go b/generators/gola/source-code-generator_test.go index 06bb59a..3c0dbc3 100644 --- a/generators/gola/source-code-generator_test.go +++ b/generators/gola/source-code-generator_test.go @@ -12,25 +12,22 @@ import ( var _ = Describe("SourceCodeGenerator", Ordered, func() { var ( - repo, testPath, sourcePath string - fs nef.UniversalFS + repo, testPath string + fS nef.UniversalFS ) BeforeAll(func() { repo = Repo("../..") testPath = filepath.Join("generators", "gola", "out", "assistant") - sourcePath = filepath.Join("src", "assistant") - fs = nef.NewUniversalABS() // use mapFS - - _ = sourcePath + fS = NewTestMemFS() }) Context("AnyMissing", func() { When("test mode", func() { - XIt("should: find all source code files are present", func() { + It("should: find all source code files are present", func() { outputPath := filepath.Join(repo, testPath) templatesSubPath := "" - codeContainer := gola.NewSourceCodeContainer(fs, outputPath, templatesSubPath) + codeContainer := gola.NewSourceCodeContainer(fS, outputPath, templatesSubPath) omitWrite := false _, err := codeContainer.Generator(omitWrite).Run()