kiwi-scp/src/kiwi/subcommands/config.py

65 lines
1.6 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
2020-08-20 12:15:38 +00:00
class ConfigCommand(SubCommand):
"""kiwi config"""
2020-08-13 08:48:01 +00:00
def __init__(self):
super().__init__(
2020-08-20 12:15:38 +00:00
'config',
action=f"Configuring '{KIWI_CONF_NAME}' in",
description="Configure kiwi-config instance"
2020-08-10 09:24:39 +00:00
)
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
2020-08-20 12:15:38 +00:00
# -s switch: Show current config instead
self._sub_parser.add_argument(
'-s', '--show',
action='store_true',
help=f"show effective {KIWI_CONF_NAME} contents instead"
)
def _run_instance(self, runner, args):
config = LoadedConfig.get()
2020-08-06 12:34:25 +00:00
2020-08-20 12:15:38 +00:00
# check show switch
if args.show:
print(config)
return True
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