Skip to content

Commit d6cfbbf

Browse files
Options that expect a file accept lists of files too
The rationale is that these options readily accept multiple files from the command line, because they can be specified multiple times. However, duplicate option keys are invalid in an INI config file. The alternative is to accept multiple values for each occurrence of an option key.
1 parent 22ac85a commit d6cfbbf

File tree

1 file changed

+27
-18
lines changed

1 file changed

+27
-18
lines changed

codespell_lib/_codespell.py

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -339,10 +339,9 @@ def parse_options(
339339
"-D",
340340
"--dictionary",
341341
action="append",
342-
help="custom dictionary file that contains spelling "
343-
"corrections. If this flag is not specified or "
344-
'equals "-" then the default dictionary is used. '
345-
"This option can be specified multiple times.",
342+
help="comma-separated list of custom dictionary files that "
343+
"contains spelling corrections. If this flag is not specified "
344+
'or equals "-" then the default dictionary is used.',
346345
)
347346
builtin_opts = "\n- ".join(
348347
[""] + [f"{d[0]!r} {d[1]}" for d in _builtin_dictionaries]
@@ -373,25 +372,25 @@ def parse_options(
373372
"--ignore-words",
374373
action="append",
375374
metavar="FILE",
376-
help="file that contains words that will be ignored "
377-
"by codespell. File must contain 1 word per line."
378-
" Words are case sensitive based on how they are "
379-
"written in the dictionary file",
375+
help="comma-separated list of files that contain "
376+
"words to be ignored by codespell. File must contain "
377+
"1 word per line. Words are case sensitive based on "
378+
"how they are written in the dictionary file.",
380379
)
381380
parser.add_argument(
382381
"-L",
383382
"--ignore-words-list",
384383
action="append",
385384
metavar="WORDS",
386-
help="comma separated list of words to be ignored "
385+
help="comma-separated list of words to be ignored "
387386
"by codespell. Words are case sensitive based on "
388-
"how they are written in the dictionary file",
387+
"how they are written in the dictionary file.",
389388
)
390389
parser.add_argument(
391390
"--uri-ignore-words-list",
392391
action="append",
393392
metavar="WORDS",
394-
help="comma separated list of words to be ignored "
393+
help="comma-separated list of words to be ignored "
395394
"by codespell in URIs and emails only. Words are "
396395
"case sensitive based on how they are written in "
397396
'the dictionary file. If set to "*", all '
@@ -443,11 +442,13 @@ def parse_options(
443442
parser.add_argument(
444443
"-x",
445444
"--exclude-file",
445+
action="append",
446446
type=str,
447-
metavar="FILE",
448-
help="ignore whole lines that match those "
449-
"in the file FILE. The lines in FILE "
450-
"should match the to-be-excluded lines exactly",
447+
metavar="EXCLUDE",
448+
help="ignore whole lines that match those in "
449+
"the comma-separated list of files EXCLUDE. "
450+
"The lines in these files should match the "
451+
"to-be-excluded lines exactly",
451452
)
452453

453454
parser.add_argument(
@@ -994,7 +995,11 @@ def main(*args: str) -> int:
994995
else:
995996
ignore_word_regex = None
996997

997-
ignore_words_files = options.ignore_words or []
998+
ignore_words_files = []
999+
if options.ignore_words:
1000+
for iw in options.ignore_words:
1001+
ignore_words_files.extend(iw.split(","))
1002+
print(f"ignore_words_files: {ignore_words_files}")
9981003
ignore_words = parse_ignore_words_option(options.ignore_words_list)
9991004
for ignore_words_file in ignore_words_files:
10001005
if not os.path.isfile(ignore_words_file):
@@ -1019,7 +1024,10 @@ def main(*args: str) -> int:
10191024
uri_ignore_words = parse_ignore_words_option(options.uri_ignore_words_list)
10201025

10211026
if options.dictionary:
1022-
dictionaries = options.dictionary
1027+
dictionaries = []
1028+
for d in options.dictionary:
1029+
dictionaries.extend(d.split(","))
1030+
print(dictionaries)
10231031
else:
10241032
dictionaries = ["-"]
10251033
use_dictionaries = []
@@ -1085,7 +1093,8 @@ def main(*args: str) -> int:
10851093

10861094
exclude_lines: Set[str] = set()
10871095
if options.exclude_file:
1088-
build_exclude_hashes(options.exclude_file, exclude_lines)
1096+
for exclude_file in options.exclude_file.split(","):
1097+
build_exclude_hashes(exclude_file, exclude_lines)
10891098

10901099
file_opener = FileOpener(options.hard_encoding_detection, options.quiet_level)
10911100

0 commit comments

Comments
 (0)