1
0
Fork 0
mirror of https://github.com/yavook/kiwi-scp.git synced 2024-11-22 21:03:00 +00:00
kiwi-scp/src/kiwi/subcommands/init.py

53 lines
1.3 KiB
Python
Raw Normal View History

2020-08-12 15:46:50 +00:00
# system
2020-08-06 12:34:25 +00:00
import logging
import os
2020-08-12 15:46:50 +00:00
# local
2020-08-18 10:28:59 +00:00
from .._constants import KIWI_CONF_NAME
2020-08-19 15:21:38 +00:00
from ..subcommand import SubCommand
from ..config import DefaultConfig, LoadedConfig
2020-08-18 10:28:59 +00:00
2020-08-06 12:34:25 +00:00
class InitCommand(SubCommand):
2020-08-13 08:48:01 +00:00
"""kiwi init"""
def __init__(self):
super().__init__(
'init',
2020-08-19 15:42:09 +00:00
action=f"Initializing '{KIWI_CONF_NAME}' in",
2020-08-10 09:24:39 +00:00
description="Create a new kiwi-config instance"
)
2020-08-13 08:48:01 +00:00
# -f switch: Initialize with default config
2020-08-11 12:03:00 +00:00
self._sub_parser.add_argument(
2020-08-10 09:24:39 +00:00
'-f', '--force',
action='store_true',
2020-08-10 14:35:38 +00:00
help=f"use default values even if {KIWI_CONF_NAME} is present"
2020-08-10 09:24:39 +00:00
)
2020-08-06 12:34:25 +00:00
def _run_instance(self, runner, args):
config = LoadedConfig.get()
2020-08-06 12:34:25 +00:00
2020-08-13 12:26:49 +00:00
# check force switch
2020-08-11 12:03:00 +00:00
if args.force and os.path.isfile(KIWI_CONF_NAME):
2020-08-12 15:46:50 +00:00
2020-08-10 12:50:47 +00:00
logging.warning(f"Overwriting existing '{KIWI_CONF_NAME}'!")
2020-08-10 09:24:39 +00:00
config = DefaultConfig.get()
2020-08-06 12:34:25 +00:00
2020-08-13 12:26:49 +00:00
# version
2020-08-20 11:29:08 +00:00
config.user_query('version')
2020-08-11 12:03:00 +00:00
2020-08-13 12:26:49 +00:00
# runtime
2020-08-20 11:29:08 +00:00
config.user_query('runtime:storage')
2020-08-06 12:34:25 +00:00
2020-08-13 12:26:49 +00:00
# markers
2020-08-20 11:29:08 +00:00
config.user_query('markers:project')
config.user_query('markers:disabled')
2020-08-13 12:26:49 +00:00
# network
2020-08-20 11:29:08 +00:00
config.user_query('network:name')
config.user_query('network:cidr')
2020-08-06 12:34:25 +00:00
2020-08-13 12:26:49 +00:00
config.save()
2020-08-17 13:00:05 +00:00
return True