remove 'add_arguments' function
This commit is contained in:
parent
c8a89c54d0
commit
c0f2e7d8dd
3 changed files with 21 additions and 18 deletions
|
@ -149,8 +149,7 @@ def main():
|
|||
# options)
|
||||
storage_type.set('sqlite3')
|
||||
config = Config(OptionDescription('root', 'root', [word, proposal_word, misses, proposals_left] + options), persistent=True, session_id='hangman')
|
||||
parser = TiramisuCmdlineParser()
|
||||
parser.add_arguments(config)
|
||||
parser = TiramisuCmdlineParser(config)
|
||||
try:
|
||||
parser.parse_args()
|
||||
except ValueError:
|
||||
|
|
|
@ -22,8 +22,7 @@ class RemoteConfig(Config):
|
|||
|
||||
def main():
|
||||
config = RemoteConfig('http://localhost:8000')
|
||||
parser = TiramisuCmdlineParser()
|
||||
parser.add_arguments(config)
|
||||
parser = TiramisuCmdlineParser(config)
|
||||
parser.parse_args()
|
||||
config = parser.get_config()
|
||||
print(config.value.dict())
|
||||
|
|
|
@ -71,13 +71,17 @@ class _TiramisuHelpAction(_HelpAction):
|
|||
|
||||
class TiramisuCmdlineParser(ArgumentParser):
|
||||
def __init__(self,
|
||||
config: Union[Config, ConfigJson],
|
||||
*args,
|
||||
fullpath: bool=True,
|
||||
_forhelp: bool=False,
|
||||
**kwargs):
|
||||
self.fullpath = fullpath
|
||||
self.config = None
|
||||
self.config = config
|
||||
super().__init__(*args, **kwargs)
|
||||
self.register('action', 'help', _TiramisuHelpAction)
|
||||
self._config_to_argparser(_forhelp,
|
||||
self.config.option)
|
||||
|
||||
def _pop_action_class(self, kwargs, default=None):
|
||||
ret = super()._pop_action_class(kwargs, default)
|
||||
|
@ -107,9 +111,9 @@ class TiramisuCmdlineParser(ArgumentParser):
|
|||
if args != args_ and args_ and args_[0].startswith(self.prefix_chars):
|
||||
# option that was disabled are no more disable
|
||||
# so create a new parser
|
||||
new_parser = TiramisuCmdlineParser(self.prog, fullpath=self.fullpath)
|
||||
new_parser._registries = self._registries
|
||||
new_parser.add_arguments(self.config)
|
||||
new_parser = TiramisuCmdlineParser(self.config,
|
||||
self.prog,
|
||||
fullpath=self.fullpath)
|
||||
namespace_, args_ = new_parser._parse_known_args(args_, namespace)
|
||||
else:
|
||||
if self._registries['action']['help'].needs:
|
||||
|
@ -125,6 +129,9 @@ class TiramisuCmdlineParser(ArgumentParser):
|
|||
else:
|
||||
raise NotImplementedError('do not use add_argument')
|
||||
|
||||
def add_arguments(self, *args, **kwargs):
|
||||
raise NotImplementedError('do not use add_argument')
|
||||
|
||||
def add_subparsers(self, *args, **kwargs):
|
||||
raise NotImplementedError('do not use add_subparsers')
|
||||
|
||||
|
@ -208,12 +215,6 @@ class TiramisuCmdlineParser(ArgumentParser):
|
|||
for args, kwargs in actions.values():
|
||||
group.add_argument(*args, **kwargs)
|
||||
|
||||
def add_arguments(self,
|
||||
tiramisu: Union[Config, ConfigJson],
|
||||
_forhelp: bool=False) -> None:
|
||||
self.config = tiramisu
|
||||
self._config_to_argparser(_forhelp,
|
||||
self.config.option)
|
||||
|
||||
def parse_args(self, *args, **kwargs):
|
||||
kwargs['namespace'] = TiramisuNamespace(self.config)
|
||||
|
@ -237,13 +238,17 @@ class TiramisuCmdlineParser(ArgumentParser):
|
|||
def format_usage(self,
|
||||
*args,
|
||||
**kwargs):
|
||||
help_formatter = TiramisuCmdlineParser(self.prog, fullpath=self.fullpath)
|
||||
help_formatter.add_arguments(self.config, _forhelp=True)
|
||||
help_formatter = TiramisuCmdlineParser(self.config,
|
||||
self.prog,
|
||||
fullpath=self.fullpath,
|
||||
_forhelp=True)
|
||||
return super(TiramisuCmdlineParser, help_formatter).format_usage(*args, **kwargs)
|
||||
|
||||
def format_help(self, *args, **kwargs):
|
||||
help_formatter = TiramisuCmdlineParser(self.prog, fullpath=self.fullpath)
|
||||
help_formatter.add_arguments(self.config, _forhelp=True)
|
||||
help_formatter = TiramisuCmdlineParser(self.config,
|
||||
self.prog,
|
||||
fullpath=self.fullpath,
|
||||
_forhelp=True)
|
||||
return super(TiramisuCmdlineParser, help_formatter).format_help(*args, **kwargs)
|
||||
|
||||
def get_config(self):
|
||||
|
|
Loading…
Reference in a new issue