|
16 | 16 |
|
17 | 17 | import click |
18 | 18 |
|
19 | | -from aiida.cmdline.commands.cmd_verdi import VerdiCommandGroup, verdi |
| 19 | +from aiida.cmdline.commands.cmd_verdi import verdi |
| 20 | +from aiida.cmdline.groups.dynamic import DynamicEntryPointCommandGroup |
20 | 21 | from aiida.cmdline.params import arguments, options |
21 | 22 | from aiida.cmdline.params.options.commands import computer as options_computer |
22 | 23 | from aiida.cmdline.utils import echo, echo_tabulate |
23 | 24 | from aiida.cmdline.utils.common import validate_output_filename |
24 | 25 | from aiida.cmdline.utils.decorators import with_dbenv |
25 | | -from aiida.common.exceptions import EntryPointError, ValidationError |
26 | | -from aiida.plugins.entry_point import get_entry_point_names |
| 26 | +from aiida.common.exceptions import ValidationError |
27 | 27 |
|
28 | 28 |
|
29 | 29 | @verdi.group('computer') |
@@ -709,48 +709,33 @@ def computer_configure(): |
709 | 709 | def computer_config_show(computer, user, defaults, as_option_string): |
710 | 710 | """Show the current configuration for a computer.""" |
711 | 711 | from aiida.common.escaping import escape_for_bash |
712 | | - from aiida.transports import cli as transport_cli |
713 | 712 |
|
714 | 713 | transport_cls = computer.get_transport_class() |
715 | | - option_list = [ |
716 | | - param |
717 | | - for param in transport_cli.create_configure_cmd(computer.transport_type).params |
718 | | - if isinstance(param, click.core.Option) |
719 | | - ] |
720 | | - option_list = [option for option in option_list if option.name in transport_cls.get_valid_auth_params()] |
| 714 | + configuration = computer.get_configuration(user) |
| 715 | + model = transport_cls.Model(**configuration) |
721 | 716 |
|
722 | | - if defaults: |
723 | | - config = {option.name: transport_cli.transport_option_default(option.name, computer) for option in option_list} |
724 | | - else: |
725 | | - config = computer.get_configuration(user) |
726 | | - |
727 | | - option_items = [] |
728 | | - if as_option_string: |
729 | | - for option in option_list: |
730 | | - t_opt = transport_cls.auth_options[option.name] |
731 | | - if config.get(option.name) or config.get(option.name) is False: |
732 | | - if t_opt.get('switch'): |
733 | | - option_value = ( |
734 | | - option.opts[-1] if config.get(option.name) else f'--no-{option.name.replace("_", "-")}' |
735 | | - ) |
736 | | - elif t_opt.get('is_flag'): |
737 | | - is_default = config.get(option.name) == transport_cli.transport_option_default( |
738 | | - option.name, computer |
739 | | - ) |
740 | | - option_value = option.opts[-1] if is_default else '' |
741 | | - else: |
742 | | - option_value = f'{option.opts[-1]}={option.type(config[option.name])}' |
743 | | - option_items.append(option_value) |
744 | | - opt_string = ' '.join(option_items) |
745 | | - echo.echo(escape_for_bash(opt_string)) |
746 | | - else: |
747 | | - table = [] |
748 | | - for name in transport_cls.get_valid_auth_params(): |
749 | | - if name in config: |
750 | | - table.append((f'* {name}', config[name])) |
| 717 | + if not as_option_string: |
| 718 | + echo_tabulate(list(model.model_dump().items()), tablefmt='plain') |
| 719 | + return |
| 720 | + |
| 721 | + option_list = [] |
| 722 | + |
| 723 | + for key, value in model.model_dump().items(): |
| 724 | + if value is None or value == '': |
| 725 | + continue |
| 726 | + |
| 727 | + if model.model_fields[key].annotation is bool: |
| 728 | + if value: |
| 729 | + option_list.append(f'--{key.replace("_", "-")}') |
751 | 730 | else: |
752 | | - table.append((f'* {name}', '-')) |
753 | | - echo_tabulate(table, tablefmt='plain') |
| 731 | + option_list.append(f'--no-{key.replace("_", "-")}') |
| 732 | + else: |
| 733 | + try: |
| 734 | + option_list.append(f'--{key.replace("_", "-")}={value.value}') |
| 735 | + except AttributeError: |
| 736 | + option_list.append(f'--{key.replace("_", "-")}={value}') |
| 737 | + |
| 738 | + echo.echo(escape_for_bash(' '.join(option_list))) |
754 | 739 |
|
755 | 740 |
|
756 | 741 | @verdi_computer.group('export') |
|
0 commit comments