@@ -29,9 +29,9 @@ import (
29
29
)
30
30
31
31
var (
32
- excludedPaths []string
33
- exclude string
34
- saveAnalysis bool
32
+ excludeList []string
33
+ saveAnalysis bool
34
+ analysisReportFile = "harpoon-report.yml"
35
35
)
36
36
37
37
// analyzeCmd represents the create args
@@ -44,10 +44,6 @@ var analyzeCmd = &cobra.Command{
44
44
SilenceUsage : true ,
45
45
SilenceErrors : true ,
46
46
RunE : func (cmd * cobra.Command , args []string ) error {
47
- if exclude != "" {
48
- excludedPaths = strings .Split (exclude , "," )
49
- }
50
-
51
47
file , err := os .Open ("go.mod" )
52
48
if err != nil {
53
49
return fmt .Errorf ("failed to open go.mod: %w" , err )
@@ -130,13 +126,16 @@ var analyzeCmd = &cobra.Command{
130
126
131
127
// store to file
132
128
if saveAnalysis {
133
- file , err = os .Create ("harpoon-report.yml" )
129
+ file , err = os .Create (analysisReportFile )
134
130
if err != nil {
135
131
return fmt .Errorf ("failed to create symbols list file: %w" , err )
136
132
}
137
133
mw := io .Writer (file )
138
- fmt .Fprintln (mw , symbolsList .String ())
139
- fmt .Println ("file harpoon-report.yml is ready" )
134
+ _ , err := fmt .Fprintln (mw , symbolsList .String ())
135
+ if err != nil {
136
+ return fmt .Errorf ("error writing into %s: %v" , analysisReportFile , err )
137
+ }
138
+ fmt .Printf ("file %s is ready\n " , analysisReportFile )
140
139
} else {
141
140
fmt .Println (symbolsList .String ())
142
141
}
@@ -147,13 +146,13 @@ var analyzeCmd = &cobra.Command{
147
146
func init () {
148
147
rootCmd .AddCommand (analyzeCmd )
149
148
150
- analyzeCmd .Flags ().StringVarP ( & exclude , "exclude" , "e" , "" , "Skip directories specified in the comma separated list " )
151
- analyzeCmd .Flags ().BoolVarP (& saveAnalysis , "save" , "S" , false , "Save the result of analysis into a file" )
149
+ analyzeCmd .Flags ().StringSliceVarP ( & excludeList , "exclude" , "e" , [] string {} , "Exclude directory from analysis " )
150
+ analyzeCmd .Flags ().BoolVarP (& saveAnalysis , "save" , "S" , false , "Save analysis result into a file" )
152
151
analyzeCmd .Flags ().StringVarP (& directory , "directory" , "D" , ".harpoon" , "Store saved files in a directory" )
153
152
}
154
153
155
154
func shouldSkipPath (path string ) bool {
156
- for _ , excludedPath := range excludedPaths {
155
+ for _ , excludedPath := range excludeList {
157
156
if strings .Contains (path , excludedPath ) {
158
157
return true
159
158
}
0 commit comments