Skip to content

Commit b7f6cfa

Browse files
committed
Add strict mode option
1 parent 99f9cf3 commit b7f6cfa

File tree

3 files changed

+28
-6
lines changed

3 files changed

+28
-6
lines changed

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,12 @@ Usage:
4949
dep-doctor diagnose [flags]
5050

5151
Flags:
52-
-f, --file string dependencies file path (default "Gemfile.lock")
52+
-f, --file string dependencies file path
5353
-h, --help help for diagnose
5454
-i, --ignores string ignore dependencies (separated by a space)
55-
-p, --package string package manager (default "bundler")
55+
-p, --package string package manager
56+
--strict exit with non-zero if warnings exist
5657
-y, --year int max years of inactivity (default 5)
57-
5858
```
5959

6060
For example:

cmd/diagnose.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ type Options struct {
183183
filePath string
184184
ignores string
185185
year int
186+
strict bool
186187
}
187188

188189
func (o *Options) Ignores() []string {
@@ -242,7 +243,7 @@ var diagnoseCmd = &cobra.Command{
242243
}
243244

244245
diagnoses := Diagnose(doctor, f, o.year, o.Ignores())
245-
if err := Report(diagnoses); err != nil {
246+
if err := Report(diagnoses, o.strict); err != nil {
246247
os.Exit(1)
247248
}
248249
},
@@ -254,6 +255,7 @@ func init() {
254255
diagnoseCmd.Flags().StringVarP(&o.filePath, "file", "f", "", "dependencies file path")
255256
diagnoseCmd.Flags().StringVarP(&o.ignores, "ignores", "i", "", "ignore dependencies (separated by a space)")
256257
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")
257259

258260
if err := diagnoseCmd.MarkFlagRequired("package"); err != nil {
259261
fmt.Println(err.Error())
@@ -263,7 +265,7 @@ func init() {
263265
}
264266
}
265267

266-
func Report(diagnoses map[string]Diagnosis) error {
268+
func Report(diagnoses map[string]Diagnosis, strict_mode bool) error {
267269
errMessages, warnMessages, ignoredMessages := []string{}, []string{}, []string{}
268270
errCount, warnCount, infoCount := 0, 0, 0
269271
unDiagnosedCount, ignoredCount := 0, 0
@@ -319,7 +321,7 @@ func Report(diagnoses map[string]Diagnosis) error {
319321
infoCount, ignoredCount),
320322
)
321323

322-
if len(errMessages) > 0 {
324+
if len(errMessages) > 0 || strict_mode && warnCount > 0 {
323325
return errors.New("has error")
324326
}
325327

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
GEM
2+
remote: https://rubygems.org/
3+
specs:
4+
concurrent-ruby (1.1.5)
5+
dotenv (2.7.2)
6+
faker (1.9.3)
7+
i18n (>= 0.7)
8+
i18n (1.6.0)
9+
concurrent-ruby (~> 1.0)
10+
active_decorator-rspec (0.0.9)
11+
12+
PLATFORMS
13+
ruby
14+
15+
DEPENDENCIES
16+
dotenv (~> 2.7)
17+
faker (~> 1.9)
18+
19+
BUNDLED WITH
20+
1.17.2

0 commit comments

Comments
 (0)