Skip to content

Commit 6169274

Browse files
committed
Reduce complexity of main function
1 parent db7a056 commit 6169274

1 file changed

Lines changed: 27 additions & 6 deletions

File tree

msgcheck/msgcheck.py

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,16 +102,17 @@ def msgcheck_parser():
102102
return parser
103103

104104

105-
def main(): # pylint: disable=too-many-branches
106-
"""Main function."""
107-
# parse arguments
108-
parser = msgcheck_parser()
105+
def msgcheck_args(parser):
106+
"""Return msgcheck options."""
109107
if len(sys.argv) == 1:
110108
parser.print_help()
111109
sys.exit(1)
112-
args = parser.parse_args(
110+
return parser.parse_args(
113111
shlex.split(os.getenv('MSGCHECK_OPTIONS') or '') + sys.argv[1:])
114112

113+
114+
def msgcheck_check_files(args):
115+
"""Check files."""
115116
# create checker and set boolean options
116117
po_check = PoCheck()
117118
for option in ('no_compile', 'fuzzy', 'skip_noqa', 'no_lines', 'no_punct',
@@ -128,7 +129,11 @@ def main(): # pylint: disable=too-many-branches
128129
print('FATAL:', exc, sep=' ')
129130
sys.exit(1)
130131

131-
# display error messages
132+
return result
133+
134+
135+
def msgcheck_display_errors(args, result):
136+
"""Display error messages."""
132137
files_ok, files_with_errors, total_errors = 0, 0, 0
133138
for filename, reports in result:
134139
if not reports:
@@ -146,6 +151,14 @@ def main(): # pylint: disable=too-many-branches
146151
key=lambda s: s.lower())))
147152
else:
148153
print('\n'.join([str(report) for report in reports]))
154+
return files_ok, files_with_errors, total_errors
155+
156+
157+
def msgcheck_display_result(args, result):
158+
"""Display result and return the number of files with errors."""
159+
# display errors
160+
files_ok, files_with_errors, total_errors = \
161+
msgcheck_display_errors(args, result)
149162

150163
# exit now if we extracted translations or if we displayed only
151164
# misspelled words
@@ -174,6 +187,14 @@ def main(): # pylint: disable=too-many-branches
174187
print('TOTAL: {0} files OK, {1} files with {2} errors'.format(
175188
files_ok, files_with_errors, total_errors))
176189

190+
return files_with_errors
191+
192+
193+
def main(): # pylint: disable=too-many-branches
194+
"""Main function."""
195+
args = msgcheck_args(msgcheck_parser())
196+
result = msgcheck_check_files(args)
197+
files_with_errors = msgcheck_display_result(args, result)
177198
sys.exit(min(files_with_errors, 255))
178199

179200

0 commit comments

Comments
 (0)