Updating salt-call, salt-run and salt to show documentation when a valid module but no function is passed.

This commit is contained in:
Gareth J. Greenaway 2017-07-19 11:56:36 -07:00
parent ddc0286d57
commit 343b970a00
4 changed files with 36 additions and 11 deletions

View File

@ -165,6 +165,11 @@ class BaseCaller(object):
ret['jid']
)
if fun not in self.minion.functions:
docs = self.minion.functions['sys.doc']('{0}*'.format(fun))
if docs:
ret['out'] = 'nested'
ret['return'] = docs
return ret
sys.stderr.write(self.minion.functions.missing_fun_string(fun))
mod_name = fun.split('.')[0]
if mod_name in self.minion.function_errors:

View File

@ -5,6 +5,7 @@ A collection of mixins useful for the various *Client interfaces
# Import Python libs
from __future__ import absolute_import, print_function, with_statement
import fnmatch
import signal
import logging
import weakref
@ -436,7 +437,16 @@ class SyncClientMixin(object):
Return a dictionary of functions and the inline documentation for each
'''
if arg:
if '*' in arg:
target_mod = arg
_use_fnmatch = True
else:
target_mod = arg + '.' if not arg.endswith('.') else arg
log.debug('target_mod {}'.format(target_mod))
if _use_fnmatch:
docs = [(fun, self.functions[fun].__doc__)
for fun in fnmatch.filter(self.functions, target_mod)]
else:
docs = [(fun, self.functions[fun].__doc__)
for fun in sorted(self.functions)
if fun == arg or fun.startswith(target_mod)]

View File

@ -1519,6 +1519,10 @@ class Minion(MinionBase):
salt.utils.error.fire_exception(salt.exceptions.MinionError(msg), opts, job=data)
ret['return'] = '{0}: {1}'.format(msg, traceback.format_exc())
ret['out'] = 'nested'
else:
docs = minion_instance.functions['sys.doc']('{0}*'.format(function_name))
if docs:
ret['return'] = docs
else:
ret['return'] = minion_instance.functions.missing_fun_string(function_name)
mod_name = function_name.split('.')[0]

View File

@ -276,6 +276,12 @@ class Runner(RunnerClient):
'fun_args': fun_args,
'jid': self.jid},
tag='salt/run/{0}/ret'.format(self.jid))
# Attempt to grab documentation
ret = self.get_docs('{0}*'.format(low['fun']))
# If we didn't get docs returned then
# return the `not availble` message.
if not ret:
ret = '{0}'.format(exc)
if not self.opts.get('quiet', False):
display_output(ret, 'nested', self.opts)