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 12:05:19 +00:00
|
|
|
__parser = None
|
2020-08-06 11:43:45 +00:00
|
|
|
__subparsers = None
|
|
|
|
__args = None
|
|
|
|
|
|
|
|
@classmethod
|
2020-08-10 12:05:19 +00:00
|
|
|
def get_parser(cls):
|
|
|
|
if cls.__parser is None:
|
|
|
|
cls.__parser = argparse.ArgumentParser(description='kiwi-config')
|
2020-08-06 11:43:45 +00:00
|
|
|
|
2020-08-10 12:05:19 +00:00
|
|
|
cls.__parser.add_argument(
|
2020-08-10 12:39:28 +00:00
|
|
|
'-v', '--verbosity',
|
2020-08-10 12:05:19 +00:00
|
|
|
action='count', default=0
|
|
|
|
)
|
2020-08-06 11:43:45 +00:00
|
|
|
|
2020-08-10 12:05:19 +00:00
|
|
|
return cls.__parser
|
2020-08-06 11:43:45 +00:00
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def get_subparsers(cls):
|
2020-08-10 12:05:19 +00:00
|
|
|
if cls.__subparsers is None:
|
|
|
|
cls.__subparsers = cls.get_parser().add_subparsers()
|
|
|
|
cls.__subparsers.required = True
|
|
|
|
cls.__subparsers.dest = 'command'
|
|
|
|
|
2020-08-06 11:43:45 +00:00
|
|
|
return cls.__subparsers
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def get_args(cls):
|
2020-08-10 12:05:19 +00:00
|
|
|
if cls.__args is None:
|
|
|
|
cls.__args = cls.get_parser().parse_args()
|
2020-08-06 11:43:45 +00:00
|
|
|
|
|
|
|
return cls.__args
|