@@ -145,7 +145,7 @@ def __call__(
145
145
146
146
147
147
class WriteArgAction (argparse .Action ):
148
- """Argparse action to handle the --write flag with optional args."""
148
+ """Argparse action to handle the --fix flag with optional args."""
149
149
150
150
_default = "__default__"
151
151
@@ -174,8 +174,8 @@ def __init__( # pylint: disable=too-many-arguments,redefined-builtin
174
174
super ().__init__ (
175
175
option_strings = option_strings ,
176
176
dest = dest ,
177
- nargs = "?" , # either 0 (--write ) or 1 (--write =a,b,c) argument
178
- const = self ._default , # --write (no option) implicitly stores this
177
+ nargs = "?" , # either 0 (--fix ) or 1 (--fix =a,b,c) argument
178
+ const = self ._default , # --fix (no option) implicitly stores this
179
179
default = default ,
180
180
type = type ,
181
181
choices = choices ,
@@ -194,8 +194,8 @@ def __call__(
194
194
lintables = getattr (namespace , "lintables" , None )
195
195
if not lintables and isinstance (values , str ):
196
196
# args are processed in order.
197
- # If --write is after lintables, then that is not ambiguous.
198
- # But if --write comes first, then it might actually be a lintable.
197
+ # If --fix is after lintables, then that is not ambiguous.
198
+ # But if --fix comes first, then it might actually be a lintable.
199
199
maybe_lintable = Path (values )
200
200
if maybe_lintable .exists ():
201
201
namespace .lintables = [values ]
@@ -211,19 +211,19 @@ def __call__(
211
211
setattr (namespace , self .dest , values )
212
212
213
213
@classmethod
214
- def merge_write_list_config (
214
+ def merge_fix_list_config (
215
215
cls ,
216
216
from_file : list [str ],
217
217
from_cli : list [str ],
218
218
) -> list [str ]:
219
- """Combine the write_list from file config with --write CLI arg.
219
+ """Combine the write_list from file config with --fix CLI arg.
220
220
221
221
Handles the implicit "all" when "__default__" is present and file config is empty.
222
222
"""
223
223
if not from_file or "none" in from_cli :
224
- # --write is the same as --write =all
224
+ # --fix is the same as --fix =all
225
225
return ["all" if value == cls ._default else value for value in from_cli ]
226
- # --write means use the config from the config file
226
+ # --fix means use the config from the config file
227
227
from_cli = [value for value in from_cli if value != cls ._default ]
228
228
return from_file + from_cli
229
229
@@ -338,7 +338,7 @@ def get_cli_parser() -> argparse.ArgumentParser:
338
338
help = "Return non-zero exit code on warnings as well as errors" ,
339
339
)
340
340
parser .add_argument (
341
- "--write " ,
341
+ "--fix " ,
342
342
dest = "write_list" ,
343
343
# this is a tri-state argument that takes an optional comma separated list:
344
344
action = WriteArgAction ,
@@ -347,12 +347,12 @@ def get_cli_parser() -> argparse.ArgumentParser:
347
347
"A rule transform can fix or simplify fixing issues identified by that rule). "
348
348
"You can limit the effective rule transforms (the 'write_list') by passing a "
349
349
"keywords 'all' or 'none' or a comma separated list of rule ids or rule tags. "
350
- "YAML reformatting happens whenever '--write ' or '--write =' is used. "
351
- "'--write ' and '--write =all' are equivalent: they allow all transforms to run. "
350
+ "YAML reformatting happens whenever '--fix ' or '--fix =' is used. "
351
+ "'--fix ' and '--fix =all' are equivalent: they allow all transforms to run. "
352
352
"The effective list of transforms comes from 'write_list' in the config file, "
353
- "followed whatever '--write ' args are provided on the commandline. "
354
- "'--write =none' resets the list of transforms to allow reformatting YAML "
355
- "without running any of the transforms (ie '--write =none,rule-id' will "
353
+ "followed whatever '--fix ' args are provided on the commandline. "
354
+ "'--fix =none' resets the list of transforms to allow reformatting YAML "
355
+ "without running any of the transforms (ie '--fix =none,rule-id' will "
356
356
"ignore write_list in the config file and only run the rule-id transform)." ,
357
357
)
358
358
parser .add_argument (
@@ -533,7 +533,7 @@ def merge_config(file_config: dict[Any, Any], cli_config: Options) -> Options:
533
533
setattr (
534
534
cli_config ,
535
535
entry ,
536
- WriteArgAction .merge_write_list_config (
536
+ WriteArgAction .merge_fix_list_config (
537
537
from_file = file_config .pop (entry , []),
538
538
from_cli = getattr (cli_config , entry , []) or [],
539
539
),
@@ -557,6 +557,13 @@ def merge_config(file_config: dict[Any, Any], cli_config: Options) -> Options:
557
557
def get_config (arguments : list [str ]) -> Options :
558
558
"""Extract the config based on given args."""
559
559
parser = get_cli_parser ()
560
+ # translate deprecated options
561
+ for i , value in enumerate (arguments ):
562
+ if arguments [i ].startswith ("--write" ):
563
+ arguments [i ] = value .replace ("--write" , "--fix" )
564
+ _logger .warning (
565
+ "Replaced deprecated '--write' option with '--fix', change you call to avoid future regressions when we remove old option." ,
566
+ )
560
567
options = Options (** vars (parser .parse_args (arguments )))
561
568
562
569
# docs is not document, being used for internal documentation building
0 commit comments