mirror of
https://github.com/yavook/kiwi-scp.git
synced 2024-11-22 04:43: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 DOCKERCIDR=10.22.46.0/24
|
||||
|
||||
export TARGETROOT=/var/kiwi
|
||||
export TARGETROOT=/tmp/kiwi
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
version: '0.1'
|
||||
|
||||
runtime:
|
||||
storage: /var/kiwi
|
||||
storage: /tmp/kiwi
|
||||
env: null
|
||||
|
||||
markers:
|
||||
|
|
|
@ -21,6 +21,6 @@ class Runner:
|
|||
args = Parser.get_args()
|
||||
|
||||
for cmd in cls.__commands:
|
||||
if cmd.get_cmd() == args.command:
|
||||
if cmd.command == args.command:
|
||||
cmd.run()
|
||||
return
|
||||
|
|
|
@ -4,9 +4,7 @@ from ..config import LoadedConfig
|
|||
|
||||
|
||||
class SubCommand:
|
||||
@classmethod
|
||||
def get_cmd(cls):
|
||||
pass
|
||||
command = None
|
||||
|
||||
@classmethod
|
||||
def setup(cls):
|
||||
|
|
|
@ -2,14 +2,14 @@ import logging
|
|||
import os
|
||||
|
||||
from ..core import KIWI_CONF_NAME, Parser
|
||||
from ..config import DefaultConfig
|
||||
from ..config import DefaultConfig, LoadedConfig
|
||||
|
||||
from ._utils import SubCommand
|
||||
|
||||
|
||||
def user_input(config, key, prompt):
|
||||
# prompt user as per argument
|
||||
result = input("{} [Default: {}] ".format(prompt, config[key])).strip()
|
||||
result = input("{} [{}] ".format(prompt, config[key])).strip()
|
||||
|
||||
# store result if present
|
||||
if result:
|
||||
|
@ -36,27 +36,34 @@ def user_input_exe(config, program_name):
|
|||
|
||||
|
||||
class InitCommand(SubCommand):
|
||||
__parser = None
|
||||
|
||||
@classmethod
|
||||
def get_cmd(cls):
|
||||
return 'init'
|
||||
command = 'init'
|
||||
|
||||
@classmethod
|
||||
def setup(cls):
|
||||
cls.__parser = Parser.get_subparsers().add_parser(cls.get_cmd(), help="Create new kiwi-config instance")
|
||||
# cls.__parser.add_argument('cmd', metavar='command', type=str, help='subcommand to execute')
|
||||
parser = Parser.get_subparsers().add_parser(
|
||||
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
|
||||
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)
|
||||
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:down', "Enter marker string for disabled projects")
|
||||
|
|
|
@ -4,15 +4,14 @@ from ._utils import SubCommand, Docker
|
|||
|
||||
|
||||
class LogsCommand(SubCommand):
|
||||
__parser = None
|
||||
|
||||
@classmethod
|
||||
def get_cmd(cls):
|
||||
return 'logs'
|
||||
command = 'logs'
|
||||
|
||||
@classmethod
|
||||
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
|
||||
def run(cls):
|
||||
|
|
|
@ -5,15 +5,14 @@ from ._utils import SubCommand
|
|||
|
||||
|
||||
class ShowCommand(SubCommand):
|
||||
__parser = None
|
||||
|
||||
@classmethod
|
||||
def get_cmd(cls):
|
||||
return 'show'
|
||||
command = 'show'
|
||||
|
||||
@classmethod
|
||||
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
|
||||
def run(cls):
|
||||
|
|
Loading…
Reference in a new issue