Skip to content

Commit

Permalink
CLI: Rename verdi profile setdefault to verdi profile set-default (
Browse files Browse the repository at this point in the history
…aiidateam#6426)

This is for consistency with `verdi user set-default`.
  • Loading branch information
agoscinski authored and mikibonacci committed Sep 3, 2024
1 parent 36be4aa commit edefc4a
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 11 deletions.
12 changes: 7 additions & 5 deletions docs/source/reference/command_line.rst
Original file line number Diff line number Diff line change
Expand Up @@ -414,11 +414,13 @@ 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 (Deprecated) Set a profile as the default profile (use `verdi profile set-
default`).
setup Set up a new profile.
show Show details for a profile.
.. _reference:command-line:verdi-quicksetup:
Expand Down
17 changes: 14 additions & 3 deletions src/aiida/cmdline/commands/cmd_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,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(
Expand Down Expand Up @@ -147,10 +147,21 @@ def profile_show(profile):
echo.echo_dictionary(config, fmt='yaml')


@verdi_profile.command('setdefault')
@verdi_profile.command('setdefault', deprecated='Please use `verdi profile set-default` instead.')
@arguments.PROFILE(required=True, default=None)
def profile_setdefault(profile):
"""Set a profile as the default one."""
"""Set a profile as the default profile (use `verdi profile set-default`)."""
_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:
Expand Down
2 changes: 1 addition & 1 deletion src/aiida/cmdline/commands/cmd_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
is_flag=True,
cls=options.interactive.InteractiveOption,
contextual_default=lambda ctx: ctx.params['user'].is_default,
Expand Down
18 changes: 16 additions & 2 deletions tests/cmdline/commands/test_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,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."""
Expand All @@ -73,7 +73,21 @@ def test_list(run_cli_command, mock_profiles):
def test_setdefault(run_cli_command, mock_profiles):
"""Test the ``verdi profile setdefault`` command."""
profile_list = mock_profiles()
run_cli_command(cmd_profile.profile_setdefault, [profile_list[1]], use_subprocess=False)
setdefault_result = 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 'Report: configuration folder:' in result.output
assert f'* {profile_list[1]}' in result.output

# test if deprecation warning is printed
assert 'Deprecated:' in setdefault_result.output
assert 'Deprecated:' in setdefault_result.stderr


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
Expand Down

0 comments on commit edefc4a

Please sign in to comment.