Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

Commit 907f509

Browse files
committed
Add version command
1 parent 12af9db commit 907f509

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

cmd/coder/main.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@ import (
44
"github.com/spf13/pflag"
55
"go.coder.com/cli"
66
"log"
7-
"os"
87
"net/http"
98
_ "net/http/pprof"
9+
"os"
1010
)
1111

12-
type rootCmd struct {
13-
}
12+
var (
13+
version string
14+
)
15+
16+
type rootCmd struct{}
1417

1518
func (r *rootCmd) Run(fl *pflag.FlagSet) {
1619
fl.Usage()
@@ -32,6 +35,7 @@ func (r *rootCmd) Subcommands() []cli.Command {
3235
&shellCmd{},
3336
&syncCmd{},
3437
&urlCmd{},
38+
&versionCmd{},
3539
}
3640
}
3741

cmd/coder/version.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"runtime"
6+
7+
"github.com/spf13/pflag"
8+
"go.coder.com/cli"
9+
)
10+
11+
type versionCmd struct{}
12+
13+
func (versionCmd) Spec() cli.CommandSpec {
14+
return cli.CommandSpec{
15+
Name: "version",
16+
Usage: "",
17+
Desc: "Print the currently installed CLI version",
18+
}
19+
}
20+
21+
func (versionCmd) Run(fl *pflag.FlagSet) {
22+
fmt.Println(
23+
version,
24+
runtime.Version(),
25+
runtime.GOOS+"/"+runtime.GOARCH,
26+
)
27+
}

0 commit comments

Comments
 (0)