@@ -183,6 +183,7 @@ type Options struct {
183
183
filePath string
184
184
ignores string
185
185
year int
186
+ strict bool
186
187
}
187
188
188
189
func (o * Options ) Ignores () []string {
@@ -242,7 +243,7 @@ var diagnoseCmd = &cobra.Command{
242
243
}
243
244
244
245
diagnoses := Diagnose (doctor , f , o .year , o .Ignores ())
245
- if err := Report (diagnoses ); err != nil {
246
+ if err := Report (diagnoses , o . strict ); err != nil {
246
247
os .Exit (1 )
247
248
}
248
249
},
@@ -254,6 +255,7 @@ func init() {
254
255
diagnoseCmd .Flags ().StringVarP (& o .filePath , "file" , "f" , "" , "dependencies file path" )
255
256
diagnoseCmd .Flags ().StringVarP (& o .ignores , "ignores" , "i" , "" , "ignore dependencies (separated by a space)" )
256
257
diagnoseCmd .Flags ().IntVarP (& o .year , "year" , "y" , MAX_YEAR_TO_BE_BLANK , "max years of inactivity" )
258
+ diagnoseCmd .PersistentFlags ().BoolVarP (& o .strict , "strict" , "" , false , "exit with non-zero if warnings exist" )
257
259
258
260
if err := diagnoseCmd .MarkFlagRequired ("package" ); err != nil {
259
261
fmt .Println (err .Error ())
@@ -263,7 +265,7 @@ func init() {
263
265
}
264
266
}
265
267
266
- func Report (diagnoses map [string ]Diagnosis ) error {
268
+ func Report (diagnoses map [string ]Diagnosis , strict_mode bool ) error {
267
269
errMessages , warnMessages , ignoredMessages := []string {}, []string {}, []string {}
268
270
errCount , warnCount , infoCount := 0 , 0 , 0
269
271
unDiagnosedCount , ignoredCount := 0 , 0
@@ -319,7 +321,7 @@ func Report(diagnoses map[string]Diagnosis) error {
319
321
infoCount , ignoredCount ),
320
322
)
321
323
322
- if len (errMessages ) > 0 {
324
+ if len (errMessages ) > 0 || strict_mode && warnCount > 0 {
323
325
return errors .New ("has error" )
324
326
}
325
327
0 commit comments