From 1e82515866ffd4a422a01c7f6f018cf076be8e81 Mon Sep 17 00:00:00 2001 From: Gabe Cook Date: Sun, 10 Nov 2024 22:44:44 -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 | 2 +- go.sum | 4 ++-- internal/generate/docs/main.go | 3 ++- main.go | 3 ++- 8 files changed, 9 insertions(+), 63 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..ab59c4e 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-20241111044313-e37a4b3f7e43 github.com/Masterminds/sprig/v3 v3.3.0 github.com/dmarkham/enumer v1.5.10 github.com/lmittmann/tint v1.0.5 diff --git a/go.sum b/go.sum index 81ec444..298ec1c 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-20241111044313-e37a4b3f7e43 h1:QooVWU1P88la/9JwKM3svOayQpXDyBlP99LdCj8qafM= +gabe565.com/utils v0.0.0-20241111044313-e37a4b3f7e43/go.mod h1:tDXvyzIUBsT0+OoU3zFYHdpOdYXWAlNHwQKIA/0XOCk= 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= 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) }