Skip to content

Commit 4ea9b74

Browse files
committed
chore: Move version cmd option into cmdutil package
1 parent e2a3d10 commit 4ea9b74

File tree

5 files changed

+11
-16
lines changed

5 files changed

+11
-16
lines changed

cmd/cmdutil/option.go

+7
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ import "github.com/spf13/cobra"
44

55
type Option func(cmd *cobra.Command)
66

7+
func WithVersion(version string) Option {
8+
return func(cmd *cobra.Command) {
9+
cmd.Version = buildVersion(version)
10+
cmd.InitDefaultVersionFlag()
11+
}
12+
}
13+
714
const DisableTTYAnnotation = "without"
815

916
func DisableTTY() Option {

cmd/version.go renamed to cmd/cmdutil/version.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package cmd
1+
package cmdutil
22

33
import "runtime/debug"
44

cmd/options.go

-13
This file was deleted.

internal/generate/docs/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func main() {
3131
panic(err)
3232
}
3333

34-
opts := []cmdutil.Option{cmd.WithVersion("beta")}
34+
opts := []cmdutil.Option{cmdutil.WithVersion("beta")}
3535
root := cmd.New(cmd.Name, opts...)
3636
cmds := append(slices.Collect(subcommands.Without(nil, opts...)), root)
3737
for _, subCmd := range root.Commands() {

main.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@ import (
66
"os/exec"
77

88
"github.com/gabe565/moreutils/cmd"
9+
"github.com/gabe565/moreutils/cmd/cmdutil"
910
)
1011

1112
var version = "beta"
1213

1314
func main() {
14-
root := cmd.New(os.Args[0], cmd.WithVersion(version))
15+
root := cmd.New(os.Args[0], cmdutil.WithVersion(version))
1516
root.SilenceErrors = true
1617
if err := root.Execute(); err != nil {
1718
var execErr *exec.ExitError

0 commit comments

Comments
 (0)