Changeset View
Changeset View
Standalone View
Standalone View
scap/cli.py
Show First 20 Lines • Show All 115 Lines • ▼ Show 20 Lines | def _parse_arguments(self, argv): | ||||
:returns: Tuple of parsed argument Namespace and list of any extra | :returns: Tuple of parsed argument Namespace and list of any extra | ||||
arguments that were not parsed. | arguments that were not parsed. | ||||
""" | """ | ||||
self._argparser = self._build_argparser() | self._argparser = self._build_argparser() | ||||
return self._argparser.parse_known_args(argv) | return self._argparser.parse_known_args(argv) | ||||
def _build_argparser(self): | def _build_argparser(self): | ||||
parser = argparse.ArgumentParser(description=self.__doc__) | doc = self.__doc__.splitlines() if self.__doc__ else [None] | ||||
desc = doc[0] | |||||
if len(doc) > 1: | |||||
epilog = "\n".join(doc[1::]).strip() | |||||
formatter = argparse.RawDescriptionHelpFormatter | |||||
else: | |||||
epilog = None | |||||
formatter = argparse.HelpFormatter | |||||
parser = argparse.ArgumentParser(description=desc, | |||||
epilog=epilog, | |||||
formatter_class=formatter) | |||||
# Look for arguments that were added to our main method | # Look for arguments that were added to our main method | ||||
local_args = getattr(self.main, ATTR_ARGUMENTS, []) | local_args = getattr(self.main, ATTR_ARGUMENTS, []) | ||||
# List is built from the bottom up so reverse it to make the parser | # List is built from the bottom up so reverse it to make the parser | ||||
# arguments read in the same order as they were declared. | # arguments read in the same order as they were declared. | ||||
for argspec in reversed(local_args): | for argspec in reversed(local_args): | ||||
flags = argspec.pop('_flags') | flags = argspec.pop('_flags') | ||||
▲ Show 20 Lines • Show All 189 Lines • Show Last 20 Lines |
Content licensed under Creative Commons Attribution-ShareAlike 3.0 (CC-BY-SA) unless otherwise noted; code licensed under GNU General Public License (GPL) or other open source licenses. By using this site, you agree to the Terms of Use, Privacy Policy, and Code of Conduct. · Wikimedia Foundation · Privacy Policy · Code of Conduct · Terms of Use · Disclaimer · CC-BY-SA · GPL