mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-05-03 07:41:30 -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
|
@ -26,6 +26,7 @@ import sys
|
|||
|
||||
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.executor.task_queue_manager import TaskQueueManager
|
||||
from ansible.module_utils._text import to_native, to_text
|
||||
|
@ -80,24 +81,22 @@ class ConsoleCLI(CLI, cmd.Cmd):
|
|||
def init_parser(self):
|
||||
super(ConsoleCLI, self).init_parser(
|
||||
usage='%prog [<host-pattern>] [options]',
|
||||
runas_opts=True,
|
||||
inventory_opts=True,
|
||||
connect_opts=True,
|
||||
check_opts=True,
|
||||
vault_opts=True,
|
||||
fork_opts=True,
|
||||
module_opts=True,
|
||||
basedir_opts=True,
|
||||
desc="REPL console for executing Ansible tasks.",
|
||||
epilog="This is not a live session/connection, each task executes in the background and returns it's results."
|
||||
)
|
||||
opt_help.add_runas_options(self.parser)
|
||||
opt_help.add_inventory_options(self.parser)
|
||||
opt_help.add_connect_options(self.parser)
|
||||
opt_help.add_check_options(self.parser)
|
||||
opt_help.add_vault_options(self.parser)
|
||||
opt_help.add_fork_options(self.parser)
|
||||
opt_help.add_module_options(self.parser)
|
||||
opt_help.add_basedir_options(self.parser)
|
||||
|
||||
# options unique to shell
|
||||
self.parser.add_option('--step', dest='step', action='store_true',
|
||||
help="one-step-at-a-time: confirm each task before running")
|
||||
|
||||
return self.parser
|
||||
|
||||
def post_process_args(self, options, args):
|
||||
options, args = super(ConsoleCLI, self).post_process_args(options, args)
|
||||
display.verbosity = options.verbosity
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue