Skip to content

Commit

Permalink
feat: Add --version info to the tool. (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffFaer authored Apr 15, 2024
1 parent 620b601 commit 2b768c4
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 3 deletions.
26 changes: 26 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"time"

"github.com/JeffFaer/tmux-vcs-sync/api/config"
"github.com/carlmjohnson/versioninfo"
"github.com/kballard/go-shellquote"
"github.com/phsym/console-slog"
"github.com/spf13/cobra"
Expand All @@ -27,6 +28,8 @@ func Execute(ctx context.Context) error {
}

var (
version = formatVersion()

verbosity int
levels = []slog.Level{
slog.LevelWarn,
Expand All @@ -48,6 +51,7 @@ var (
var rootCmd = &cobra.Command{
Use: "tmux-vcs-sync",
Short: "Synchronize VCS state with tmux state.",
Version: version,
SilenceUsage: true,
CompletionOptions: cobra.CompletionOptions{
HiddenDefaultCmd: true,
Expand Down Expand Up @@ -79,6 +83,28 @@ var rootCmd = &cobra.Command{
},
}

func formatVersion() string {
var s string
if v := versioninfo.Version; v != "" && v != "unknown" && v != "(devel)" {
s = versioninfo.Version
}
if r := versioninfo.Revision; r != "" && r != "unknown" {
s = versioninfo.Revision
if len(s) > 7 {
s = s[:7]
}
}
if s == "" {
s = "devel"
} else if versioninfo.DirtyBuild {
s += "-dev"
}
if t := versioninfo.LastCommit; !t.IsZero() {
s += fmt.Sprintf(" (%s)", t.Format(time.RFC3339))
}
return s
}

func init() {
rootCmd.PersistentFlags().CountVarP(&verbosity, "verbose", "v", "Log more verbosely.")
rootCmd.PersistentFlags().BoolVar(&doTrace, "trace", false, "Whether to record an execution trace or not.")
Expand Down
5 changes: 4 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ go 1.22.0

require (
github.com/JeffFaer/go-stdlib-ext v0.1.1
github.com/JeffFaer/tmux-vcs-sync/api v0.0.0-20240314045224-4f466c92bafd
github.com/JeffFaer/tmux-vcs-sync/api v0.0.0-20240412020100-620b6014ff99
github.com/avast/retry-go/v4 v4.5.1
github.com/carlmjohnson/versioninfo v0.22.5
github.com/creack/pty v1.1.21
github.com/google/go-cmp v0.6.0
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51
Expand All @@ -17,6 +18,8 @@ require (
)

require (
github.com/adrg/xdg v0.4.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
golang.org/x/sys v0.1.0 // indirect
)
17 changes: 15 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
github.com/JeffFaer/go-stdlib-ext v0.1.1 h1:M8JFdsiV9Uyi8CFSTZr/TCAoE8bdVYuDlGvudxVkgHw=
github.com/JeffFaer/go-stdlib-ext v0.1.1/go.mod h1:+ipHu7aPnk5LuKfU1dda8+eIEfXNF2m7bC4porFJKXs=
github.com/JeffFaer/tmux-vcs-sync/api v0.0.0-20240314045224-4f466c92bafd h1:WJgnYObOv3BnL+AV+mUCIzGthpypB5xb3bHAvJxvbCs=
github.com/JeffFaer/tmux-vcs-sync/api v0.0.0-20240314045224-4f466c92bafd/go.mod h1:3hqch0mjY8h884063yZLPulFxvxbsoB9Pir02j3ubt4=
github.com/JeffFaer/tmux-vcs-sync/api v0.0.0-20240412020100-620b6014ff99 h1:gHPhm2NxD8PeCZfXcywIr2Ox34x5oE2lF3OaTlmdcPI=
github.com/JeffFaer/tmux-vcs-sync/api v0.0.0-20240412020100-620b6014ff99/go.mod h1:JHH9vUnR+VmOCVGQmjbIMYFjmgPq2xWXCuemRFwFMrk=
github.com/adrg/xdg v0.4.0 h1:RzRqFcjH4nE5C6oTAxhBtoE2IRyjBSa62SCbyPidvls=
github.com/adrg/xdg v0.4.0/go.mod h1:N6ag73EX4wyxeaoeHctc1mas01KZgsj5tYiAIwqJE/E=
github.com/avast/retry-go/v4 v4.5.1 h1:AxIx0HGi4VZ3I02jr78j5lZ3M6x1E0Ivxa6b0pUUh7o=
github.com/avast/retry-go/v4 v4.5.1/go.mod h1:/sipNsvNB3RRuT5iNcb6h73nw3IBmXJ/H3XrCQYSOpc=
github.com/carlmjohnson/versioninfo v0.22.5 h1:O00sjOLUAFxYQjlN/bzYTuZiS0y6fWDQjMRvwtKgwwc=
github.com/carlmjohnson/versioninfo v0.22.5/go.mod h1:QT9mph3wcVfISUKd0i9sZfVrPviHuSF+cUtLjm2WSf8=
github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/creack/pty v1.1.21 h1:1/QdRyBaHHJP61QkWMXlOIBfsgdDeeKfK8SYVUWJKf0=
github.com/creack/pty v1.1.21/go.mod h1:MOBLtS5ELjhRRrroQr9kyvTxUAFNvYEK993ew/Vr4O4=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
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/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
Expand All @@ -28,10 +33,18 @@ github.com/spf13/cobra v1.8.0 h1:7aJaZx1B85qltLMc546zn58BxxfZdR/W22ej9CFoEf0=
github.com/spf13/cobra v1.8.0/go.mod h1:WXLWApfZ71AjXPya3WOlMsY9yMs7YeiHhFVlvLyhcho=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
golang.org/x/exp v0.0.0-20240314144324-c7f7c6466f7f h1:3CW0unweImhOzd5FmYuRsD4Y4oQFKZIjAnKbjV4WIrw=
golang.org/x/exp v0.0.0-20240314144324-c7f7c6466f7f/go.mod h1:CxmFvTBINI24O/j8iY7H1xHzx2i4OsyguNBmN/uPtqc=
golang.org/x/sys v0.0.0-20211025201205-69cdffdb9359/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.1.0 h1:kunALQeHf1/185U1i0GOB/fy1IPRDDpuoOOqRReG57U=
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/tools v0.18.0 h1:k8NLag8AGHnn+PHbl7g43CtqZAwG60vZkLqgyZgIHgQ=
golang.org/x/tools v0.18.0/go.mod h1:GL7B4CwcLLeo59yx/9UWWuNOW1n3VZ4f5axWfML7Lcg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
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=

0 comments on commit 2b768c4

Please sign in to comment.