Skip to content

Commit f9c80b6

Browse files
committed
fix: make --exclude flag repeatable
Signed-off-by: Alessio Greggi <[email protected]>
1 parent dada614 commit f9c80b6

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

cmd/analyze.go

+12-13
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ import (
2929
)
3030

3131
var (
32-
excludedPaths []string
33-
exclude string
34-
saveAnalysis bool
32+
excludeList []string
33+
saveAnalysis bool
34+
analysisReportFile = "harpoon-report.yml"
3535
)
3636

3737
// analyzeCmd represents the create args
@@ -44,10 +44,6 @@ var analyzeCmd = &cobra.Command{
4444
SilenceUsage: true,
4545
SilenceErrors: true,
4646
RunE: func(cmd *cobra.Command, args []string) error {
47-
if exclude != "" {
48-
excludedPaths = strings.Split(exclude, ",")
49-
}
50-
5147
file, err := os.Open("go.mod")
5248
if err != nil {
5349
return fmt.Errorf("failed to open go.mod: %w", err)
@@ -130,13 +126,16 @@ var analyzeCmd = &cobra.Command{
130126

131127
// store to file
132128
if saveAnalysis {
133-
file, err = os.Create("harpoon-report.yml")
129+
file, err = os.Create(analysisReportFile)
134130
if err != nil {
135131
return fmt.Errorf("failed to create symbols list file: %w", err)
136132
}
137133
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)
140139
} else {
141140
fmt.Println(symbolsList.String())
142141
}
@@ -147,13 +146,13 @@ var analyzeCmd = &cobra.Command{
147146
func init() {
148147
rootCmd.AddCommand(analyzeCmd)
149148

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")
152151
analyzeCmd.Flags().StringVarP(&directory, "directory", "D", ".harpoon", "Store saved files in a directory")
153152
}
154153

155154
func shouldSkipPath(path string) bool {
156-
for _, excludedPath := range excludedPaths {
155+
for _, excludedPath := range excludeList {
157156
if strings.Contains(path, excludedPath) {
158157
return true
159158
}

0 commit comments

Comments
 (0)