4242
4343from msgcheck .po import PoCheck , PoFileReport
4444
45+ HELP_OUTPUT_FORMATS = [
46+ "full = complete output" ,
47+ "oneline = one line output" ,
48+ "extract = display all translations (all checks except compilation are disabled in this mode)" ,
49+ "misspelled = display only misspelled words" ,
50+ ]
51+
4552
4653class CustomHelpFormatter (argparse .RawDescriptionHelpFormatter , argparse .ArgumentDefaultsHelpFormatter ):
4754 """Help formatter with raw description/epilog and default values."""
@@ -59,7 +66,7 @@ def msgcheck_parser() -> argparse.ArgumentParser:
5966
6067The script returns:
6168 0: all files checked are OK (or one of these options given:
62- --extract, --only- misspelled or --ignore-errors given)
69+ --output-format={extract| misspelled} or --ignore-errors given)
6370 n: number of files with errors (1 ≤ n ≤ 255)
6471""" ,
6572 )
@@ -116,7 +123,7 @@ def msgcheck_parser() -> argparse.ArgumentParser:
116123 "-m" ,
117124 "--only-misspelled" ,
118125 action = "store_true" ,
119- help = "display only misspelled words (no error, line number and translation )" ,
126+ help = "display only misspelled words (alias of --output-format=misspelled )" ,
120127 )
121128 parser .add_argument (
122129 "-w" ,
@@ -134,7 +141,7 @@ def msgcheck_parser() -> argparse.ArgumentParser:
134141 "-e" ,
135142 "--extract" ,
136143 action = "store_true" ,
137- help = "display all translations and exit (all checks except compilation are disabled in this mode )" ,
144+ help = "display all translations and exit (alias of --output-format=extract )" ,
138145 )
139146 parser .add_argument (
140147 "-i" ,
@@ -145,9 +152,9 @@ def msgcheck_parser() -> argparse.ArgumentParser:
145152 parser .add_argument (
146153 "-o" ,
147154 "--output-format" ,
148- choices = ["full" , "oneline" ],
155+ choices = ["full" , "oneline" , "extract" , "misspelled" ],
149156 default = "full" ,
150- help = "output format: full = complete output, oneline = one line output " ,
157+ help = f "output format: { ', ' . join ( HELP_OUTPUT_FORMATS ) } " ,
151158 )
152159 parser .add_argument (
153160 "-q" ,
@@ -190,10 +197,15 @@ def msgcheck_check_files(args: argparse.Namespace) -> list[PoFileReport]:
190197 "no_punct" ,
191198 "no_whitespace" ,
192199 "no_whitespace_eol" ,
193- "extract" ,
194200 ):
195201 if args .__dict__ [option ]:
196202 po_check .set_check (option .lstrip ("no_" ), not option .startswith ("no_" ))
203+ if args .extract :
204+ args .output_format = "extract"
205+ elif args .only_misspelled :
206+ args .output_format = "misspelled"
207+ if args .output_format == "extract" :
208+ po_check .set_check ("extract" )
197209
198210 # check all files
199211 try :
@@ -216,7 +228,7 @@ def msgcheck_display_errors(args: argparse.Namespace, result: list[PoFileReport]
216228 files_with_errors += 1
217229 total_errors += len (report )
218230 if not args .quiet :
219- if args .only_misspelled :
231+ if args .output_format == "misspelled" :
220232 words = []
221233 for error in report :
222234 words .extend (error .get_misspelled_words ())
@@ -231,9 +243,8 @@ def msgcheck_display_result(args: argparse.Namespace, result: list[PoFileReport]
231243 # display errors
232244 files_ok , files_with_errors , total_errors = msgcheck_display_errors (args , result )
233245
234- # exit now if we extracted translations or if we displayed only
235- # misspelled words
236- if args .extract or args .only_misspelled :
246+ # exit now if we extracted translations or if we displayed only misspelled words
247+ if args .output_format in ("extract" , "misspelled" ):
237248 sys .exit (0 )
238249
239250 # display files with number of errors
0 commit comments