Skip to content

Commit 7e1b85c

Browse files
authored
feat(cmd/version): provide detailed info (ignite#1480)
* feat(cmd/version): provide detailed info * tidy * fix * nit * Update starport/internal/version/version.go
1 parent 50c0b4e commit 7e1b85c

File tree

9 files changed

+85
-22
lines changed

9 files changed

+85
-22
lines changed

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1224,8 +1224,6 @@ github.com/tendermint/btcd v0.1.1 h1:0VcxPfflS2zZ3RiOAHkBiFUcPvbtRj5O7zHmcJWHV7s
12241224
github.com/tendermint/btcd v0.1.1/go.mod h1:DC6/m53jtQzr/NFmMNEu0rxf18/ktVoVtMrnDD5pN+U=
12251225
github.com/tendermint/crypto v0.0.0-20191022145703-50d29ede1e15 h1:hqAk8riJvK4RMWx1aInLzndwxKalgi5rTqgfXxOxbEI=
12261226
github.com/tendermint/crypto v0.0.0-20191022145703-50d29ede1e15/go.mod h1:z4YtwM70uOnk8h0pjJYlj3zdYwi9l03By6iAIF5j/Pk=
1227-
github.com/tendermint/flutter v0.1.0 h1:0EWAWJWyP0QopThmc1Cxa2Ja8bft6ShraHoLOpllWow=
1228-
github.com/tendermint/flutter v0.1.0/go.mod h1:hW8URRpeA0KEaBWl9sOJUAlFLXeUrNWMvUoahMi1s3A=
12291227
github.com/tendermint/flutter v1.0.0 h1:z3dKFopmX8OqCBdclrnziZHTWmaKqmSfmx/5nB8yQR0=
12301228
github.com/tendermint/flutter v1.0.0/go.mod h1:hW8URRpeA0KEaBWl9sOJUAlFLXeUrNWMvUoahMi1s3A=
12311229
github.com/tendermint/go-amino v0.16.0 h1:GyhmgQKvqF82e2oZeuMSp9JTN0N09emoSZlb2lyGa2E=

starport/cmd/cmd.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package starportcmd
33
import (
44
"context"
55
"fmt"
6-
"os"
76
"path/filepath"
87
"sort"
98
"strings"
@@ -15,6 +14,7 @@ import (
1514
"github.com/tendermint/starport/starport/internal/version"
1615
"github.com/tendermint/starport/starport/pkg/clispinner"
1716
"github.com/tendermint/starport/starport/pkg/events"
17+
"github.com/tendermint/starport/starport/pkg/gitpod"
1818
"github.com/tendermint/starport/starport/pkg/goenv"
1919
"github.com/tendermint/starport/starport/pkg/xgenny"
2020
"github.com/tendermint/starport/starport/services/chain"
@@ -191,7 +191,7 @@ func deprecated() []*cobra.Command {
191191
}
192192

193193
func checkNewVersion(ctx context.Context) {
194-
if os.Getenv("GITPOD_WORKSPACE_ID") != "" {
194+
if gitpod.IsOnGitpod() {
195195
return
196196
}
197197

starport/cmd/network.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ import (
44
"context"
55
"errors"
66
"fmt"
7-
"os"
87

98
"github.com/AlecAivazis/survey/v2"
109
"github.com/AlecAivazis/survey/v2/terminal"
1110
"github.com/cosmos/cosmos-sdk/crypto/keyring"
1211
"github.com/spf13/cobra"
1312
"github.com/tendermint/starport/starport/pkg/cliquiz"
13+
"github.com/tendermint/starport/starport/pkg/gitpod"
1414
"github.com/tendermint/starport/starport/pkg/spn"
1515
"github.com/tendermint/starport/starport/services/networkbuilder"
1616
)
@@ -76,7 +76,7 @@ func newNetworkBuilder(options ...networkbuilder.Option) (*networkbuilder.Builde
7676
// password. This happens because Gitpod uses containers.
7777
//
7878
// when not on Gitpod, OS keyring backend is used which only asks password once.
79-
if os.Getenv("GITPOD_WORKSPACE_ID") != "" {
79+
if gitpod.IsOnGitpod() {
8080
spnoptions = append(spnoptions, spn.Keyring(keyring.BackendTest))
8181
}
8282

starport/cmd/version.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ func NewVersion() *cobra.Command {
1212
c := &cobra.Command{
1313
Use: "version",
1414
Short: "Print the current build information",
15-
Run: func(_ *cobra.Command, _ []string) {
16-
fmt.Println(version.Long())
15+
Run: func(cmd *cobra.Command, _ []string) {
16+
fmt.Println(version.Long(cmd.Context()))
1717
},
1818
}
1919
return c

starport/internal/version/version.go

Lines changed: 56 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
11
package version
22

33
import (
4+
"bytes"
45
"context"
56
"fmt"
7+
"os"
68
"runtime"
79
"strings"
10+
"text/tabwriter"
811

912
"github.com/blang/semver"
1013
"github.com/google/go-github/v37/github"
14+
"github.com/tendermint/starport/starport/pkg/cmdrunner/exec"
15+
"github.com/tendermint/starport/starport/pkg/cmdrunner/step"
16+
"github.com/tendermint/starport/starport/pkg/docker"
17+
"github.com/tendermint/starport/starport/pkg/gitpod"
18+
"github.com/tendermint/starport/starport/pkg/xexec"
1119
)
1220

1321
const versionDev = "development"
@@ -18,10 +26,10 @@ var (
1826
Version = versionDev
1927

2028
// Date is the build date of Starport.
21-
Date = ""
29+
Date = "-"
2230

2331
// Head is the HEAD of the current branch.
24-
Head = ""
32+
Head = "-"
2533
)
2634

2735
// CheckNext checks whether there is a new version of Starport.
@@ -59,15 +67,51 @@ func CheckNext(ctx context.Context) (isAvailable bool, version string, err error
5967
}
6068

6169
// Long generates a detailed version info.
62-
func Long() string {
63-
output := fmt.Sprintf("starport version %s %s/%s -build date: %s",
64-
Version,
65-
runtime.GOOS,
66-
runtime.GOARCH,
67-
Date)
68-
69-
if Head != "" {
70-
output = fmt.Sprintf("%s\ngit object hash: %s", output, Head)
70+
func Long(ctx context.Context) string {
71+
var (
72+
w = &tabwriter.Writer{}
73+
b = &bytes.Buffer{}
74+
)
75+
76+
write := func(k string, v interface{}) {
77+
fmt.Fprintf(w, "%s:\t%v\n", k, v)
7178
}
72-
return output
79+
80+
w.Init(b, 0, 8, 0, '\t', 0)
81+
82+
write("Starport version", Version)
83+
write("Starport build date", Date)
84+
write("Starport source hash", Head)
85+
86+
write("Your OS", runtime.GOOS)
87+
write("Your arch", runtime.GOARCH)
88+
89+
cmdOut := &bytes.Buffer{}
90+
91+
err := exec.Exec(ctx, []string{"go", "version"}, exec.StepOption(step.Stdout(cmdOut)))
92+
if err != nil {
93+
panic(err)
94+
}
95+
write("Your go version", strings.TrimSpace(cmdOut.String()))
96+
97+
unameCmd := "uname"
98+
if xexec.IsCommandAvailable(unameCmd) {
99+
cmdOut.Reset()
100+
101+
err := exec.Exec(ctx, []string{unameCmd, "-a"}, exec.StepOption(step.Stdout(cmdOut)))
102+
if err == nil {
103+
write("Your uname -a", strings.TrimSpace(cmdOut.String()))
104+
}
105+
}
106+
107+
if cwd, err := os.Getwd(); err == nil {
108+
write("Your cwd", cwd)
109+
}
110+
111+
write("Is on Gitpod", gitpod.IsOnGitpod())
112+
write("Is in Docker", docker.IsInDocker())
113+
114+
w.Flush()
115+
116+
return b.String()
73117
}

starport/pkg/docker/docker.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package docker
2+
3+
import (
4+
"os"
5+
)
6+
7+
// IsInDocker reports whether if running inside a Docker container or not.
8+
func IsInDocker() bool {
9+
_, err := os.Stat(os.ExpandEnv("$HOME/.dockerenv"))
10+
return err == nil
11+
}

starport/pkg/gitpod/gitpod.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package gitpod
2+
3+
import "os"
4+
5+
// IsOnGitpod reports whether if running on Gitpod or not.
6+
func IsOnGitpod() bool {
7+
return os.Getenv("GITPOD_WORKSPACE_ID") != ""
8+
}

starport/services/networkbuilder/blockchain.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"github.com/tendermint/starport/starport/pkg/chaincmd"
1818
"github.com/tendermint/starport/starport/pkg/cosmosver"
1919
"github.com/tendermint/starport/starport/pkg/events"
20+
"github.com/tendermint/starport/starport/pkg/gitpod"
2021
"github.com/tendermint/starport/starport/pkg/jsondoc"
2122
"github.com/tendermint/starport/starport/pkg/spn"
2223
"github.com/tendermint/starport/starport/pkg/xchisel"
@@ -75,7 +76,7 @@ func (b *Blockchain) init(
7576

7677
// use test keyring backend on Gitpod in order to prevent prompting for keyring
7778
// password. This happens because Gitpod uses containers.
78-
if os.Getenv("GITPOD_WORKSPACE_ID") != "" {
79+
if gitpod.IsOnGitpod() {
7980
chainOption = append(chainOption, chain.KeyringBackend(chaincmd.KeyringBackendTest))
8081
} else {
8182
// Otherwise use the keyring backend specified by the user

starport/services/networkbuilder/networkbuilder.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"strings"
1212
"time"
1313

14+
"github.com/tendermint/starport/starport/pkg/gitpod"
1415
"github.com/tendermint/starport/starport/pkg/xfilepath"
1516

1617
"github.com/tendermint/starport/starport/services"
@@ -379,7 +380,7 @@ func (b *Builder) StartChain(ctx context.Context, chainID string, flags []string
379380

380381
// use test keyring backend on Gitpod in order to prevent prompting for keyring
381382
// password. This happens because Gitpod uses containers.
382-
if os.Getenv("GITPOD_WORKSPACE_ID") != "" {
383+
if gitpod.IsOnGitpod() {
383384
chainOption = append(chainOption, chain.KeyringBackend(chaincmd.KeyringBackendTest))
384385
}
385386

0 commit comments

Comments
 (0)