diff options
author | Chris St. Pierre <chris.a.st.pierre@gmail.com> | 2013-08-09 14:37:05 -0400 |
---|---|---|
committer | Chris St. Pierre <chris.a.st.pierre@gmail.com> | 2013-08-09 14:37:08 -0400 |
commit | cc11ada6b8871d7719fd0ea8a2ff382bba8a3bc2 (patch) | |
tree | f2e517121fa9bd21f0ccdd68abc88dddd4f6ddb1 /src/lib/Bcfg2/Options/Parser.py | |
parent | 0d149fd3584276e4ed0915609d35e9bad07bc439 (diff) | |
download | bcfg2-cc11ada6b8871d7719fd0ea8a2ff382bba8a3bc2.tar.gz bcfg2-cc11ada6b8871d7719fd0ea8a2ff382bba8a3bc2.tar.bz2 bcfg2-cc11ada6b8871d7719fd0ea8a2ff382bba8a3bc2.zip |
Options: reparse all arguments on each pass
This ensures that required positional arguments are handled properly.
If we only reparse the remaining arguments -- i.e., those that were
not understood on previous passes -- then we may parse out all of the
positional arguments on the first pass, and then on a subsequent pass
parse_known_args() will fail because the positional argument is not
provided.
Diffstat (limited to 'src/lib/Bcfg2/Options/Parser.py')
-rw-r--r-- | src/lib/Bcfg2/Options/Parser.py | 10 |
1 files changed, 3 insertions, 7 deletions
diff --git a/src/lib/Bcfg2/Options/Parser.py b/src/lib/Bcfg2/Options/Parser.py index b956ca089..343399db9 100644 --- a/src/lib/Bcfg2/Options/Parser.py +++ b/src/lib/Bcfg2/Options/Parser.py @@ -204,16 +204,12 @@ class Parser(argparse.ArgumentParser): while not self.parsed: self.parsed = True self._set_defaults() - remaining = self.parse_known_args(args=remaining, - namespace=self.namespace)[1] + self.parse_known_args(namespace=self.namespace)[1] self._parse_config_options() self._finalize() - - # phase 3: parse command line for real, with all components - # loaded and all options known self._parse_config_options() - # phase 4: fix up <repository> macros + # phase 3: fix up <repository> macros repo = getattr(self.namespace, "repository", repository.default) for attr in dir(self.namespace): value = getattr(self.namespace, attr) @@ -221,7 +217,7 @@ class Parser(argparse.ArgumentParser): setattr(self.namespace, attr, value.replace("<repository>", repo, 1)) - # phase 5: call post-parsing hooks + # phase 4: call post-parsing hooks for component in self.components: if hasattr(component, "options_parsed_hook"): getattr(component, "options_parsed_hook")() |