Marco Ricci commited on 2025-01-23 10:51:36
Zeige 1 geänderte Dateien mit 26 Einfügungen und 26 Löschungen.
| ... | ... |
@@ -1465,6 +1465,13 @@ def derivepassphrase_export_vault( |
| 1465 | 1465 |
# Vault |
| 1466 | 1466 |
# ===== |
| 1467 | 1467 |
|
| 1468 |
+_config_filename_table = {
|
|
| 1469 |
+ None: '.', |
|
| 1470 |
+ 'vault': 'vault.json', |
|
| 1471 |
+ 'user configuration': 'config.toml', |
|
| 1472 |
+ 'old settings.json': 'settings.json', |
|
| 1473 |
+} |
|
| 1474 |
+ |
|
| 1468 | 1475 |
|
| 1469 | 1476 |
def _config_filename( |
| 1470 | 1477 |
subsystem: str | None = 'old settings.json', |
| ... | ... |
@@ -1499,18 +1506,11 @@ def _config_filename( |
| 1499 | 1506 |
os.getenv(PROG_NAME.upper() + '_PATH') |
| 1500 | 1507 |
or click.get_app_dir(PROG_NAME, force_posix=True) |
| 1501 | 1508 |
) |
| 1502 |
- # Use match/case here once Python 3.9 becomes unsupported. |
|
| 1503 |
- if subsystem is None: |
|
| 1504 |
- return path |
|
| 1505 |
- elif subsystem == 'vault': # noqa: RET505 |
|
| 1506 |
- filename = f'{subsystem}.json'
|
|
| 1507 |
- elif subsystem == 'user configuration': |
|
| 1508 |
- filename = 'config.toml' |
|
| 1509 |
- elif subsystem == 'old settings.json': |
|
| 1510 |
- filename = 'settings.json' |
|
| 1511 |
- else: # pragma: no cover |
|
| 1509 |
+ try: |
|
| 1510 |
+ filename = _config_filename_table[subsystem] |
|
| 1511 |
+ except (KeyError, TypeError): # pragma: no cover |
|
| 1512 | 1512 |
msg = f'Unknown configuration subsystem: {subsystem!r}'
|
| 1513 |
- raise AssertionError(msg) |
|
| 1513 |
+ raise AssertionError(msg) from None |
|
| 1514 | 1514 |
return path / filename |
| 1515 | 1515 |
|
| 1516 | 1516 |
|
| ... | ... |
@@ -2577,21 +2577,21 @@ def derivepassphrase_vault( # noqa: C901,PLR0912,PLR0913,PLR0914,PLR0915 |
| 2577 | 2577 |
for param in ctx.command.params: |
| 2578 | 2578 |
if isinstance(param, click.Option): |
| 2579 | 2579 |
group: type[click.Option] |
| 2580 |
- # Use match/case here once Python 3.9 becomes unsupported. |
|
| 2581 |
- if isinstance(param, PassphraseGenerationOption): |
|
| 2582 |
- group = PassphraseGenerationOption |
|
| 2583 |
- elif isinstance(param, ConfigurationOption): |
|
| 2584 |
- group = ConfigurationOption |
|
| 2585 |
- elif isinstance(param, StorageManagementOption): |
|
| 2586 |
- group = StorageManagementOption |
|
| 2587 |
- elif isinstance(param, LoggingOption): |
|
| 2588 |
- group = LoggingOption |
|
| 2589 |
- elif isinstance(param, CompatibilityOption): |
|
| 2590 |
- group = CompatibilityOption |
|
| 2591 |
- elif isinstance(param, StandardOption): |
|
| 2592 |
- group = StandardOption |
|
| 2593 |
- elif isinstance(param, OptionGroupOption): # pragma: no cover |
|
| 2594 |
- raise AssertionError( # noqa: TRY003,TRY004 |
|
| 2580 |
+ known_option_groups = [ |
|
| 2581 |
+ PassphraseGenerationOption, |
|
| 2582 |
+ ConfigurationOption, |
|
| 2583 |
+ StorageManagementOption, |
|
| 2584 |
+ LoggingOption, |
|
| 2585 |
+ CompatibilityOption, |
|
| 2586 |
+ StandardOption, |
|
| 2587 |
+ ] |
|
| 2588 |
+ if isinstance(param, OptionGroupOption): |
|
| 2589 |
+ for class_ in known_option_groups: |
|
| 2590 |
+ if isinstance(param, class_): |
|
| 2591 |
+ group = class_ |
|
| 2592 |
+ break |
|
| 2593 |
+ else: # pragma: no cover |
|
| 2594 |
+ raise AssertionError( # noqa: TRY003 |
|
| 2595 | 2595 |
f'Unknown option group for {param!r}' # noqa: EM102
|
| 2596 | 2596 |
) |
| 2597 | 2597 |
else: |
| 2598 | 2598 |