11package  version
22
33import  (
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
1321const  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\n git 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}
0 commit comments