diff --git a/docs/source/reference/command_line.rst b/docs/source/reference/command_line.rst index 8c47f04046..564d9eb7a8 100644 --- a/docs/source/reference/command_line.rst +++ b/docs/source/reference/command_line.rst @@ -395,11 +395,12 @@ Below is a list with all available subcommands. --help Show this message and exit. Commands: - delete Delete one or more profiles. - list Display a list of all available profiles. - setdefault Set a profile as the default one. - setup Set up a new profile. - show Show details for a profile. + delete Delete one or more profiles. + list Display a list of all available profiles. + set-default Set a profile as the default profile. + setdefault Set a profile as the default profile. + setup Set up a new profile. + show Show details for a profile. .. _reference:command-line:verdi-quicksetup: diff --git a/src/aiida/cmdline/commands/cmd_profile.py b/src/aiida/cmdline/commands/cmd_profile.py index 0d22b9025b..39ef300218 100644 --- a/src/aiida/cmdline/commands/cmd_profile.py +++ b/src/aiida/cmdline/commands/cmd_profile.py @@ -17,6 +17,7 @@ from aiida.cmdline.params import arguments, options from aiida.cmdline.params.options.commands import setup from aiida.cmdline.utils import defaults, echo +from aiida.cmdline.utils.decorators import deprecated_command from aiida.common import exceptions from aiida.manage.configuration import Profile, create_profile, get_config @@ -78,7 +79,7 @@ def command_create_profile( echo.echo_success(f'Created new profile `{profile.name}`.') if set_as_default: - ctx.invoke(profile_setdefault, profile=profile) + ctx.invoke(profile_set_default, profile=profile) @verdi_profile.group( @@ -148,9 +149,21 @@ def profile_show(profile): @verdi_profile.command('setdefault') +@deprecated_command('setdefault is deprecated, use set-default instead', version=3) @arguments.PROFILE(required=True, default=None) def profile_setdefault(profile): - """Set a profile as the default one.""" + """Set a profile as the default profile.""" + _profile_set_default(profile) + + +@verdi_profile.command('set-default') +@arguments.PROFILE(required=True, default=None) +def profile_set_default(profile): + """Set a profile as the default profile.""" + _profile_set_default(profile) + + +def _profile_set_default(profile): try: config = get_config() except (exceptions.MissingConfigurationError, exceptions.ConfigurationError) as exception: diff --git a/src/aiida/cmdline/commands/cmd_user.py b/src/aiida/cmdline/commands/cmd_user.py index b3505baa51..b9361e1922 100644 --- a/src/aiida/cmdline/commands/cmd_user.py +++ b/src/aiida/cmdline/commands/cmd_user.py @@ -60,7 +60,7 @@ def user_list(): @click.option( '--set-default', prompt='Set as default?', - help='Set the user as the default user for the current profile.', + help='Set the user as the default user for the default profile.', is_flag=True, cls=options.interactive.InteractiveOption, contextual_default=lambda ctx: ctx.params['user'].is_default, diff --git a/tests/cmdline/commands/test_profile.py b/tests/cmdline/commands/test_profile.py index 4c382e732c..b88ae1d854 100644 --- a/tests/cmdline/commands/test_profile.py +++ b/tests/cmdline/commands/test_profile.py @@ -49,7 +49,7 @@ def _factory(**kwargs): @pytest.mark.parametrize( 'command', - (cmd_profile.profile_list, cmd_profile.profile_setdefault, cmd_profile.profile_delete, cmd_profile.profile_show), + (cmd_profile.profile_list, cmd_profile.profile_set_default, cmd_profile.profile_delete, cmd_profile.profile_show), ) def test_help(run_cli_command, command): """Tests help text for all ``verdi profile`` commands.""" @@ -66,11 +66,19 @@ def test_list(run_cli_command, mock_profiles): assert profile_list[1] in result.output -def test_setdefault(run_cli_command, mock_profiles): - """Test the ``verdi profile setdefault`` command.""" +def test_setdefault_deprecated(run_cli_command, mock_profiles): + """Test the ``verdi profile set_default`` command.""" profile_list = mock_profiles() run_cli_command(cmd_profile.profile_setdefault, [profile_list[1]], use_subprocess=False) result = run_cli_command(cmd_profile.profile_list, use_subprocess=False) + assert 'deprecated' in result.output + + +def test_set_default(run_cli_command, mock_profiles): + """Test the ``verdi profile set_default`` command.""" + profile_list = mock_profiles() + run_cli_command(cmd_profile.profile_set_default, [profile_list[1]], use_subprocess=False) + result = run_cli_command(cmd_profile.profile_list, use_subprocess=False) assert 'Report: configuration folder:' in result.output assert f'* {profile_list[1]}' in result.output