Skip to content

Commit

Permalink
CLI: verdi profile setdefault to set-default
Browse files Browse the repository at this point in the history
Since verdi user uses set-default, we make the two consistent by
using set-default for profile
  • Loading branch information
agoscinski committed May 28, 2024
1 parent 6051909 commit fba1216
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 11 deletions.
11 changes: 6 additions & 5 deletions docs/source/reference/command_line.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
17 changes: 15 additions & 2 deletions src/aiida/cmdline/commands/cmd_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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:
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 for the default profile.',
is_flag=True,
cls=options.interactive.InteractiveOption,
contextual_default=lambda ctx: ctx.params['user'].is_default,
Expand Down
14 changes: 11 additions & 3 deletions tests/cmdline/commands/test_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand All @@ -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
Expand Down

0 comments on commit fba1216

Please sign in to comment.