1
0
Fork 0
mirror of https://github.com/yavook/kiwi-scp.git synced 2024-11-24 21:52:59 +00:00

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"""
__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):
"""
@ -80,6 +93,20 @@ class Config:
except yaml.YAMLError as 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):
"""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
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):
"""kiwi init"""
@ -50,18 +35,18 @@ class InitCommand(SubCommand):
config = DefaultConfig.get()
# version
user_input(config, 'version', "Enter kiwi-config version for this instance")
config.user_query('version')
# runtime
user_input(config, 'runtime:storage', "Enter local directory for service data")
config.user_query('runtime:storage')
# markers
user_input(config, 'markers:project', "Enter marker string for project directories")
user_input(config, 'markers:disabled', "Enter marker string for disabled projects")
config.user_query('markers:project')
config.user_query('markers:disabled')
# network
user_input(config, 'network:name', "Enter name for local docker network")
user_input(config, 'network:cidr', "Enter CIDR block for local docker network")
config.user_query('network:name')
config.user_query('network:cidr')
config.save()
return True