From 1caa172072f36ef965bf1005f3b93e53f15a8150 Mon Sep 17 00:00:00 2001 From: Laurent Peuch Date: Sun, 23 Jul 2017 04:16:12 +0200 Subject: [PATCH] [mod] renaming, make method name match reality and had a method for code readability --- moulinette/actionsmap.py | 7 ++++--- moulinette/interfaces/__init__.py | 3 +++ moulinette/interfaces/api.py | 2 +- moulinette/interfaces/cli.py | 7 +++++-- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/moulinette/actionsmap.py b/moulinette/actionsmap.py index 6b677640..9f8da1f5 100644 --- a/moulinette/actionsmap.py +++ b/moulinette/actionsmap.py @@ -603,9 +603,10 @@ class ActionsMap(object): # Set the global configuration to use for the parser. top_parser.set_global_conf(_global['configuration']) - # GLOBAL_SECTION = '_global' - _add_arguments(GLOBAL_SECTION, top_parser.add_global_parser(), - _global['arguments']) + if top_parser.has_global_parser(): + # GLOBAL_SECTION = '_global' + _add_arguments(GLOBAL_SECTION, top_parser.get_global_parser(), + _global['arguments']) # category_name is stuff like "user", "domain", "hooks"... # category_values is the values of this category (like actions) diff --git a/moulinette/interfaces/__init__.py b/moulinette/interfaces/__init__.py index 3b2e69bd..6d5d332b 100644 --- a/moulinette/interfaces/__init__.py +++ b/moulinette/interfaces/__init__.py @@ -72,6 +72,9 @@ class BaseActionsMapParser(object): raise NotImplementedError("derived class '%s' must override this method" % self.__class__.__name__) + def has_global_parser(self): + return False + def add_global_parser(self, **kwargs): """Add a parser for global arguments diff --git a/moulinette/interfaces/api.py b/moulinette/interfaces/api.py index 5d96af98..345624b1 100644 --- a/moulinette/interfaces/api.py +++ b/moulinette/interfaces/api.py @@ -548,7 +548,7 @@ class ActionsMapParser(BaseActionsMapParser): return [name.replace('--', '@', 1)] return [name.replace('-', '@', 1)] - def add_global_parser(self, **kwargs): + def get_global_parser(self, **kwargs): raise AttributeError("global arguments are not managed") def add_category_parser(self, name, **kwargs): diff --git a/moulinette/interfaces/cli.py b/moulinette/interfaces/cli.py index ada6697d..6a85f7a5 100644 --- a/moulinette/interfaces/cli.py +++ b/moulinette/interfaces/cli.py @@ -235,7 +235,7 @@ class ActionsMapParser(BaseActionsMapParser): if top_parser: # Append each top parser action to the global group - glob = self.add_global_parser() + glob = self.get_global_parser() for action in top_parser._actions: action.dest = SUPPRESS glob._add_action(action) @@ -252,7 +252,10 @@ class ActionsMapParser(BaseActionsMapParser): return [name, full] return [name] - def add_global_parser(self, **kwargs): + def has_global_parser(self): + return True + + def get_global_parser(self, **kwargs): if not self._global_parser: self._global_parser = self._parser.add_argument_group( "global arguments")