Skip to content

Commit

Permalink
chore(deps): upgrade various dependencies
Browse files Browse the repository at this point in the history
Signed-off-by: kilianpaquier <[email protected]>
  • Loading branch information
kilianpaquier committed Dec 11, 2024
1 parent 76a1e3d commit 268753b
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 35 deletions.
12 changes: 6 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
github.com/go-playground/validator/v10 v10.23.0
github.com/hashicorp/go-cleanhttp v0.5.2
github.com/huandu/xstrings v1.5.0
github.com/kilianpaquier/cli-sdk v0.0.0-20240817193626-4b2ded52f151
github.com/kilianpaquier/cli-sdk v0.0.0-20241210203855-073205e87ddb
github.com/samber/lo v1.47.0
github.com/sirupsen/logrus v1.9.3
github.com/spf13/cobra v1.8.1
Expand All @@ -23,22 +23,22 @@ require (
require (
dario.cat/mergo v1.0.1 // indirect
github.com/Masterminds/goutils v1.1.1 // indirect
github.com/Masterminds/semver/v3 v3.3.0 // indirect
github.com/Masterminds/semver/v3 v3.3.1 // indirect
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/gabriel-vasile/mimetype v1.4.5 // indirect
github.com/gabriel-vasile/mimetype v1.4.7 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/google/go-github/v63 v63.0.0 // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/hashicorp/errwrap v1.0.0 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-getter/v2 v2.2.3 // indirect
github.com/hashicorp/go-multierror v1.1.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/go-safetemp v1.0.0 // indirect
github.com/hashicorp/go-version v1.7.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/klauspost/compress v1.17.9 // indirect
github.com/klauspost/compress v1.17.11 // indirect
github.com/leodido/go-urn v1.4.0 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
Expand Down
23 changes: 12 additions & 11 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ dario.cat/mergo v1.0.1 h1:Ra4+bf83h2ztPIQYNP99R6m+Y7KfnARDfID+a+vLl4s=
dario.cat/mergo v1.0.1/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk=
github.com/Masterminds/goutils v1.1.1 h1:5nUrii3FMTL5diU80unEVvNevw1nH4+ZV4DSLVJLSYI=
github.com/Masterminds/goutils v1.1.1/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU=
github.com/Masterminds/semver/v3 v3.3.0 h1:B8LGeaivUe71a5qox1ICM/JLl0NqZSW5CHyL+hmvYS0=
github.com/Masterminds/semver/v3 v3.3.0/go.mod h1:4V+yj/TJE1HU9XfppCwVMZq3I84lprf4nC11bSS5beM=
github.com/Masterminds/semver/v3 v3.3.1 h1:QtNSWtVZ3nBfk8mAOu/B6v7FMJ+NHTIgUPi7rj+4nv4=
github.com/Masterminds/semver/v3 v3.3.1/go.mod h1:4V+yj/TJE1HU9XfppCwVMZq3I84lprf4nC11bSS5beM=
github.com/Masterminds/sprig/v3 v3.3.0 h1:mQh0Yrg1XPo6vjYXgtf5OtijNAKJRNcTdOOGZe3tPhs=
github.com/Masterminds/sprig/v3 v3.3.0/go.mod h1:Zy1iXRYNqNLUolqCpL4uhk6SHUMAOSCzdgBfDb35Lz0=
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d h1:xDfNPAt8lFiC1UJrqV3uuy861HCTo708pDMbjHHdCas=
Expand All @@ -16,8 +16,8 @@ github.com/fatih/structtag v1.2.0 h1:/OdNE99OxoI/PqaW/SuSK9uxxT3f/tcSZgon/ssNSx4
github.com/fatih/structtag v1.2.0/go.mod h1:mBJUNpUnHmRKrKlQQlmCrh5PuhftFbNv8Ys4/aAZl94=
github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
github.com/gabriel-vasile/mimetype v1.4.5 h1:J7wGKdGu33ocBOhGy0z653k/lFKLFDPJMG8Gql0kxn4=
github.com/gabriel-vasile/mimetype v1.4.5/go.mod h1:ibHel+/kbxn9x2407k1izTA1S81ku1z/DlgOW2QE0M4=
github.com/gabriel-vasile/mimetype v1.4.7 h1:SKFKl7kD0RiPdbht0s7hFtjl489WcQ1VyPW8ZzUMYCA=
github.com/gabriel-vasile/mimetype v1.4.7/go.mod h1:GDlAgAyIRT27BhFl53XNAFtfjzOkLaF35JdEG0P7LtU=
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
Expand All @@ -35,14 +35,15 @@ github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
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/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/UYA=
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I=
github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
github.com/hashicorp/go-cleanhttp v0.5.2 h1:035FKYIWjmULyFRBKPs8TBQoi0x6d9G4xc9neXJWAZQ=
github.com/hashicorp/go-cleanhttp v0.5.2/go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/SoxCXGY6BqNFT48=
github.com/hashicorp/go-getter/v2 v2.2.3 h1:6CVzhT0KJQHqd9b0pK3xSP0CM/Cv+bVhk+jcaRJ2pGk=
github.com/hashicorp/go-getter/v2 v2.2.3/go.mod h1:hp5Yy0GMQvwWVUmwLs3ygivz1JSLI323hdIE9J9m7TY=
github.com/hashicorp/go-multierror v1.1.0 h1:B9UzwGQJehnUY1yNrnwREHc3fGbC2xefo8g4TbElacI=
github.com/hashicorp/go-multierror v1.1.0/go.mod h1:spPvp8C1qA32ftKqdAHm4hHTbPw+vmowP0z+KUhOZdA=
github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo=
github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM=
github.com/hashicorp/go-safetemp v1.0.0 h1:2HR189eFNrjHQyENnQMMpCiBAsRxzbTMIgBhEyExpmo=
github.com/hashicorp/go-safetemp v1.0.0/go.mod h1:oaerMy3BhqiTbVye6QuFhFtIceqFoDHxNAB65b+Rj1I=
github.com/hashicorp/go-version v1.7.0 h1:5tqGy27NaOTB8yJKUZELlFAS/LTKJkrmONwQKeRZfjY=
Expand All @@ -53,10 +54,10 @@ github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/jarcoal/httpmock v1.3.1 h1:iUx3whfZWVf3jT01hQTO/Eo5sAYtB2/rqaUuOtpInww=
github.com/jarcoal/httpmock v1.3.1/go.mod h1:3yb8rc4BI7TCBhFY8ng0gjuLKJNquuDNiPaZjnENuYg=
github.com/kilianpaquier/cli-sdk v0.0.0-20240817193626-4b2ded52f151 h1:rZc1iavSUGfF/mZePPtGlQVCQh3f++qLCLuH+W8NIm8=
github.com/kilianpaquier/cli-sdk v0.0.0-20240817193626-4b2ded52f151/go.mod h1:CEfDZgCNy6GGYgA4nLVK/ZYln0vC5e22ciN25Ap8m20=
github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2qeMA=
github.com/klauspost/compress v1.17.9/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw=
github.com/kilianpaquier/cli-sdk v0.0.0-20241210203855-073205e87ddb h1:ZHl4Q/2Fd3Gtcuv7yG1drqN9GQmTfK4WgX+iDUnB8I4=
github.com/kilianpaquier/cli-sdk v0.0.0-20241210203855-073205e87ddb/go.mod h1:Z36mTmBD68x1sc7JBZeIVEknXmvWN8Cwe8Y1PsrUeJQ=
github.com/klauspost/compress v1.17.11 h1:In6xLpyWOi1+C7tXUUWv2ot1QvBjxevKAaI6IXrJmUc=
github.com/klauspost/compress v1.17.11/go.mod h1:pMDklpSncoRMuLFrf1W9Ss9KT+0rH90U12bZKk7uwG0=
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=
Expand Down
18 changes: 8 additions & 10 deletions internal/generate/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"go/ast"
"io/fs"
"os"
"path"
"path/filepath"
Expand Down Expand Up @@ -55,7 +56,7 @@ func generateBuilders(file *ast.File, pkg packagesData, opts CLIOptions) ([]genD

// create destination directory
// only now because we don't want to create the directory unless at least one builder was successfully computed and ready for generation
if err := os.MkdirAll(builder.Opts.Destdir, cfs.RwxRxRxRx); err != nil && !os.IsExist(err) {
if err := os.MkdirAll(builder.Opts.Destdir, cfs.RwxRxRxRx); err != nil && errors.Is(err, fs.ErrExist) {
errs = append(errs, fmt.Errorf("mkdir %s: %w", builder.Opts.Destdir, err))
return false // since the destination directory couldn't be created, stop all
}
Expand Down Expand Up @@ -94,23 +95,20 @@ func generateAny(filename string, dest string, data any) error {
return fmt.Errorf("execute template %s: %w", filename, err)
}

writeFile := func(bytes []byte) error {
if err := os.WriteFile(dest, bytes, cfs.RwRR); err != nil {
return fmt.Errorf("write file %s: %w", dest, err)
}
return nil
}

// optimize file imports
bytes := []byte(content.String())
formatted, err := imports.Process(dest, bytes, nil)
if err != nil {
// also write file when imports optimization failed
// better for debugging
_ = writeFile(bytes)
_ = os.WriteFile(dest, bytes, cfs.RwRR)

Check warning on line 104 in internal/generate/generate.go

View check run for this annotation

Codecov / codecov/patch

internal/generate/generate.go#L104

Added line #L104 was not covered by tests
return fmt.Errorf("generated builder '%s' is incorrect: %w", dest, err)
}
return writeFile(formatted)

if err := os.WriteFile(dest, formatted, cfs.RwRR); err != nil {
return fmt.Errorf("write file %s: %w", dest, err)
}

Check warning on line 110 in internal/generate/generate.go

View check run for this annotation

Codecov / codecov/patch

internal/generate/generate.go#L109-L110

Added lines #L109 - L110 were not covered by tests
return nil
}

// funcMap returns the functions to be used in go template generation to make it easier.
Expand Down
19 changes: 11 additions & 8 deletions internal/generate/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,11 @@ func TestRun_DifferentPackage(t *testing.T) {
} {
t.Run(tc.DirName, func(t *testing.T) {
// Arrange
tc.CLIOptions.File = filepath.Join(testdata, tc.DirName, "types.go")
assertdir := filepath.Join(testdata, tc.DirName, "builders")
tc.CLIOptions.Destdir = filepath.Join(testdata, tc.DirName, "result")

tc.CLIOptions.PackageName = "builders"
tc.CLIOptions.File = filepath.Join(testdata, tc.DirName, "types.go")
tc.CLIOptions.Destdir = filepath.Join(testdata, tc.DirName, "result")
t.Cleanup(func() { require.NoError(t, os.RemoveAll(tc.CLIOptions.Destdir)) })

// Act
Expand Down Expand Up @@ -277,8 +278,9 @@ func TestRun_ExternalModule(t *testing.T) {
t.Run(tc.DirName, func(t *testing.T) {
// Arrange
assertdir := filepath.Join(testdata, tc.DirName, "builders")
tc.CLIOptions.Destdir = filepath.Join(testdata, tc.DirName, "result")

tc.CLIOptions.PackageName = "builders"
tc.CLIOptions.Destdir = filepath.Join(testdata, tc.DirName, "result")
t.Cleanup(func() { require.NoError(t, os.RemoveAll(tc.CLIOptions.Destdir)) })

// Act
Expand Down Expand Up @@ -319,15 +321,16 @@ func TestRun_SamePackage(t *testing.T) {
} {
t.Run(tc.DirName, func(t *testing.T) {
// Arrange
assertdir := filepath.Join(testdata, tc.DirName)
assertdir := t.TempDir()
require.NoError(t, os.CopyFS(assertdir, os.DirFS(filepath.Join(testdata, tc.DirName))))

src := filepath.Join(testdata, tc.DirName, "types.go")
tc.CLIOptions.Destdir = filepath.Join(testdata, tc.DirName, "result")
tc.CLIOptions.File = filepath.Join(tc.CLIOptions.Destdir, "types.go")
require.NoError(t, os.MkdirAll(tc.CLIOptions.Destdir, cfs.RwxRxRxRx))
require.NoError(t, cfs.CopyFile(src, tc.CLIOptions.File))
require.NoError(t, os.MkdirAll(tc.CLIOptions.Destdir, cfs.RwxRxRxRx)) // the only reason we need to create the directory is because types.go is copied before generation
t.Cleanup(func() { require.NoError(t, os.RemoveAll(tc.CLIOptions.Destdir)) })

tc.CLIOptions.File = filepath.Join(tc.CLIOptions.Destdir, "types.go")
require.NoError(t, cfs.CopyFile(filepath.Join(testdata, tc.DirName, "types.go"), tc.CLIOptions.File))

// Act
err := generate.Run(tc.CLIOptions, strings.Split(tc.Args, " "))

Expand Down

0 comments on commit 268753b

Please sign in to comment.