2020-08-06 11:43:45 +00:00
|
|
|
import argparse
|
|
|
|
import os
|
|
|
|
|
|
|
|
###########
|
|
|
|
# CONSTANTS
|
|
|
|
|
|
|
|
KIWI_ROOT = os.getenv('KIWI_ROOT', ".")
|
|
|
|
KIWI_CONF_NAME = os.getenv('KIWI_CONF_NAME', "kiwi.yml")
|
|
|
|
|
|
|
|
|
|
|
|
class Parser:
|
2020-08-10 13:21:39 +00:00
|
|
|
class __Parser:
|
|
|
|
__parser = None
|
|
|
|
__subparsers = None
|
|
|
|
__args = None
|
2020-08-06 11:43:45 +00:00
|
|
|
|
2020-08-10 13:21:39 +00:00
|
|
|
def __init__(self):
|
|
|
|
self.__parser = argparse.ArgumentParser(description='kiwi-config')
|
2020-08-06 11:43:45 +00:00
|
|
|
|
2020-08-10 13:21:39 +00:00
|
|
|
self.__subparsers = self.__parser.add_subparsers()
|
|
|
|
self.__subparsers.required = True
|
|
|
|
self.__subparsers.dest = 'command'
|
2020-08-06 11:43:45 +00:00
|
|
|
|
2020-08-10 13:21:39 +00:00
|
|
|
def get_parser(self):
|
|
|
|
return self.__parser
|
2020-08-10 12:05:19 +00:00
|
|
|
|
2020-08-10 13:21:39 +00:00
|
|
|
def get_subparsers(self):
|
|
|
|
return self.__subparsers
|
2020-08-06 11:43:45 +00:00
|
|
|
|
2020-08-10 13:21:39 +00:00
|
|
|
def get_args(self):
|
|
|
|
if self.__args is None:
|
|
|
|
self.__args = self.__parser.parse_args()
|
2020-08-06 11:43:45 +00:00
|
|
|
|
2020-08-10 13:21:39 +00:00
|
|
|
return self.__args
|
|
|
|
|
|
|
|
__instance = None
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
if Parser.__instance is None:
|
|
|
|
Parser.__instance = Parser.__Parser()
|
|
|
|
|
|
|
|
def __getattr__(self, item):
|
|
|
|
return getattr(self.__instance, item)
|