From 3a28af7f7e64ef32d2fc42ae861449d74ebbbea9 Mon Sep 17 00:00:00 2001 From: ldericher Date: Thu, 20 Aug 2020 13:29:08 +0200 Subject: [PATCH] user query into Config object --- src/kiwi/config.py | 27 +++++++++++++++++++++++++++ src/kiwi/subcommands/init.py | 27 ++++++--------------------- 2 files changed, 33 insertions(+), 21 deletions(-) diff --git a/src/kiwi/config.py b/src/kiwi/config.py index ac56457..d5de124 100644 --- a/src/kiwi/config.py +++ b/src/kiwi/config.py @@ -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""" diff --git a/src/kiwi/subcommands/init.py b/src/kiwi/subcommands/init.py index 7e0fa59..05012c0 100644 --- a/src/kiwi/subcommands/init.py +++ b/src/kiwi/subcommands/init.py @@ -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