mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-28 21:31:26 -07:00
Migrate command line parsing to argparse (#50610)
* Start of migration to argparse * various fixes and improvements * Linting fixes * Test fixes * Fix vault_password_files * Add PrependAction for argparse * A bunch of additional tweak/fixes * Fix ansible-config tests * Fix man page generation * linting fix * More adhoc pattern fixes * Add changelog fragment * Add support for argcomplete * Enable argcomplete global completion * Rename PrependAction to PrependListAction to better describe what it does * Add documentation for installing and configuring argcomplete * Address rebase issues * Fix display encoding for vault * Fix line length * Address rebase issues * Handle rebase issues * Use mutually exclusive group instead of handling manually * Fix rebase issues * Address rebase issue * Update version added for argcomplete support * -e must be given a value * ci_complete
This commit is contained in:
parent
7ee6c136fd
commit
db6cc60352
28 changed files with 930 additions and 914 deletions
|
@ -8,7 +8,7 @@ __metaclass__ = type
|
|||
from ansible import constants as C
|
||||
from ansible import context
|
||||
from ansible.cli import CLI
|
||||
from ansible.cli.arguments import optparse_helpers as opt_help
|
||||
from ansible.cli.arguments import option_helpers as opt_help
|
||||
from ansible.errors import AnsibleError, AnsibleOptionsError
|
||||
from ansible.executor.task_queue_manager import TaskQueueManager
|
||||
from ansible.module_utils._text import to_text
|
||||
|
@ -46,26 +46,22 @@ class AdHocCLI(CLI):
|
|||
opt_help.add_basedir_options(self.parser)
|
||||
|
||||
# options unique to ansible ad-hoc
|
||||
self.parser.add_option('-a', '--args', dest='module_args',
|
||||
help="module arguments", default=C.DEFAULT_MODULE_ARGS)
|
||||
self.parser.add_option('-m', '--module-name', dest='module_name',
|
||||
help="module name to execute (default=%s)" % C.DEFAULT_MODULE_NAME,
|
||||
default=C.DEFAULT_MODULE_NAME)
|
||||
self.parser.add_argument('-a', '--args', dest='module_args',
|
||||
help="module arguments", default=C.DEFAULT_MODULE_ARGS)
|
||||
self.parser.add_argument('-m', '--module-name', dest='module_name',
|
||||
help="module name to execute (default=%s)" % C.DEFAULT_MODULE_NAME,
|
||||
default=C.DEFAULT_MODULE_NAME)
|
||||
self.parser.add_argument('args', metavar='pattern', help='host pattern')
|
||||
|
||||
def post_process_args(self, options, args):
|
||||
def post_process_args(self, options):
|
||||
'''Post process and validate options for bin/ansible '''
|
||||
|
||||
options, args = super(AdHocCLI, self).post_process_args(options, args)
|
||||
|
||||
if len(args) < 1:
|
||||
raise AnsibleOptionsError("Missing target hosts")
|
||||
elif len(args) > 1:
|
||||
raise AnsibleOptionsError("Extraneous options or arguments")
|
||||
options = super(AdHocCLI, self).post_process_args(options)
|
||||
|
||||
display.verbosity = options.verbosity
|
||||
self.validate_conflicts(options, runas_opts=True, vault_opts=True, fork_opts=True)
|
||||
self.validate_conflicts(options, runas_opts=True, fork_opts=True)
|
||||
|
||||
return options, args
|
||||
return options
|
||||
|
||||
def _play_ds(self, pattern, async_val, poll):
|
||||
check_raw = context.CLIARGS['module_name'] in ('command', 'win_command', 'shell', 'win_shell', 'script', 'raw')
|
||||
|
@ -89,7 +85,7 @@ class AdHocCLI(CLI):
|
|||
super(AdHocCLI, self).run()
|
||||
|
||||
# only thing left should be host pattern
|
||||
pattern = to_text(context.CLIARGS['args'][0], errors='surrogate_or_strict')
|
||||
pattern = to_text(context.CLIARGS['args'], errors='surrogate_or_strict')
|
||||
|
||||
sshpass = None
|
||||
becomepass = None
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue