Skip to content

Commit 10e9755

Browse files
authored
feat(cmd): Add a version cli command (#921)
Signed-off-by: Akhil Repala <[email protected]>
1 parent 09e9e31 commit 10e9755

File tree

2 files changed

+41
-8
lines changed

2 files changed

+41
-8
lines changed

cmd/dingo/main.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,12 @@ func slogPrintf(format string, v ...any) {
3737

3838
var (
3939
globalFlags = struct {
40-
version bool
41-
debug bool
40+
debug bool
4241
}{}
4342
configFile string
4443
)
4544

4645
func commonRun() *slog.Logger {
47-
if globalFlags.version {
48-
fmt.Printf("%s %s\n", programName, version.GetVersionString())
49-
os.Exit(0)
50-
}
5146
// Configure logger
5247
logLevel := slog.LevelInfo
5348
addSource := false
@@ -92,8 +87,6 @@ func main() {
9287
// Global flags
9388
rootCmd.PersistentFlags().
9489
BoolVarP(&globalFlags.debug, "debug", "D", false, "enable debug logging")
95-
rootCmd.PersistentFlags().
96-
BoolVarP(&globalFlags.version, "version", "", false, "show version and exit")
9790
rootCmd.PersistentFlags().
9891
StringVar(&configFile, "config", "", "path to config file")
9992

@@ -109,6 +102,7 @@ func main() {
109102
// Subcommands
110103
rootCmd.AddCommand(serveCommand())
111104
rootCmd.AddCommand(loadCommand())
105+
rootCmd.AddCommand(versionCommand())
112106

113107
// Execute cobra command
114108
if err := rootCmd.Execute(); err != nil {

cmd/dingo/version.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Copyright 2025 Blink Labs Software
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package main
16+
17+
import (
18+
"fmt"
19+
"os"
20+
21+
"github.com/blinklabs-io/dingo/internal/version"
22+
"github.com/spf13/cobra"
23+
)
24+
25+
func versionRun(_ *cobra.Command, _ []string) {
26+
fmt.Println(version.GetVersionString())
27+
os.Exit(0)
28+
}
29+
30+
func versionCommand() *cobra.Command {
31+
cmd := &cobra.Command{
32+
Use: "version",
33+
Short: "Print version and exit",
34+
Run: func(cmd *cobra.Command, args []string) {
35+
versionRun(cmd, args)
36+
},
37+
}
38+
return cmd
39+
}

0 commit comments

Comments
 (0)