Skip to content

Commit 0c36211

Browse files
committed
Add version command to the CLI
1 parent 0ab9139 commit 0c36211

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

cmd/hs/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ func main() {
2424
commandAdmin(),
2525
commandServe(),
2626
commandServeWeb(),
27+
commandVersion(),
2728
)
2829

2930
err := app.Run(os.Args)

cmd/hs/version.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"runtime/debug"
6+
7+
"github.com/urfave/cli/v2"
8+
)
9+
10+
func commandVersion() *cli.Command {
11+
return &cli.Command{
12+
Name: "version",
13+
Usage: "HashUp version",
14+
Flags: []cli.Flag{},
15+
Action: func(c *cli.Context) error {
16+
if bi, ok := debug.ReadBuildInfo(); ok {
17+
fmt.Println(bi.Main.Version)
18+
}
19+
return nil
20+
},
21+
}
22+
}

main.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"embed"
55
"fmt"
66
"os"
7+
"runtime/debug"
78

89
"github.com/urfave/cli/v2"
910
)
@@ -168,6 +169,17 @@ func main() {
168169
return setupConfig(c.Bool("force"))
169170
},
170171
},
172+
{
173+
Name: "version",
174+
Usage: "HashUp version",
175+
Flags: []cli.Flag{},
176+
Action: func(c *cli.Context) error {
177+
if bi, ok := debug.ReadBuildInfo(); ok {
178+
fmt.Println(bi.Main.Version)
179+
}
180+
return nil
181+
},
182+
},
171183
},
172184
}
173185

0 commit comments

Comments
 (0)