mirror of
https://github.com/yavook/kiwi-scp.git
synced 2024-11-22 12:53:00 +00:00
rework "SubCommand" class members
This commit is contained in:
parent
3e1d9510dc
commit
f188d05e56
7 changed files with 34 additions and 31 deletions
|
@ -4,4 +4,4 @@ export SUFFIX_DOWN=.down
|
||||||
export DOCKERNET=kiwinet
|
export DOCKERNET=kiwinet
|
||||||
export DOCKERCIDR=10.22.46.0/24
|
export DOCKERCIDR=10.22.46.0/24
|
||||||
|
|
||||||
export TARGETROOT=/var/kiwi
|
export TARGETROOT=/tmp/kiwi
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
version: '0.1'
|
version: '0.1'
|
||||||
|
|
||||||
runtime:
|
runtime:
|
||||||
storage: /var/kiwi
|
storage: /tmp/kiwi
|
||||||
env: null
|
env: null
|
||||||
|
|
||||||
markers:
|
markers:
|
||||||
|
|
|
@ -21,6 +21,6 @@ class Runner:
|
||||||
args = Parser.get_args()
|
args = Parser.get_args()
|
||||||
|
|
||||||
for cmd in cls.__commands:
|
for cmd in cls.__commands:
|
||||||
if cmd.get_cmd() == args.command:
|
if cmd.command == args.command:
|
||||||
cmd.run()
|
cmd.run()
|
||||||
return
|
return
|
||||||
|
|
|
@ -4,9 +4,7 @@ from ..config import LoadedConfig
|
||||||
|
|
||||||
|
|
||||||
class SubCommand:
|
class SubCommand:
|
||||||
@classmethod
|
command = None
|
||||||
def get_cmd(cls):
|
|
||||||
pass
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def setup(cls):
|
def setup(cls):
|
||||||
|
|
|
@ -2,14 +2,14 @@ import logging
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from ..core import KIWI_CONF_NAME, Parser
|
from ..core import KIWI_CONF_NAME, Parser
|
||||||
from ..config import DefaultConfig
|
from ..config import DefaultConfig, LoadedConfig
|
||||||
|
|
||||||
from ._utils import SubCommand
|
from ._utils import SubCommand
|
||||||
|
|
||||||
|
|
||||||
def user_input(config, key, prompt):
|
def user_input(config, key, prompt):
|
||||||
# prompt user as per argument
|
# prompt user as per argument
|
||||||
result = input("{} [Default: {}] ".format(prompt, config[key])).strip()
|
result = input("{} [{}] ".format(prompt, config[key])).strip()
|
||||||
|
|
||||||
# store result if present
|
# store result if present
|
||||||
if result:
|
if result:
|
||||||
|
@ -36,27 +36,34 @@ def user_input_exe(config, program_name):
|
||||||
|
|
||||||
|
|
||||||
class InitCommand(SubCommand):
|
class InitCommand(SubCommand):
|
||||||
__parser = None
|
command = 'init'
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def get_cmd(cls):
|
|
||||||
return 'init'
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def setup(cls):
|
def setup(cls):
|
||||||
cls.__parser = Parser.get_subparsers().add_parser(cls.get_cmd(), help="Create new kiwi-config instance")
|
parser = Parser.get_subparsers().add_parser(
|
||||||
# cls.__parser.add_argument('cmd', metavar='command', type=str, help='subcommand to execute')
|
cls.command,
|
||||||
|
description="Create a new kiwi-config instance"
|
||||||
|
)
|
||||||
|
|
||||||
|
parser.add_argument(
|
||||||
|
'-f', '--force',
|
||||||
|
action='store_true',
|
||||||
|
help="Use default values even if {} is present".format(KIWI_CONF_NAME)
|
||||||
|
)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def run(cls):
|
def run(cls):
|
||||||
config = DefaultConfig.get()
|
logging.info("Initializing kiwi-config instance in '%s'", os.getcwd())
|
||||||
|
|
||||||
if os.path.isfile(KIWI_CONF_NAME):
|
if Parser.get_args().force and os.path.isfile(KIWI_CONF_NAME):
|
||||||
logging.warning("Overwriting existing '%s'!", KIWI_CONF_NAME)
|
logging.warning("Overwriting existing '%s'!", KIWI_CONF_NAME)
|
||||||
|
config = DefaultConfig.get()
|
||||||
|
else:
|
||||||
|
config = LoadedConfig.get()
|
||||||
|
|
||||||
user_input(config, 'version', "Choose kiwi-config version")
|
user_input(config, 'version', "Enter kiwi-config version for this instance")
|
||||||
|
|
||||||
user_input(config, 'runtime:storage', "Enter main directory for local data")
|
user_input(config, 'runtime:storage', "Enter local directory for service data")
|
||||||
|
|
||||||
user_input(config, 'markers:project', "Enter marker string for project directories")
|
user_input(config, 'markers:project', "Enter marker string for project directories")
|
||||||
user_input(config, 'markers:down', "Enter marker string for disabled projects")
|
user_input(config, 'markers:down', "Enter marker string for disabled projects")
|
||||||
|
|
|
@ -4,15 +4,14 @@ from ._utils import SubCommand, Docker
|
||||||
|
|
||||||
|
|
||||||
class LogsCommand(SubCommand):
|
class LogsCommand(SubCommand):
|
||||||
__parser = None
|
command = 'logs'
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def get_cmd(cls):
|
|
||||||
return 'logs'
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def setup(cls):
|
def setup(cls):
|
||||||
cls.__parser = Parser.get_subparsers().add_parser(cls.get_cmd(), help="Show logs of a project")
|
parser = Parser.get_subparsers().add_parser(
|
||||||
|
cls.command,
|
||||||
|
description="Show logs of a project"
|
||||||
|
)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def run(cls):
|
def run(cls):
|
||||||
|
|
|
@ -5,15 +5,14 @@ from ._utils import SubCommand
|
||||||
|
|
||||||
|
|
||||||
class ShowCommand(SubCommand):
|
class ShowCommand(SubCommand):
|
||||||
__parser = None
|
command = 'show'
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def get_cmd(cls):
|
|
||||||
return 'show'
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def setup(cls):
|
def setup(cls):
|
||||||
cls.__parser = Parser.get_subparsers().add_parser(cls.get_cmd(), help="Show effective kiwi.yml")
|
parser = Parser.get_subparsers().add_parser(
|
||||||
|
cls.command,
|
||||||
|
description="Show effective kiwi.yml"
|
||||||
|
)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def run(cls):
|
def run(cls):
|
||||||
|
|
Loading…
Reference in a new issue