Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLI: Keep list unique in verdi config set --append #6162

Merged
merged 1 commit into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion aiida/cmdline/commands/cmd_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def verdi_config_set(ctx, option, value, globally, append, remove):
if not isinstance(current, list):
echo.echo_critical(f'cannot append/remove to value: {current}')
if append:
value = current + [value]
value = list(set(current + [value]))
else:
value = [item for item in current if item != value]

Expand Down
6 changes: 3 additions & 3 deletions tests/cmdline/commands/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,18 @@ def test_config_append_option(run_cli_command, config_with_profile_factory):
"""Test the `verdi config set --append` command when appending an option value."""
config = config_with_profile_factory()
option_name = 'caching.enabled_for'
for value in ['x', 'y']:
for value in ['x', 'y', 'x', 'y']:
options = ['config', 'set', '--append', option_name, value]
run_cli_command(cmd_verdi.verdi, options, use_subprocess=False)
assert config.get_option(option_name, scope=get_profile().name) == ['x', 'y']
assert sorted(config.get_option(option_name, scope=get_profile().name)) == ['x', 'y']


def test_config_remove_option(run_cli_command, config_with_profile_factory):
"""Test the `verdi config set --remove` command when removing an option value."""
config = config_with_profile_factory()

option_name = 'caching.disabled_for'
config.set_option(option_name, ['x', 'y'], scope=get_profile().name)
config.set_option(option_name, ['x', 'x', 'y', 'x'], scope=get_profile().name)

options = ['config', 'set', '--remove', option_name, 'x']
run_cli_command(cmd_verdi.verdi, options, use_subprocess=False)
Expand Down