(config: ArchConfig)
| 32 | |
| 33 | |
| 34 | async def save_config(config: ArchConfig) -> None: |
| 35 | def preview(item: MenuItem) -> str | None: |
| 36 | match item.value: |
| 37 | case 'user_config': |
| 38 | serialized = config.user_config_to_json() |
| 39 | return f'{USER_CONFIG_FILE}\n{serialized}' |
| 40 | case 'user_creds': |
| 41 | if maybe_serial := config.user_credentials_to_json(): |
| 42 | return f'{USER_CREDS_FILE}\n{maybe_serial}' |
| 43 | return tr('No configuration') |
| 44 | case 'all': |
| 45 | output = [str(USER_CONFIG_FILE)] |
| 46 | config.user_credentials_to_json() |
| 47 | output.append(str(USER_CREDS_FILE)) |
| 48 | return '\n'.join(output) |
| 49 | return None |
| 50 | |
| 51 | items = [ |
| 52 | MenuItem( |
| 53 | tr('Save user configuration (including disk layout)'), |
| 54 | value='user_config', |
| 55 | preview_action=preview, |
| 56 | ), |
| 57 | MenuItem( |
| 58 | tr('Save user credentials'), |
| 59 | value='user_creds', |
| 60 | preview_action=preview, |
| 61 | ), |
| 62 | MenuItem( |
| 63 | tr('Save all'), |
| 64 | value='all', |
| 65 | preview_action=preview, |
| 66 | ), |
| 67 | ] |
| 68 | |
| 69 | group = MenuItemGroup(items) |
| 70 | result = await Selection[str]( |
| 71 | group, |
| 72 | allow_skip=True, |
| 73 | preview_location='right', |
| 74 | ).show() |
| 75 | |
| 76 | match result.type_: |
| 77 | case ResultType.Skip: |
| 78 | return |
| 79 | case ResultType.Selection: |
| 80 | save_option = result.get_value() |
| 81 | case _: |
| 82 | raise ValueError('Unhandled return type') |
| 83 | |
| 84 | readline.set_completer_delims('\t\n=') |
| 85 | readline.parse_and_bind('tab: complete') |
| 86 | |
| 87 | dest_path = await prompt_dir( |
| 88 | tr('Enter a directory for the configuration(s) to be saved') + '\n', |
| 89 | allow_skip=True, |
| 90 | ) |
| 91 |
no test coverage detected