From 237ee29200d48b7ca09f5595fe9fb953c775d804 Mon Sep 17 00:00:00 2001 From: Kateryna Dovgan <46348880+k-dovgan@users.noreply.github.com> Date: Wed, 20 Apr 2022 11:42:42 +0300 Subject: [PATCH 1/4] fix(doc): add commentary on default parser --- universum/lib/module_arguments.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/universum/lib/module_arguments.py b/universum/lib/module_arguments.py index 9deb8b18..46d91086 100644 --- a/universum/lib/module_arguments.py +++ b/universum/lib/module_arguments.py @@ -135,6 +135,15 @@ def _needs_default_parser(subparsers_action, args): return True def _add_default_parser(self, args): + *** + We need to manually add the default parser because of the following reasons. + Argparser allows calls like this: ``./executable --arg=value1 subcommand --arg=value2`` + after processing this is transformed to two different namespaces, each of which have + argument 'arg' with two different values. So calling ``universum -vt=p4 poll`` and + ``universum poll -vt=p4``will transfer these args to different namespaces. Taking into + account that we also manually process environment variables, handling such structure + is more complicated, than excluding non-subcommand namespace complitely. + *** subparsers_action = self._get_subparsers_action() if not subparsers_action: return From 24c9cf36a46b63553a74c63f63033fb141ad3d49 Mon Sep 17 00:00:00 2001 From: Kateryna Dovgan <46348880+k-dovgan@users.noreply.github.com> Date: Wed, 20 Apr 2022 11:53:41 +0300 Subject: [PATCH 2/4] typo --- universum/lib/module_arguments.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/universum/lib/module_arguments.py b/universum/lib/module_arguments.py index 46d91086..5a0989c6 100644 --- a/universum/lib/module_arguments.py +++ b/universum/lib/module_arguments.py @@ -135,7 +135,7 @@ def _needs_default_parser(subparsers_action, args): return True def _add_default_parser(self, args): - *** + """ We need to manually add the default parser because of the following reasons. Argparser allows calls like this: ``./executable --arg=value1 subcommand --arg=value2`` after processing this is transformed to two different namespaces, each of which have @@ -143,7 +143,7 @@ def _add_default_parser(self, args): ``universum poll -vt=p4``will transfer these args to different namespaces. Taking into account that we also manually process environment variables, handling such structure is more complicated, than excluding non-subcommand namespace complitely. - *** + """ subparsers_action = self._get_subparsers_action() if not subparsers_action: return From 540bc6a2b8b5d8a8e14a2d1a835a99c6fa12be29 Mon Sep 17 00:00:00 2001 From: Kateryna Dovgan <46348880+k-dovgan@users.noreply.github.com> Date: Wed, 20 Apr 2022 18:12:47 +0300 Subject: [PATCH 3/4] fix(doc): add clarifications due to review --- universum/lib/module_arguments.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/universum/lib/module_arguments.py b/universum/lib/module_arguments.py index 5a0989c6..598e882c 100644 --- a/universum/lib/module_arguments.py +++ b/universum/lib/module_arguments.py @@ -136,13 +136,12 @@ def _needs_default_parser(subparsers_action, args): def _add_default_parser(self, args): """ - We need to manually add the default parser because of the following reasons. - Argparser allows calls like this: ``./executable --arg=value1 subcommand --arg=value2`` - after processing this is transformed to two different namespaces, each of which have - argument 'arg' with two different values. So calling ``universum -vt=p4 poll`` and - ``universum poll -vt=p4``will transfer these args to different namespaces. Taking into - account that we also manually process environment variables, handling such structure - is more complicated, than excluding non-subcommand namespace complitely. + We need to manually add the default parser because of subcommand's arguments intersection. + 1. We need subcommands for namespaces and help messages to be ajustable in different Universum modes. + 2. If a subcommand is passed, and arguments in parser and subparser intersect, all values passed to + non-subparser are ignored; so without default subparser ``universum -vt=p4 submit`` will result in + undefined value of 'vcs_type', and ``universum -vt=p4 submit -vt=git`` will result in 'git' value. + Adding default subparser allows to avoid such unexpected behaviour. """ subparsers_action = self._get_subparsers_action() if not subparsers_action: From ce05199f74c01044ad5c6fc76b7085f3edefc3a0 Mon Sep 17 00:00:00 2001 From: Kateryna Dovgan <46348880+k-dovgan@users.noreply.github.com> Date: Wed, 20 Apr 2022 18:17:20 +0300 Subject: [PATCH 4/4] fix(doc): add more explanations --- universum/lib/module_arguments.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/universum/lib/module_arguments.py b/universum/lib/module_arguments.py index 598e882c..69682beb 100644 --- a/universum/lib/module_arguments.py +++ b/universum/lib/module_arguments.py @@ -142,6 +142,8 @@ def _add_default_parser(self, args): non-subparser are ignored; so without default subparser ``universum -vt=p4 submit`` will result in undefined value of 'vcs_type', and ``universum -vt=p4 submit -vt=git`` will result in 'git' value. Adding default subparser allows to avoid such unexpected behaviour. + 3. Also if arguments of 'general' parser and a subparser intersect, the environment variables are + stored to 'general' parser (and then ignored as described above). """ subparsers_action = self._get_subparsers_action() if not subparsers_action: