-
Notifications
You must be signed in to change notification settings - Fork 35
/
entropy.go
52 lines (46 loc) · 1.44 KB
/
entropy.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
package cmd
import (
"github.com/gabotechs/dep-tree/internal/graph"
"github.com/gabotechs/dep-tree/internal/language"
"github.com/spf13/cobra"
"github.com/gabotechs/dep-tree/internal/entropy"
)
var noBrowserOpen bool
var enableGui bool
var renderPath string
func EntropyCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "entropy",
Short: "(default) Renders a 3d force-directed graph in the browser",
GroupID: renderGroupId,
Args: cobra.MinimumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
files, err := filesFromArgs(args)
if err != nil {
return err
}
cfg, err := loadConfig()
if err != nil {
return err
}
lang, err := inferLang(files, cfg)
if err != nil {
return err
}
parser := language.NewParser(lang)
parser.UnwrapProxyExports = cfg.UnwrapExports
parser.Exclude = cfg.Exclude
err = entropy.Render(files, parser, entropy.RenderConfig{
NoOpen: noBrowserOpen,
EnableGui: enableGui,
LoadCallbacks: graph.NewStdErrCallbacks[*language.FileInfo](),
RenderPath: renderPath,
})
return err
},
}
cmd.Flags().BoolVar(&noBrowserOpen, "no-browser-open", false, "Disable the automatic browser open while rendering entropy")
cmd.Flags().BoolVar(&enableGui, "enable-gui", false, "Enables a GUI for changing rendering settings")
cmd.Flags().StringVar(&renderPath, "render-path", "", "Sets the output path of the rendered html file")
return cmd
}