-
Notifications
You must be signed in to change notification settings - Fork 108
/
concept.go
47 lines (37 loc) · 1.14 KB
/
concept.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
package cmd
import (
"encoding/json"
"github.com/modernizing/coca/cmd/cmd_util"
"github.com/modernizing/coca/cmd/config"
"github.com/modernizing/coca/pkg/application/concept"
"github.com/modernizing/coca/pkg/domain/core_domain"
"github.com/spf13/cobra"
"strconv"
)
var parsedDeps []core_domain.CodeDataStruct
var conceptCmd = &cobra.Command{
Use: "concept",
Short: "build domain concept from source code",
Long: ``,
Run: func(cmd *cobra.Command, args []string) {
dependence := cmd.Flag("dependence").Value.String()
if dependence != "" {
analyser := concept.NewConceptAnalyser()
file := cmd_util.ReadFile(dependence)
_ = json.Unmarshal(file, &parsedDeps)
wordCounts := analyser.Analysis(&parsedDeps)
table := cmd_util.NewOutput(output)
table.SetHeader([]string{"Words", "Counts"})
for _, word := range wordCounts {
if word.Value > 0 {
table.Append([]string{word.Key, strconv.Itoa(word.Value)})
}
}
table.Render()
}
},
}
func init() {
rootCmd.AddCommand(conceptCmd)
conceptCmd.PersistentFlags().StringP("dependence", "d", config.CocaConfig.ReporterPath+"/deps.json", "get dependence file")
}