Commit a740b67f authored by Amir MOHAMMADI's avatar Amir MOHAMMADI

Merge branch '65-bob-config-fixes' into 'master'

Resolve "bob config fixes"

Closes #65

See merge request !103
parents c45f9f40 2568ca86
Pipeline #33435 passed with stages
in 8 minutes and 34 seconds
"""The manager for bob's main configuration.
"""
from .. import rc
from ..rc_config import _saverc, _rc_to_str, _get_rc_path
from ..rc_config import _saverc, _rc_to_str, _get_rc_path
from .click_helper import verbosity_option, AliasedGroup
import logging
import click
......@@ -89,3 +89,41 @@ def set(key, value):
except Exception:
logger.error("Could not configure the rc file", exc_info=True)
raise click.ClickException("Failed to change the configuration.")
@config.command()
@click.argument('substr')
@click.option('-c', '--contain', is_flag=True, default=False, type=click.BOOL, show_default=True)
def unset(substr, contain=False):
"""Clear all variables starting (containing) with substring.
Clear all the variables that starts with the provided substring.
Each key/value pair for which the key starts with substring will be
removed from bob's global configuration file.
\b
Arguments
---------
substring : str
The starting substring of one or several key(s)
\b
Parameters
----------
contain : bool
If set, check also for keys containing substring
"""
found = False
for key in list(rc.keys()):
if key.startswith(substr):
found = True
del rc[key]
if contain:
if substr in key:
del rc[key]
found = True
_saverc(rc)
if not found:
if not contain:
logger.error("The key starting with '{}' was not found in the rc file".format(substr))
else:
logger.error("The key containing '{}' was not found in the rc file".format(substr))
......@@ -68,3 +68,23 @@ def test_bob_config():
}
'''
assert expected_output == result.output, result.output
# test config unset (with starting substring)
result = runner.invoke(main_cli, ['config', 'unset', 'bob.db.atnt'])
result = runner.invoke(main_cli, ['config', 'get', 'bob.db.atnt'])
assert_click_runner_result(result, 1)
# test config unset (with substring contained)
# reset the key / value pair
result = runner.invoke(
main_cli, [
'config', 'set', 'bob.db.atnt.directory',
'/home/bob/databases/orl_faces'
],
env={
ENVNAME: bobrcfile
})
result = runner.invoke(main_cli, ['config', 'unset', '--contain', 'atnt'])
result = runner.invoke(main_cli, ['config', 'get', 'bob.db.atnt'])
assert_click_runner_result(result, 1)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment