mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-25 03:41:25 -07:00
Split up the base_parser function
The goal of breaking apart the base_parser() function is to get rid of a bunch of conditionals and parameters in the code and, instead, make code look like simple composition. When splitting, a choice had to be made as to whether this would operate by side effect (modifying a passed in parser) or side effect-free (returning a new parser everytime). Making a version that's side-effect-free appears to be fighting with the optparse API (it wants to work by creating a parser object, configuring the object, and then parsing the arguments with it) so instead, make it clear that our helper functions are modifying the passed in parser by (1) not returning the parser and (2) changing the function names to be more clear that it is operating by side-effect. Also move all of the generic optparse code, along with the argument context classes, into a new subdirectory.
This commit is contained in:
parent
afdbb0d9d5
commit
7e92ff823e
21 changed files with 545 additions and 486 deletions
|
@ -16,6 +16,7 @@ import ansible.plugins.loader as plugin_loader
|
|||
|
||||
from ansible import constants as C
|
||||
from ansible import context
|
||||
from ansible.arguments import optparse_helpers as opt_help
|
||||
from ansible.cli import CLI
|
||||
from ansible.errors import AnsibleError, AnsibleOptionsError
|
||||
from ansible.module_utils._text import to_native
|
||||
|
@ -47,12 +48,12 @@ class DocCLI(CLI):
|
|||
|
||||
def init_parser(self):
|
||||
|
||||
self.parser = super(DocCLI, self).init_parser(
|
||||
super(DocCLI, self).init_parser(
|
||||
usage='usage: %prog [-l|-F|-s] [options] [-t <plugin type> ] [plugin]',
|
||||
module_opts=True,
|
||||
desc="plugin documentation tool",
|
||||
epilog="See man pages for Ansible CLI options or website for tutorials https://docs.ansible.com"
|
||||
)
|
||||
opt_help.add_module_options(self.parser)
|
||||
|
||||
self.parser.add_option("-F", "--list_files", action="store_true", default=False, dest="list_files",
|
||||
help='Show plugin names and their source files without summaries (implies --list)')
|
||||
|
@ -68,7 +69,6 @@ class DocCLI(CLI):
|
|||
help='Choose which plugin type (defaults to "module"). '
|
||||
'Available plugin types are : {0}'.format(C.DOCUMENTABLE_PLUGINS),
|
||||
choices=C.DOCUMENTABLE_PLUGINS)
|
||||
return self.parser
|
||||
|
||||
def post_process_args(self, options, args):
|
||||
if [options.all_plugins, options.json_dump, options.list_dir, options.list_files, options.show_snippet].count(True) > 1:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue