Skip to content

Commit 42d97f8

Browse files
committed
bt: add version information
1 parent b9a89f3 commit 42d97f8

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

bt/main.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ func program(args []string) int {
5959
opt.String("color", "auto", opt.Description("show colored output"), opt.ValidValues("always", "auto", "never"))
6060
opt.SetUnknownMode(getoptions.Pass)
6161

62+
opt.NewCommand("version", "Show version").SetCommandFn(printVersion())
63+
6264
configCMD(ctx, opt)
6365
terraform.NewCommand(ctx, opt)
6466
stack.NewCommand(ctx, opt)

bt/version.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package main
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"runtime"
7+
"runtime/debug"
8+
9+
"github.com/DavidGamba/go-getoptions"
10+
)
11+
12+
func printVersion() getoptions.CommandFn {
13+
return func(context.Context, *getoptions.GetOpt, []string) error {
14+
fmt.Printf("%15s %s\n", "go.version", runtime.Version())
15+
info, ok := debug.ReadBuildInfo()
16+
if !ok {
17+
return fmt.Errorf("failed to read build info")
18+
}
19+
fmt.Printf("%15s %s\n", "module.path", info.Main.Path)
20+
fmt.Printf("%15s %s\n", "module.version", info.Main.Version)
21+
for _, s := range info.Settings {
22+
if s.Value != "" {
23+
fmt.Printf("%15s %s\n", s.Key, s.Value)
24+
}
25+
}
26+
return nil
27+
}
28+
}

0 commit comments

Comments
 (0)