Skip to content

Commit 47431cf

Browse files
committed
Moved ctrl.type='legacy' to ctrl.legacy to separate concerns
1 parent ef1ff2c commit 47431cf

2 files changed

Lines changed: 8 additions & 8 deletions

File tree

remove-json-keys/src/remove_json_keys/lib/settings.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,23 @@
2727
debug=sn(
2828
args=['-V', '--debug'], nargs='?', const=True, metavar='TARGET_KEY' ),
2929
no_wizard_legacy=sn(
30-
args=['-W',], type='legacy')
30+
legacy=True, args=['-W',])
3131
)
3232

3333
def load(cli):
3434
cli.config = sn()
3535

3636
# Assign help tips from cli.msgs
3737
for ctrl_key, ctrl in vars(controls).items():
38-
if getattr(ctrl, 'type', None) == 'legacy' : continue
38+
if getattr(ctrl, 'legacy', False) : continue
3939
if not hasattr(ctrl, 'help') : ctrl.help = getattr(cli.msgs, f'help_{ctrl_key.upper()}')
4040

4141
# Parse CLI args
4242
argp = argparse.ArgumentParser(description=cli.description, add_help=False)
4343
for ctrl_key, ctrl in vars(controls).items(): # add args to argp
4444
kwargs = ctrl.__dict__.copy()
4545
args = kwargs.pop('args')
46-
if getattr(ctrl, 'type', None) == 'legacy':
46+
if getattr(ctrl, 'legacy', False):
4747
for arg in args:
4848
if arg in sys.argv:
4949
log.warn(f'{cli.msgs.warn_OPTION} {arg} {cli.msgs.warn_NO_LONGER_HAS_ANY_EFFECT}.')
@@ -55,7 +55,7 @@ def load(cli):
5555
parsed_args, unknown_args = argp.parse_known_args()
5656
exempt_flags = [] # exempt dashless + legacy args from validation
5757
for ctrl in vars(controls).values():
58-
if getattr(ctrl, 'subcmd', False) or getattr(ctrl, 'type', None) == 'legacy':
58+
if getattr(ctrl, 'subcmd', False) or getattr(ctrl, 'legacy', False):
5959
for arg in ctrl.args : exempt_flags.append(arg)
6060
if unknown_args and not all(any(arg.startswith(exempt) for exempt in exempt_flags) for arg in unknown_args):
6161
log.cmd_docs_url_exit(cli, f"{cli.msgs.err_UNRECOGNIZED_ARGS}: {' '.join(unknown_args)}", cmd='help')

translate-messages/src/translate_messages/lib/settings.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,23 +37,23 @@
3737
debug=sn(
3838
args=['-V', '--debug'], nargs='?', const=True, metavar='TARGET_KEY' ),
3939
no_wizard_legacy=sn(
40-
args=['-W',], type='legacy')
40+
legacy=True, args=['-W',])
4141
)
4242

4343
def load(cli):
4444
cli.config = sn()
4545

4646
# Assign help tips from cli.msgs
4747
for ctrl_key, ctrl in vars(controls).items():
48-
if getattr(ctrl, 'type', None) == 'legacy' : continue
48+
if getattr(ctrl, 'legacy', False) : continue
4949
if not hasattr(ctrl, 'help') : ctrl.help = getattr(cli.msgs, f'help_{ctrl_key.upper()}')
5050

5151
# Parse CLI args
5252
argp = argparse.ArgumentParser(description=cli.description, add_help=False)
5353
for ctrl_key, ctrl in vars(controls).items(): # add args to argp
5454
kwargs = ctrl.__dict__.copy()
5555
args = kwargs.pop('args')
56-
if getattr(ctrl, 'type', None) == 'legacy':
56+
if getattr(ctrl, 'legacy', False):
5757
for arg in args:
5858
if arg in sys.argv:
5959
log.warn(f'{cli.msgs.warn_OPTION} {arg} {cli.msgs.warn_NO_LONGER_HAS_ANY_EFFECT}.')
@@ -65,7 +65,7 @@ def load(cli):
6565
parsed_args, unknown_args = argp.parse_known_args()
6666
exempt_flags = [] # exempt dashless + legacy args from validation
6767
for ctrl in vars(controls).values():
68-
if getattr(ctrl, 'subcmd', False) or getattr(ctrl, 'type', None) == 'legacy':
68+
if getattr(ctrl, 'subcmd', False) or getattr(ctrl, 'legacy', False):
6969
for arg in ctrl.args : exempt_flags.append(arg)
7070
if unknown_args and not all(any(arg.startswith(exempt) for exempt in exempt_flags) for arg in unknown_args):
7171
log.cmd_docs_url_exit(cli, f"{cli.msgs.err_UNRECOGNIZED_ARGS}: {' '.join(unknown_args)}", cmd='help')

0 commit comments

Comments
 (0)