From 9dc41571dbd4e77f2d48f4101f421ec9557c8c8a Mon Sep 17 00:00:00 2001 From: Gabe Cook Date: Sun, 10 Nov 2024 23:34:10 -0600 Subject: [PATCH] chore(cmd): Use go-utils func for versioning --- cmd/cmd.go | 4 ++-- cmd/options.go | 12 ------------ cmd/version.go | 32 -------------------------------- cmd/version_test.go | 12 ------------ go.mod | 4 ++-- go.sum | 12 ++++++------ internal/generate/docs/main.go | 3 ++- main.go | 3 ++- 8 files changed, 14 insertions(+), 68 deletions(-) delete mode 100644 cmd/options.go delete mode 100644 cmd/version.go delete mode 100644 cmd/version_test.go diff --git a/cmd/cmd.go b/cmd/cmd.go index a8033e3..480efa8 100644 --- a/cmd/cmd.go +++ b/cmd/cmd.go @@ -10,6 +10,7 @@ import ( "path/filepath" "strings" + "gabe565.com/utils/cobrax" "gabe565.com/utils/coloryaml" "github.com/clevyr/yampl/internal/config" "github.com/clevyr/yampl/internal/util" @@ -26,7 +27,7 @@ YAML data can be piped to stdin or files/dirs can be passed as arguments. Full reference at ` + termenv.Hyperlink("https://github.com/clevyr/yampl#readme", "github.com/clevyr/yampl") -func New(opts ...Option) *cobra.Command { +func New(opts ...cobrax.Option) *cobra.Command { cmd := &cobra.Command{ Use: "yampl [files | dirs] [-v key=value...]", Short: "Inline YAML templating via line-comments", @@ -44,7 +45,6 @@ func New(opts ...Option) *cobra.Command { for _, opt := range opts { opt(cmd) } - return cmd } diff --git a/cmd/options.go b/cmd/options.go deleted file mode 100644 index 9dd25b4..0000000 --- a/cmd/options.go +++ /dev/null @@ -1,12 +0,0 @@ -package cmd - -import "github.com/spf13/cobra" - -type Option func(cmd *cobra.Command) - -func WithVersion(version string) Option { - return func(cmd *cobra.Command) { - cmd.Version = buildVersion(version) - cmd.InitDefaultVersionFlag() - } -} diff --git a/cmd/version.go b/cmd/version.go deleted file mode 100644 index 8b40d7b..0000000 --- a/cmd/version.go +++ /dev/null @@ -1,32 +0,0 @@ -package cmd - -import "runtime/debug" - -func buildVersion(version string) string { - var commit string - var modified bool - if info, ok := debug.ReadBuildInfo(); ok { - for _, setting := range info.Settings { - switch setting.Key { - case "vcs.revision": - commit = setting.Value - case "vcs.modified": - if setting.Value == "true" { - modified = true - } - } - } - } - - if commit != "" { - version += " (" - if modified { - version += "*" - } - if len(commit) > 8 { - commit = commit[:8] - } - version += commit + ")" - } - return version -} diff --git a/cmd/version_test.go b/cmd/version_test.go deleted file mode 100644 index 6ce51f3..0000000 --- a/cmd/version_test.go +++ /dev/null @@ -1,12 +0,0 @@ -package cmd - -import ( - "testing" - - "github.com/stretchr/testify/assert" -) - -func Test_buildVersion(t *testing.T) { - got := buildVersion("0.0.0-next") - assert.Equal(t, "0.0.0-next", got) -} diff --git a/go.mod b/go.mod index b924b02..79b21d9 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/clevyr/yampl go 1.23.2 require ( - gabe565.com/utils v0.0.0-20241029174609-934fb3acf91e + gabe565.com/utils v0.0.0-20241111053222-0f59399cbb3c github.com/Masterminds/sprig/v3 v3.3.0 github.com/dmarkham/enumer v1.5.10 github.com/lmittmann/tint v1.0.5 @@ -23,7 +23,7 @@ require ( github.com/cpuguy83/go-md2man/v2 v2.0.4 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/fatih/color v1.18.0 // indirect - github.com/goccy/go-yaml v1.13.0 // indirect + github.com/goccy/go-yaml v1.13.7 // indirect github.com/google/uuid v1.6.0 // indirect github.com/huandu/xstrings v1.5.0 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect diff --git a/go.sum b/go.sum index 81ec444..7730b7c 100644 --- a/go.sum +++ b/go.sum @@ -1,7 +1,7 @@ dario.cat/mergo v1.0.1 h1:Ra4+bf83h2ztPIQYNP99R6m+Y7KfnARDfID+a+vLl4s= dario.cat/mergo v1.0.1/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk= -gabe565.com/utils v0.0.0-20241029174609-934fb3acf91e h1:UP9HzqvfJI8n6k2XIBe95pixGA36wFx3JiVbPa8RFJE= -gabe565.com/utils v0.0.0-20241029174609-934fb3acf91e/go.mod h1:i93PnuU9qG5dNr79l+206DXeYn+E6r7FrqNGSLhjrvw= +gabe565.com/utils v0.0.0-20241111053222-0f59399cbb3c h1:xKxZ9fGvYYihnqbyt1OE5Giz+rDQf5junHUxmvkFBfw= +gabe565.com/utils v0.0.0-20241111053222-0f59399cbb3c/go.mod h1:ekV9VNVFXI1E8niHsgfb76RQHP2oJH2zYaCw1cEWrhA= 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= @@ -12,8 +12,8 @@ github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiE github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8= github.com/cpuguy83/go-md2man/v2 v2.0.4 h1:wfIWP927BUkWJb2NmU/kNDYIBTh/ziUX91+lVfRxZq4= github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= -github.com/creack/pty v1.1.23 h1:4M6+isWdcStXEf15G/RbrMPOQj1dZ7HPZCGwE4kOeP0= -github.com/creack/pty v1.1.23/go.mod h1:08sCNb52WyoAwi2QDyzUCTgcvVFhUzewun7wtTfvcwE= +github.com/creack/pty v1.1.24 h1:bJrF4RRfyJnbTJqzRLHzcGaZK1NeM5kTC9jGgovnR1s= +github.com/creack/pty v1.1.24/go.mod h1:08sCNb52WyoAwi2QDyzUCTgcvVFhUzewun7wtTfvcwE= 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/dmarkham/enumer v1.5.10 h1:ygL0L6quiTiH1jpp68DyvsWaea6MaZLZrTTkIS++R0M= @@ -22,8 +22,8 @@ github.com/fatih/color v1.18.0 h1:S8gINlzdQ840/4pfAwic/ZE0djQEH3wM94VfqLTZcOM= github.com/fatih/color v1.18.0/go.mod h1:4FelSpRwEGDpQ12mAdzqdOukCy4u8WUtOY6lkT/6HfU= 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/goccy/go-yaml v1.13.0 h1:0Wtp0FZLd7Sm8gERmR9S6Iczzb3vItJj7NaHmFg8pTs= -github.com/goccy/go-yaml v1.13.0/go.mod h1:IjYwxUiJDoqpx2RmbdjMUceGHZwYLon3sfOGl5Hi9lc= +github.com/goccy/go-yaml v1.13.7 h1:5k2i973KptPV1mur30XMXwGepDmskip4gA2zHWzWmOY= +github.com/goccy/go-yaml v1.13.7/go.mod h1:XBurs7gK8ATbW4ZPGKgcbrY1Br56PdM69F7LkFRi1kA= 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/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= diff --git a/internal/generate/docs/main.go b/internal/generate/docs/main.go index dc82b03..2042ee8 100644 --- a/internal/generate/docs/main.go +++ b/internal/generate/docs/main.go @@ -5,6 +5,7 @@ import ( "os" "strings" + "gabe565.com/utils/cobrax" "github.com/clevyr/yampl/cmd" "github.com/spf13/cobra/doc" ) @@ -21,7 +22,7 @@ func main() { log.Fatalf("failed to mkdir: %v", err) } - rootCmd := cmd.New(cmd.WithVersion("beta")) + rootCmd := cmd.New(cobrax.WithVersion("beta")) if i := strings.Index(rootCmd.Long, "\n\nFull reference at"); i != -1 { rootCmd.Long = rootCmd.Long[:i] } diff --git a/main.go b/main.go index 0420f32..a30748c 100644 --- a/main.go +++ b/main.go @@ -4,6 +4,7 @@ import ( "log/slog" "os" + "gabe565.com/utils/cobrax" "github.com/clevyr/yampl/cmd" "github.com/clevyr/yampl/internal/config" ) @@ -12,7 +13,7 @@ var version = "beta" func main() { config.InitLog(os.Stderr, slog.LevelInfo, config.FormatAuto) - root := cmd.New(cmd.WithVersion(version)) + root := cmd.New(cobrax.WithVersion(version)) if err := root.Execute(); err != nil { os.Exit(1) }