Skip to content

Commit

Permalink
Options that expect a file 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 3, 2023
1 parent 22ac85a commit d6cfbbf
Showing 1 changed file with 27 additions and 18 deletions.
45 changes: 27 additions & 18 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 "
"contains 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 @@ -373,25 +372,25 @@ def parse_options(
"--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",
help="comma-separated list of files that contain "
"words to 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.",
)
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="EXCLUDE",
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 @@ -994,7 +995,11 @@ 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(","))
print(f"ignore_words_files: {ignore_words_files}")
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 @@ -1019,7 +1024,10 @@ 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(","))
print(dictionaries)
else:
dictionaries = ["-"]
use_dictionaries = []
Expand Down Expand Up @@ -1085,7 +1093,8 @@ 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 in options.exclude_file.split(","):
build_exclude_hashes(exclude_file, exclude_lines)

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

Expand Down

0 comments on commit d6cfbbf

Please sign in to comment.