user query into Config object

This commit is contained in:
Jörn-Michael Miehe 2020-08-20 13:29:08 +02:00
parent 3468570403
commit 3a28af7f7e
2 changed files with 33 additions and 21 deletions

View file

@ -13,6 +13,19 @@ class Config:
"""represents a kiwi.yml""" """represents a kiwi.yml"""
__yml_content = {} __yml_content = {}
__keys = {
'version': "kiwi-config version to use in this instance",
'runtime:storage': "local directory for service data",
'runtime:shells': "shell preference for working in service containers",
'runtime:env': "common environment for compose yml",
'markers:project': "marker string for project directories",
'markers:disabled': "marker string for disabled projects",
'network:name': "name for local network hub",
'network:cidr': "CIDR block for local network hub",
}
def __key_resolve(self, key): def __key_resolve(self, key):
""" """
@ -80,6 +93,20 @@ class Config:
except yaml.YAMLError as exc: except yaml.YAMLError as exc:
logging.error(exc) logging.error(exc)
def user_query(self, key):
"""query user for new config value"""
# prompt user as per argument
try:
result = input(f"Enter {self.__keys[key]} [{self[key]}] ").strip()
except EOFError:
print()
result = None
# store result if present
if result:
self[key] = result
def save(self): def save(self):
"""save current yml representation in current directory's kiwi.yml""" """save current yml representation in current directory's kiwi.yml"""

View file

@ -8,21 +8,6 @@ from ..subcommand import SubCommand
from ..config import DefaultConfig, LoadedConfig from ..config import DefaultConfig, LoadedConfig
def user_input(config, key, prompt):
"""query user for new config value"""
# prompt user as per argument
try:
result = input(f"{prompt} [{config[key]}] ").strip()
except EOFError:
print()
result = None
# store result if present
if result:
config[key] = result
class InitCommand(SubCommand): class InitCommand(SubCommand):
"""kiwi init""" """kiwi init"""
@ -50,18 +35,18 @@ class InitCommand(SubCommand):
config = DefaultConfig.get() config = DefaultConfig.get()
# version # version
user_input(config, 'version', "Enter kiwi-config version for this instance") config.user_query('version')
# runtime # runtime
user_input(config, 'runtime:storage', "Enter local directory for service data") config.user_query('runtime:storage')
# markers # markers
user_input(config, 'markers:project', "Enter marker string for project directories") config.user_query('markers:project')
user_input(config, 'markers:disabled', "Enter marker string for disabled projects") config.user_query('markers:disabled')
# network # network
user_input(config, 'network:name', "Enter name for local docker network") config.user_query('network:name')
user_input(config, 'network:cidr', "Enter CIDR block for local docker network") config.user_query('network:cidr')
config.save() config.save()
return True return True