@@ -263,6 +263,11 @@ def parse_options(args):
263263                        action = 'store_true' , default = False ,
264264                        help = 'print summary of fixes' )
265265
266+     parser .add_argument ('--count' ,
267+                         action = 'store_true' , default = False ,
268+                         help = 'print the number of errors as the last line of ' 
269+                              'stderr' )
270+ 
266271    parser .add_argument ('-S' , '--skip' ,
267272                        action = 'append' ,
268273                        help = 'Comma-separated list of files to skip. It ' 
@@ -612,15 +617,15 @@ def main(*args):
612617        print ("ERROR: --write-changes cannot be used together with " 
613618              "--regex" )
614619        parser .print_help ()
615-         return  1 
620+         return  2 
616621    word_regex  =  options .regex  or  word_regex_def 
617622    try :
618623        word_regex  =  re .compile (word_regex )
619624    except  re .error  as  err :
620625        print ("ERROR: invalid regular expression \" %s\"  (%s)"  % 
621626              (word_regex , err ), file = sys .stderr )
622627        parser .print_help ()
623-         return  1 
628+         return  2 
624629
625630    ignore_words_files  =  options .ignore_words  or  []
626631    ignore_words  =  set ()
@@ -629,7 +634,7 @@ def main(*args):
629634            print ("ERROR: cannot find ignore-words file: %s"  % 
630635                  ignore_words_file , file = sys .stderr )
631636            parser .print_help ()
632-             return  1 
637+             return  2 
633638        build_ignore_words (ignore_words_file , ignore_words )
634639
635640    ignore_words_list  =  options .ignore_words_list  or  []
@@ -657,13 +662,13 @@ def main(*args):
657662                    print ("ERROR: Unknown builtin dictionary: %s"  %  (u ,),
658663                          file = sys .stderr )
659664                    parser .print_help ()
660-                     return  1 
665+                     return  2 
661666        else :
662667            if  not  os .path .isfile (dictionary ):
663668                print ("ERROR: cannot find dictionary file: %s"  %  dictionary ,
664669                      file = sys .stderr )
665670                parser .print_help ()
666-                 return  1 
671+                 return  2 
667672            use_dictionaries .append (dictionary )
668673    misspellings  =  dict ()
669674    for  dictionary  in  use_dictionaries :
@@ -684,7 +689,7 @@ def main(*args):
684689            print ("ERROR: --context/-C cannot be used together with " 
685690                  "--context-before/-B or --context-after/-A" )
686691            parser .print_help ()
687-             return  1 
692+             return  2 
688693        context_both  =  max (0 , options .context )
689694        context  =  (context_both , context_both )
690695    elif  (options .before_context  is  not   None ) or  \
@@ -742,4 +747,6 @@ def main(*args):
742747    if  summary :
743748        print ("\n -------8<-------\n SUMMARY:" )
744749        print (summary )
745-     return  bad_count 
750+     if  options .count :
751+         print (bad_count , file = sys .stderr )
752+     return  int (bool (bad_count ))
0 commit comments