mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-24 11:21:25 -07:00
Migrate cli and dependencies to use global display
This commit is contained in:
parent
1b7d3f2898
commit
318bfbb207
12 changed files with 167 additions and 131 deletions
|
@ -34,6 +34,14 @@ from ansible.plugins import get_all_plugin_loaders
|
|||
from ansible.utils.vars import load_extra_vars
|
||||
from ansible.vars import VariableManager
|
||||
|
||||
try:
|
||||
from __main__ import display
|
||||
display = display
|
||||
except ImportError:
|
||||
from ansible.utils.display import Display
|
||||
display = Display()
|
||||
|
||||
|
||||
########################################################
|
||||
|
||||
class AdHocCLI(CLI):
|
||||
|
@ -68,7 +76,7 @@ class AdHocCLI(CLI):
|
|||
if len(self.args) != 1:
|
||||
raise AnsibleOptionsError("Missing target hosts")
|
||||
|
||||
self.display.verbosity = self.options.verbosity
|
||||
display.verbosity = self.options.verbosity
|
||||
self.validate_conflicts(runas_opts=True, vault_opts=True, fork_opts=True)
|
||||
|
||||
return True
|
||||
|
@ -86,7 +94,6 @@ class AdHocCLI(CLI):
|
|||
|
||||
super(AdHocCLI, self).run()
|
||||
|
||||
|
||||
# only thing left should be host pattern
|
||||
pattern = self.args[0]
|
||||
|
||||
|
@ -121,7 +128,7 @@ class AdHocCLI(CLI):
|
|||
hosts = inventory.list_hosts(pattern)
|
||||
no_hosts = False
|
||||
if len(hosts) == 0:
|
||||
self.display.warning("provided hosts list is empty, only localhost is available")
|
||||
display.warning("provided hosts list is empty, only localhost is available")
|
||||
no_hosts = True
|
||||
|
||||
if self.options.subset:
|
||||
|
@ -131,9 +138,9 @@ class AdHocCLI(CLI):
|
|||
raise AnsibleError("Specified --limit does not match any hosts")
|
||||
|
||||
if self.options.listhosts:
|
||||
self.display.display(' hosts (%d):' % len(hosts))
|
||||
display.display(' hosts (%d):' % len(hosts))
|
||||
for host in hosts:
|
||||
self.display.display(' %s' % host)
|
||||
display.display(' %s' % host)
|
||||
return 0
|
||||
|
||||
if self.options.module_name in C.MODULE_REQUIRE_ARGS and not self.options.module_args:
|
||||
|
@ -168,7 +175,6 @@ class AdHocCLI(CLI):
|
|||
inventory=inventory,
|
||||
variable_manager=variable_manager,
|
||||
loader=loader,
|
||||
display=self.display,
|
||||
options=self.options,
|
||||
passwords=passwords,
|
||||
stdout_callback=cb,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue