commands: config: error out if value is unset
This makes sense, and matches git config's behavior too. Stay silent by default, but log.dbg() what happened. Add a test case, too. Signed-off-by: Marti Bolivar <marti.bolivar@nordicsemi.no>
This commit is contained in:
parent
b02caa6c8f
commit
52f1f48de6
|
@ -10,7 +10,7 @@ import configparser
|
|||
from west import log
|
||||
from west import configuration
|
||||
from west.configuration import ConfigFile
|
||||
from west.commands import WestCommand
|
||||
from west.commands import WestCommand, CommandError
|
||||
|
||||
CONFIG_DESCRIPTION = '''\
|
||||
West configuration file handling.
|
||||
|
@ -125,6 +125,9 @@ class Config(WestCommand):
|
|||
value = config_settings.get(section, key, fallback=None)
|
||||
if value is not None:
|
||||
log.inf(value)
|
||||
else:
|
||||
log.dbg('{} is unset'.format(args.name))
|
||||
raise CommandError(returncode=1)
|
||||
else:
|
||||
if configfile == ConfigFile.ALL:
|
||||
# No file given, thus writing defaults to LOCAL
|
||||
|
|
|
@ -270,3 +270,10 @@ def test_config_missing_key():
|
|||
cmd('config pytest')
|
||||
assert str(e) == 'west config: error: missing key, please invoke ' \
|
||||
'as: west config <section>.<key>\n'
|
||||
|
||||
def test_unset_config():
|
||||
# Getting unset configuration options should raise an error.
|
||||
# With verbose output, the exact missing option should be printed.
|
||||
with pytest.raises(subprocess.CalledProcessError) as e:
|
||||
cmd('-v config pytest.missing')
|
||||
assert 'pytest.missing is unset' in str(e)
|
||||
|
|
Loading…
Reference in New Issue