Skip to content

Commit

Permalink
Options that expect a file should accept lists of files too
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
DimitriPapadopoulos committed Mar 10, 2023
1 parent cee9eff commit 88539fa
Showing 1 changed file with 27 additions and 19 deletions.
46 changes: 27 additions & 19 deletions codespell_lib/_codespell.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,10 +339,9 @@ def parse_options(
"-D",
"--dictionary",
action="append",
help="custom dictionary file that contains spelling "
"corrections. If this flag is not specified or "
'equals "-" then the default dictionary is used. '
"This option can be specified multiple times.",
help="comma-separated list of custom dictionary files that "
"contain spelling corrections. If this flag is not specified "
'or equals "-" then the default dictionary is used.',
)
builtin_opts = "\n- ".join(
[""] + [f"{d[0]!r} {d[1]}" for d in _builtin_dictionaries]
Expand Down Expand Up @@ -372,26 +371,26 @@ def parse_options(
"-I",
"--ignore-words",
action="append",
metavar="FILE",
help="file that contains words that will be ignored "
"by codespell. File must contain 1 word per line."
" Words are case sensitive based on how they are "
"written in the dictionary file",
metavar="FILES",
help="comma-separated list of files that contain "
"words to be ignored by codespell. Files must contain "
"1 word per line. Words are case sensitive based on "
"how they are written in the dictionary file.",
)
parser.add_argument(
"-L",
"--ignore-words-list",
action="append",
metavar="WORDS",
help="comma separated list of words to be ignored "
help="comma-separated list of words to be ignored "
"by codespell. Words are case sensitive based on "
"how they are written in the dictionary file",
"how they are written in the dictionary file.",
)
parser.add_argument(
"--uri-ignore-words-list",
action="append",
metavar="WORDS",
help="comma separated list of words to be ignored "
help="comma-separated list of words to be ignored "
"by codespell in URIs and emails only. Words are "
"case sensitive based on how they are written in "
'the dictionary file. If set to "*", all '
Expand Down Expand Up @@ -443,11 +442,13 @@ def parse_options(
parser.add_argument(
"-x",
"--exclude-file",
action="append",
type=str,
metavar="FILE",
help="ignore whole lines that match those "
"in the file FILE. The lines in FILE "
"should match the to-be-excluded lines exactly",
metavar="FILES",
help="ignore whole lines that match those in "
"the comma-separated list of files EXCLUDE. "
"The lines in these files should match the "
"to-be-excluded lines exactly",
)

parser.add_argument(
Expand Down Expand Up @@ -1028,7 +1029,10 @@ def main(*args: str) -> int:
else:
ignore_word_regex = None

ignore_words_files = options.ignore_words or []
ignore_words_files = []
if options.ignore_words:
for iw in options.ignore_words:
ignore_words_files.extend(iw.split(","))
ignore_words = parse_ignore_words_option(options.ignore_words_list)
for ignore_words_file in ignore_words_files:
if not os.path.isfile(ignore_words_file):
Expand All @@ -1053,7 +1057,9 @@ def main(*args: str) -> int:
uri_ignore_words = parse_ignore_words_option(options.uri_ignore_words_list)

if options.dictionary:
dictionaries = options.dictionary
dictionaries = []
for d in options.dictionary:
dictionaries.extend(d.split(","))
else:
dictionaries = ["-"]
use_dictionaries = []
Expand Down Expand Up @@ -1119,7 +1125,9 @@ def main(*args: str) -> int:

exclude_lines: Set[str] = set()
if options.exclude_file:
build_exclude_hashes(options.exclude_file, exclude_lines)
for exclude_file_list in options.exclude_file:
for exclude_file in exclude_file_list.split(","):
build_exclude_hashes(exclude_file, exclude_lines)

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

Expand Down

0 comments on commit 88539fa

Please sign in to comment.