forked from fyne-io/fyne
-
Notifications
You must be signed in to change notification settings - Fork 0
/
env.go
66 lines (55 loc) · 1.47 KB
/
env.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package commands
import (
"fmt"
"os"
"runtime/debug"
"github.com/lucor/goinfo"
"github.com/lucor/goinfo/format"
"github.com/lucor/goinfo/report"
"github.com/urfave/cli/v2"
)
const fyneModule = "github.com/cheeryprogrammer/fyne/v2"
// Env returns the env command
func Env() *cli.Command {
return &cli.Command{
Name: "env",
Usage: "The env command prints the Fyne module and environment information",
Action: func(_ *cli.Context) error {
workDir, err := os.Getwd()
if err != nil {
return fmt.Errorf("could not get the path for the current working dir: %v", err)
}
reporters := []goinfo.Reporter{
&fyneReport{GoMod: &report.GoMod{WorkDir: workDir, Module: fyneModule}},
&report.GoVersion{},
&report.GoEnv{Filter: []string{"GOOS", "GOARCH", "CGO_ENABLED", "GO111MODULE"}},
&report.OS{},
}
err = goinfo.Write(os.Stdout, reporters, &format.Text{})
if err != nil {
return err
}
return nil
},
}
}
// fyneReport defines a custom report for fyne
type fyneReport struct {
*report.GoMod
}
// Info returns the collected info
func (r *fyneReport) Info() (goinfo.Info, error) {
info, err := r.GoMod.Info()
if err != nil {
return info, err
}
// remove info for the report
delete(info, "module")
binfo, ok := debug.ReadBuildInfo()
if !ok {
info["cli_version"] = "could not retrieve version information (ensure module support is activated and build again)"
} else {
info["cli_version"] = binfo.Main.Version
}
return info, nil
}