Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add extenio functionality (#3) #6

Merged
merged 1 commit into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
"--fast"
],
"cSpell.words": [
"astrolib",
"avfs",
"beezledub",
"bodyclose",
"cmds",
"coverpkg",
"cobrass",
"coverprofile",
"cubiest",
"deadcode",
Expand All @@ -18,7 +19,9 @@
"errcheck",
"exportloopref",
"extendio",
"faydeaudeau",
"fieldalignment",
"GOARCH",
"goconst",
"gocritic",
"gocyclo",
Expand All @@ -37,27 +40,40 @@
"jibberjabber",
"linters",
"mattn",
"memfs",
"nakedret",
"newname",
"newpath",
"nicksnyder",
"nolint",
"nolintlint",
"nosec",
"oldname",
"oldpath",
"onsi",
"outdir",
"pixa",
"prealloc",
"rabbitweed",
"repotoken",
"samber",
"shogo",
"sidewalk",
"snivilised",
"staticcheck",
"struct",
"structcheck",
"stylecheck",
"Taskfile",
"thelper",
"toplevel",
"tparallel",
"typecheck",
"unconvert",
"unparam",
"varcheck",
"watchv",
"watchvc",
"watchvi"
"Wrapf",
"xpander",
"zeroable"
]
}
12 changes: 6 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,25 @@ module github.com/snivilised/li18ngo
go 1.22.0

require (
github.com/avfs/avfs v0.33.0
github.com/nicksnyder/go-i18n/v2 v2.4.0
github.com/onsi/ginkgo/v2 v2.20.0
github.com/onsi/gomega v1.34.1
github.com/snivilised/extendio v0.7.0
github.com/pkg/errors v0.9.1
golang.org/x/text v0.17.0
)

require (
github.com/avfs/avfs v0.33.0 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-task/slim-sprig/v3 v3.0.0 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/pprof v0.0.0-20240727154555-813a5fbdbec8 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/nicksnyder/go-i18n/v2 v2.4.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/samber/lo v1.39.0 // indirect
github.com/rogpeppe/go-internal v1.11.0 // indirect
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 // indirect
golang.org/x/net v0.28.0 // indirect
golang.org/x/sys v0.23.0 // indirect
golang.org/x/text v0.17.0 // indirect
golang.org/x/tools v0.24.0 // indirect
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
16 changes: 0 additions & 16 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,10 @@ 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-20240727154555-813a5fbdbec8 h1:FKHo8hFI3A+7w0aUQuYXQ+6EN5stWmeY/AZqtM8xk9k=
github.com/google/pprof v0.0.0-20240727154555-813a5fbdbec8/go.mod h1:K1liHPHnj73Fdn/EKuT8nrFqBihUSKXoLYU0BuatOYo=
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/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
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.0 h1:3IcvPOAvnCKwNm0TB0dLDTuawWEj+ax/RERNC+diLMM=
github.com/nicksnyder/go-i18n/v2 v2.4.0/go.mod h1:nxYSZE9M0bf3Y70gPQjN9ha7XNHX7gMc814+6wVyEI4=
github.com/onsi/ginkgo/v2 v2.20.0 h1:PE84V2mHqoT1sglvHc8ZdQtPcwmvvt29WLEEO3xmdZw=
Expand All @@ -35,20 +31,8 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M=
github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA=
github.com/samber/lo v1.39.0 h1:4gTz1wUhNYLhFSKl6O+8peW0v2F4BCY034GRpU9WnuA=
github.com/samber/lo v1.39.0/go.mod h1:+m/ZKRl6ClXCE2Lgf3MsQlWfh4bn1bz6CXEOxnEXnEA=
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/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
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=
Expand Down
13 changes: 0 additions & 13 deletions i18n/i18n_suite_test.go

This file was deleted.

19 changes: 13 additions & 6 deletions internal/helpers/test-utilities.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
package helpers

import (
"errors"
"fmt"
"os"
"os/exec"
"path/filepath"
"runtime"
"strings"
)

// Path; the relative path always uses /
func Path(parent, relative string) string {
segments := strings.Split(relative, "/")
return filepath.Join(append([]string{parent}, segments...)...)
}

// Normalise; the relative path always uses /
func Normalise(p string) string {
return strings.ReplaceAll(p, "/", string(filepath.Separator))
}
Expand Down Expand Up @@ -42,19 +45,23 @@ func Root() string {
panic("could not get root path")
}

// Repo; the relative path always uses /
func Repo(relative string) string {
_, filename, _, _ := runtime.Caller(0) //nolint:dogsled // ignore
return Path(filepath.Dir(filename), relative)
cmd := exec.Command("git", "rev-parse", "--show-toplevel")
output, _ := cmd.Output()
repo := strings.TrimSpace(string(output))

return Path(repo, relative)
}

func Log() string {
func Log() (string, error) {
if current, err := os.Getwd(); err == nil {
parent, _ := filepath.Split(current)
grand := filepath.Dir(parent)
great := filepath.Dir(grand)

return filepath.Join(great, "Test", "test.log")
return filepath.Join(great, "Test", "test.log"), nil
}

panic("could not get root path")
return "", errors.New("could not get path")
}
21 changes: 21 additions & 0 deletions internal/lo/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2022 Samuel Berthe

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
150 changes: 150 additions & 0 deletions internal/lo/condition.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
package lo

// Ternary is a 1 line if/else statement.
// Play: https://go.dev/play/p/t-D7WBL44h2
func Ternary[T any](condition bool, ifOutput, elseOutput T) T {
if condition {
return ifOutput
}

return elseOutput
}

// TernaryF is a 1 line if/else statement whose options are functions
// Play: https://go.dev/play/p/AO4VW20JoqM
func TernaryF[T any](condition bool, ifFunc, elseFunc func() T) T {
if condition {
return ifFunc()
}

return elseFunc()
}

// type IfElse[T any] struct {
// result T
// done bool
// }

// If
// Play: https://go.dev/play/p/WSw3ApMxhyW
// func If[T any](condition bool, result T) *IfElse[T] {
// if condition {
// return &IfElse[T]{result, true}
// }

// var t T
// return &IfElse[T]{t, false}
// }

// IfF
// Play: https://go.dev/play/p/WSw3ApMxhyW
// func IfF[T any](condition bool, resultF func() T) *IfElse[T] {
// if condition {
// return &IfElse[T]{resultF(), true}
// }

// var t T
// return &IfElse[T]{t, false}
// }

// ElseIf
// Play: https://go.dev/play/p/WSw3ApMxhyW
// func (i *IfElse[T]) ElseIf(condition bool, result T) *IfElse[T] {
// if !i.done && condition {
// i.result = result
// i.done = true
// }

// return i
// }

// ElseIfF
// Play: https://go.dev/play/p/WSw3ApMxhyW
// func (i *IfElse[T]) ElseIfF(condition bool, resultF func() T) *IfElse[T] {
// if !i.done && condition {
// i.result = resultF()
// i.done = true
// }

// return i
// }

// Else
// Play: https://go.dev/play/p/WSw3ApMxhyW
// func (i *IfElse[T]) Else(result T) T {
// if i.done {
// return i.result
// }

// return result
// }

// ElseF
// Play: https://go.dev/play/p/WSw3ApMxhyW
// func (i *IfElse[T]) ElseF(resultF func() T) T {
// if i.done {
// return i.result
// }

// return resultF()
// }

// type SwitchCase[T comparable, R any] struct {
// predicate T
// result R
// done bool
// }

// Switch is a pure functional switch/case/default statement.
// Play: https://go.dev/play/p/TGbKUMAeRUd
// func Switch[T comparable, R any](predicate T) *SwitchCase[T, R] {
// var result R

// return &SwitchCase[T, R]{
// predicate,
// result,
// false,
// }
// }

// Case
// Play: https://go.dev/play/p/TGbKUMAeRUd
// func (s *SwitchCase[T, R]) Case(val T, result R) *SwitchCase[T, R] {
// if !s.done && s.predicate == val {
// s.result = result
// s.done = true
// }

// return s
// }

// CaseF
// Play: https://go.dev/play/p/TGbKUMAeRUd
// func (s *SwitchCase[T, R]) CaseF(val T, cb func() R) *SwitchCase[T, R] {
// if !s.done && s.predicate == val {
// s.result = cb()
// s.done = true
// }

// return s
// }

// Default
// Play: https://go.dev/play/p/TGbKUMAeRUd
// func (s *SwitchCase[T, R]) Default(result R) R {
// if !s.done {
// s.result = result
// }

// return s.result
// }

// DefaultF
// Play: https://go.dev/play/p/TGbKUMAeRUd
// func (s *SwitchCase[T, R]) DefaultF(cb func() R) R {
// if !s.done {
// s.result = cb()
// }

// return s.result
// }
Loading
Loading