template / commit
lint fixes and upgrades to latest linter and releaser, and all packages, and go itself
Makefile | 4 ++-- config.go | 4 ++-- config_test.go | 10 +++++---- extras_test.go | 2 +- file.go | 7 +++++-- go.mod | 30 +++++++++++++------------- go.sum | 66 +++++++++++++++++++++++----------------------------------- main.go | 7 ++++--- postscript.go | 2 +- profile.go | 13 ++++++------ 10 files changed, 70 insertions(+), 75 deletions(-) diff --git a/Makefile b/Makefile index 37bc82d..fb95975 100644 --- a/Makefile +++ b/Makefile @@ -8,9 +8,9 @@ all: build test lint all-clean: clean all dev-setup: - go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest + go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.8.0 golangci-lint --version - go install github.com/goreleaser/goreleaser@latest + go install github.com/goreleaser/goreleaser/v2@latest goreleaser --version echo "${VERSION}" > dev-setup diff --git a/config.go b/config.go index 7d6fd30..2e12711 100644 --- a/config.go +++ b/config.go @@ -13,7 +13,7 @@ type Config struct { } func validateConfig(config *Config) error { - if config.Profiles == nil || len(config.Profiles) == 0 { + if len(config.Profiles) == 0 { return fmt.Errorf("no profiles found") } @@ -75,7 +75,7 @@ func saveConfig(path string, config Config) error { if err != nil { return err } - defer file.Close() + defer func() { _ = file.Close() }() encoder := yaml.NewEncoder(file) err = encoder.Encode(config) if err != nil { diff --git a/config_test.go b/config_test.go index c934bca..3e1a45a 100644 --- a/config_test.go +++ b/config_test.go @@ -26,7 +26,7 @@ func TestSaveLoadConfig(t *testing.T) { if err != nil && !errors.Is(err, os.ErrExist) { assert.Nil(t, err, "Error creating config directory") } - defer os.Remove(configDir) + defer func() { _ = os.Remove(configDir) }() config := defaultConfig() @@ -50,14 +50,16 @@ func TestSaveLoadConfig(t *testing.T) { assert.Nil(t, err, "Error writing invalid yaml file") _, err = loadConfig("./invalid-yaml.yaml") assert.NotNil(t, err, "Expected to fail to parse config, but succeeded") - os.Remove("./invalid-yaml.yaml") + err = os.Remove("./invalid-yaml.yaml") + assert.Nil(t, err, "Error removing invalid yaml file") // test saving config to invalid path err = saveConfig("invalid/path/invalid-config.yaml", config) assert.NotNil(t, err, "Expected to fail to save config, but succeeded") // remove config - os.Remove(configPath) + err = os.Remove(configPath) + assert.Nil(t, err, "Error removing config file") // test default config creation _, err = os.Stat(configPath) @@ -163,7 +165,7 @@ profiles: `) err := os.WriteFile("./invalid-config.yaml", bytes, 0644) assert.Nil(t, err, "Error writing invalid config file") - defer os.Remove("./invalid-config.yaml") + defer func() { _ = os.Remove("./invalid-config.yaml") }() // load config _, err = loadConfig("./invalid-config.yaml") diff --git a/extras_test.go b/extras_test.go index 92e1a8f..96a72e5 100644 --- a/extras_test.go +++ b/extras_test.go @@ -23,7 +23,7 @@ func TestExtras(t *testing.T) { // cleanup code deleteFile := func() { - os.Remove(file.Name()) + _ = os.Remove(file.Name()) } defer deleteFile() diff --git a/file.go b/file.go index 3189f17..54c2071 100644 --- a/file.go +++ b/file.go @@ -24,7 +24,7 @@ func createFile( if err != nil { return fmt.Errorf("error creating file: %v", err) } - defer file.Close() + defer func() { _ = file.Close() }() writer := bufio.NewWriter(file) for pipeInputScanner.Scan() { @@ -34,7 +34,10 @@ func createFile( return fmt.Errorf("error writing file: %v", err) } } - writer.Flush() + err = writer.Flush() + if err != nil { + return fmt.Errorf("error flushing file: %v", err) + } } else if useTemplate { postPatternData := createPostPatternData(fullPath, prePatternData) log.WithFields(log.Fields{"fullPath": fullPath}).Debug("Creating file from template string\n", fullPath) diff --git a/go.mod b/go.mod index 6cc1a02..ba98bb4 100644 --- a/go.mod +++ b/go.mod @@ -1,12 +1,14 @@ module gitlab.com/PavelSafronov/template -go 1.19 +go 1.24.0 + +toolchain go1.24.4 require ( - github.com/sirupsen/logrus v1.9.0 - github.com/stretchr/testify v1.8.0 - github.com/urfave/cli/v2 v2.16.3 - golang.org/x/exp v0.0.0-20220921164117-439092de6870 + github.com/sirupsen/logrus v1.9.4 + github.com/stretchr/testify v1.11.1 + github.com/urfave/cli/v2 v2.27.7 + golang.org/x/exp v0.0.0-20260112195511-716be5621a96 gopkg.in/yaml.v3 v3.0.1 ) @@ -15,16 +17,16 @@ require github.com/Masterminds/semver v1.5.0 // indirect require ( github.com/Masterminds/goutils v1.1.1 // indirect github.com/Masterminds/sprig v2.22.0+incompatible - github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect + github.com/cpuguy83/go-md2man/v2 v2.0.7 // indirect github.com/davecgh/go-spew v1.1.1 // indirect - github.com/google/uuid v1.1.1 // indirect - github.com/huandu/xstrings v1.3.1 // indirect - github.com/imdario/mergo v0.3.11 // indirect - github.com/mitchellh/copystructure v1.0.0 // indirect - github.com/mitchellh/reflectwalk v1.0.0 // indirect + github.com/google/uuid v1.6.0 // indirect + github.com/huandu/xstrings v1.5.0 // indirect + github.com/imdario/mergo v0.3.16 // indirect + github.com/mitchellh/copystructure v1.2.0 // indirect + github.com/mitchellh/reflectwalk v1.0.2 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/russross/blackfriday/v2 v2.1.0 // indirect - github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect - golang.org/x/crypto v0.0.0-20200414173820-0848c9571904 // indirect - golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10 // indirect + github.com/xrash/smetrics v0.0.0-20250705151800-55b8f293f342 // indirect + golang.org/x/crypto v0.47.0 // indirect + golang.org/x/sys v0.40.0 // indirect ) diff --git a/go.sum b/go.sum index bb4b6d8..d82edc4 100644 --- a/go.sum +++ b/go.sum @@ -4,53 +4,39 @@ github.com/Masterminds/semver v1.5.0 h1:H65muMkzWKEuNDnfl9d70GUjFniHKHRbFPGBuZ3Q github.com/Masterminds/semver v1.5.0/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF078ddwwvV3Y= github.com/Masterminds/sprig v2.22.0+incompatible h1:z4yfnGrZ7netVz+0EDJ0Wi+5VZCSYp4Z0m2dk6cEM60= github.com/Masterminds/sprig v2.22.0+incompatible/go.mod h1:y6hNFY5UBTIWBxnzTeuNhlNS5hqE0NB0E6fgfo2Br3o= -github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w= -github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/cpuguy83/go-md2man/v2 v2.0.7 h1:zbFlGlXEAKlwXpmvle3d8Oe3YnkKIK4xSRTd3sHPnBo= +github.com/cpuguy83/go-md2man/v2 v2.0.7/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY= -github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/huandu/xstrings v1.3.1 h1:4jgBlKK6tLKFvO8u5pmYjG91cqytmDCDvGh7ECVFfFs= -github.com/huandu/xstrings v1.3.1/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE= -github.com/imdario/mergo v0.3.11 h1:3tnifQM4i+fbajXKBHXWEH+KvNHqojZ778UH75j3bGA= -github.com/imdario/mergo v0.3.11/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA= -github.com/mitchellh/copystructure v1.0.0 h1:Laisrj+bAB6b/yJwB5Bt3ITZhGJdqmxquMKeZ+mmkFQ= -github.com/mitchellh/copystructure v1.0.0/go.mod h1:SNtv71yrdKgLRyLFxmLdkAbkKEFWgYaq1OVrnRcwhnw= -github.com/mitchellh/reflectwalk v1.0.0 h1:9D+8oIskB4VJBN5SFlmc27fSlIBZaov1Wpk/IfikLNY= -github.com/mitchellh/reflectwalk v1.0.0/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw= +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/huandu/xstrings v1.5.0 h1:2ag3IFq9ZDANvthTwTiqSSZLjDc+BedvHPAp5tJy2TI= +github.com/huandu/xstrings v1.5.0/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE= +github.com/imdario/mergo v0.3.16 h1:wwQJbIsHYGMUyLSPrEq1CT16AhnhNJQ51+4fdHUnCl4= +github.com/imdario/mergo v0.3.16/go.mod h1:WBLT9ZmE3lPoWsEzCh9LPo3TiwVN+ZKEjmz+hD27ysY= +github.com/mitchellh/copystructure v1.2.0 h1:vpKXTN4ewci03Vljg/q9QvCGUDttBOGBIa15WveJJGw= +github.com/mitchellh/copystructure v1.2.0/go.mod h1:qLl+cE2AmVv+CoeAwDPye/v+N2HKCj9FbZEVFJRxO9s= +github.com/mitchellh/reflectwalk v1.0.2 h1:G2LzWKi524PWgd3mLHV8Y5k7s6XUvT0Gef6zxSIeXaQ= +github.com/mitchellh/reflectwalk v1.0.2/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= -github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0= -github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= -github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk= -github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= -github.com/urfave/cli/v2 v2.16.3 h1:gHoFIwpPjoyIMbJp/VFd+/vuD0dAgFK4B6DpEMFJfQk= -github.com/urfave/cli/v2 v2.16.3/go.mod h1:1CNUng3PtjQMtRzJO4FMXBQvkGtuYRxxiR9xMa7jMwI= -github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU= -github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8= -golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20200414173820-0848c9571904 h1:bXoxMPcSLOq08zI3/c5dEBT6lE4eh+jOh886GHrn6V8= -golang.org/x/crypto v0.0.0-20200414173820-0848c9571904/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/exp v0.0.0-20220921164117-439092de6870 h1:j8b6j9gzSigH28O5SjSpQSSh9lFd6f5D/q0aHjNTulc= -golang.org/x/exp v0.0.0-20220921164117-439092de6870/go.mod h1:cyybsKvd6eL0RnXn6p/Grxp8F5bW7iYuBgsNCOHpMYE= -golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10 h1:WIoqL4EROvwiPdUtaip4VcDdpZ4kha7wBWZrbVKCIZg= -golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +github.com/sirupsen/logrus v1.9.4 h1:TsZE7l11zFCLZnZ+teH4Umoq5BhEIfIzfRDZ1Uzql2w= +github.com/sirupsen/logrus v1.9.4/go.mod h1:ftWc9WdOfJ0a92nsE2jF5u5ZwH8Bv2zdeOC42RjbV2g= +github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= +github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= +github.com/urfave/cli/v2 v2.27.7 h1:bH59vdhbjLv3LAvIu6gd0usJHgoTTPhCFib8qqOwXYU= +github.com/urfave/cli/v2 v2.27.7/go.mod h1:CyNAG/xg+iAOg0N4MPGZqVmv2rCoP267496AOXUZjA4= +github.com/xrash/smetrics v0.0.0-20250705151800-55b8f293f342 h1:FnBeRrxr7OU4VvAzt5X7s6266i6cSVkkFPS0TuXWbIg= +github.com/xrash/smetrics v0.0.0-20250705151800-55b8f293f342/go.mod h1:Ohn+xnUBiLI6FVj/9LpzZWtj1/D6lUovWYBkxHVV3aM= +golang.org/x/crypto v0.47.0 h1:V6e3FRj+n4dbpw86FJ8Fv7XVOql7TEwpHapKoMJ/GO8= +golang.org/x/crypto v0.47.0/go.mod h1:ff3Y9VzzKbwSSEzWqJsJVBnWmRwRSHt/6Op5n9bQc4A= +golang.org/x/exp v0.0.0-20260112195511-716be5621a96 h1:Z/6YuSHTLOHfNFdb8zVZomZr7cqNgTJvA8+Qz75D8gU= +golang.org/x/exp v0.0.0-20260112195511-716be5621a96/go.mod h1:nzimsREAkjBCIEFtHiYkrJyT+2uy9YZJB7H1k68CXZU= +golang.org/x/sys v0.40.0 h1:DBZZqJ2Rkml6QMQsZywtnjnnGvHza6BTfYFWY9kjEWQ= +golang.org/x/sys v0.40.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU= -gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/main.go b/main.go index f6c9140..2a4217a 100644 --- a/main.go +++ b/main.go @@ -138,7 +138,8 @@ func main() { // list profiles fmt.Println("Available profiles:") for _, p := range config.Profiles { - fmt.Printf(" %v: %v\n", p.Name, p.Description) + fmt.Printf(" %v: \n", p.Name) + fmt.Printf(" %v\n", p.Description) } fmt.Println() return nil @@ -425,7 +426,7 @@ func createSettings( } else { config, err := loadConfig(fullConfigPath) if err != nil { - return settings, fmt.Errorf("error loading config from %v: %w\nConsider running `template reset` to recreate the config file. Keep in mind that `reset` will remove existing config.", fullConfigPath, err) + return settings, fmt.Errorf("error loading config from %v: %w\nConsider running `template reset` to recreate the config file, but keep in mind that `reset` will remove existing config settings", fullConfigPath, err) } fmt.Printf("Loaded config from %v\n", fullConfigPath) @@ -476,7 +477,7 @@ func readEnvVars() (EnvVarValues, error) { } func findProfile(settings Settings) (Profile, error) { - var profile Profile = Profile{} + var profile = Profile{} var err error config := settings.config createTempProfile := len(settings.fileTemplate) > 0 || len(settings.dirTemplate) > 0 || len(settings.scriptTemplate) > 0 diff --git a/postscript.go b/postscript.go index a2f353f..4b072d1 100644 --- a/postscript.go +++ b/postscript.go @@ -9,7 +9,7 @@ func createPostScriptArrays( postPatternData PostPatternData) ([]string, error) { array := make([]string, 0) - if profile.PostScripts == nil || len(profile.PostScripts) == 0 { + if len(profile.PostScripts) == 0 { return nil, fmt.Errorf("no post scripts specified") } diff --git a/profile.go b/profile.go index f8d4153..01cf20a 100644 --- a/profile.go +++ b/profile.go @@ -164,7 +164,7 @@ func processProfile(profile Profile, projectName string, extras map[string]strin } // execute PostScript, if present - if profile.PostScripts != nil && len(profile.PostScripts) > 0 { + if len(profile.PostScripts) > 0 { postPatternData := createPostPatternData(fullPath, prePatternData) postScripts, err := createPostScriptArrays(profile, postPatternData) if err != nil { @@ -221,7 +221,8 @@ func createEntity( profileType := profile.Type fullPath := filepath.Join(cwd, newName) - if profileType == FolderType { + switch profileType { + case FolderType: fmt.Printf("Creating folder: %v\n", fullPath) err := monkey.OSMkdir(fullPath, os.ModePerm) if err != nil { @@ -261,13 +262,13 @@ func createEntity( } } } - } else if profileType == FileType { + case FileType: fmt.Printf("Creating file: %v\n", fullPath) err := createFile(prePatternData, profile.FileTemplate, fullPath, pipeInputScanner) if err != nil { return "", err } - } else { + default: fmt.Printf("Profile type is script, doing nothing during main phase\n") } return fullPath, nil @@ -283,7 +284,7 @@ func validateProfile(profile *Profile) error { } // check name patterns - if profile.NamePatterns == nil || len(profile.NamePatterns) == 0 { + if len(profile.NamePatterns) == 0 { return fmt.Errorf("namePatterns is required") } for index, namePattern := range profile.NamePatterns { @@ -313,7 +314,7 @@ func validateProfile(profile *Profile) error { // check ScriptType profile if profile.Type == ScriptType { - if profile.NamePatterns != nil && len(profile.NamePatterns) > 1 { + if len(profile.NamePatterns) > 1 { return fmt.Errorf("multiple name patterns are not supported for profile %s, which has Type=%s", profile.Name, profile.Type) } }