-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmd.go
69 lines (59 loc) · 1.43 KB
/
cmd.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
67
68
69
package depcmd
import (
"fmt"
"os"
"runtime/debug"
"github.com/olekukonko/tablewriter"
"github.com/pubgo/dix"
"github.com/pubgo/funk/pretty"
"github.com/pubgo/funk/recovery"
"github.com/pubgo/funk/running"
"github.com/pubgo/funk/version"
cli "github.com/urfave/cli/v2"
"github.com/pubgo/lava/pkg/cmdutil"
)
func New(di *dix.Dix) *cli.Command {
return &cli.Command{
Name: "dep",
Usage: "Print the dependency package information",
Description: cmdutil.ExampleFmt(
"lava dep",
"lava dep json",
"lava dep t"),
Action: func(ctx *cli.Context) error {
defer recovery.Exit()
info, ok := debug.ReadBuildInfo()
if !ok {
return nil
}
var typ string
if ctx.NArg() > 0 {
typ = ctx.Args().First()
}
switch typ {
case "":
pretty.Println(info)
case "sys":
pretty.Println(running.GetSysInfo())
case "table", "tb", "t":
table := tablewriter.NewWriter(os.Stdout)
table.SetHeader([]string{"path", "Version", "Replace"})
table.Append([]string{info.Main.Path, version.Version(), replace(info.Main.Replace)})
for _, dep := range info.Deps {
table.Append([]string{dep.Path, dep.Version, replace(dep.Replace)})
}
table.Render()
case "di":
fmt.Println(di.Graph().Objects)
fmt.Println(di.Graph().Providers)
}
return nil
},
}
}
func replace(dep *debug.Module) string {
if dep == nil {
return ""
}
return fmt.Sprintf("%s:%s", dep.Path, dep.Version)
}