mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Several changes to ansible-doc
added display of deprecated to ansible-doc now it does better job of using tty columns fixed indication truncation of desc with trailing ... removed extension from module list, also fixed matching exlusion blacklist
This commit is contained in:
parent
cc12c9b226
commit
1b70ef6cba
1 changed files with 34 additions and 11 deletions
|
@ -164,7 +164,11 @@ def get_snippet_text(doc):
|
||||||
return "\n".join(text)
|
return "\n".join(text)
|
||||||
|
|
||||||
def get_module_list_text(module_list):
|
def get_module_list_text(module_list):
|
||||||
|
columns = max(60, int(os.popen('stty size', 'r').read().split()[1]))
|
||||||
|
displace = max(len(x) for x in module_list)
|
||||||
|
linelimit = columns - displace - 5
|
||||||
text = []
|
text = []
|
||||||
|
deprecated = []
|
||||||
for module in sorted(set(module_list)):
|
for module in sorted(set(module_list)):
|
||||||
|
|
||||||
if module in module_docs.BLACKLIST_MODULES:
|
if module in module_docs.BLACKLIST_MODULES:
|
||||||
|
@ -181,13 +185,22 @@ def get_module_list_text(module_list):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
doc, plainexamples = module_docs.get_docstring(filename)
|
doc, plainexamples = module_docs.get_docstring(filename)
|
||||||
desc = tty_ify(doc.get('short_description', '?'))
|
desc = tty_ify(doc.get('short_description', '?')).strip()
|
||||||
if len(desc) > 55:
|
if len(desc) > linelimit:
|
||||||
desc = desc + '...'
|
desc = desc[:linelimit] + '...'
|
||||||
text.append("%-20s %-60.60s" % (module, desc))
|
|
||||||
|
if module.startswith('_'): # Handle replecated
|
||||||
|
module = module[1:]
|
||||||
|
deprecated.append("%-*s %-*.*s" % (displace, module, linelimit, len(desc), desc))
|
||||||
|
else:
|
||||||
|
text.append("%-*s %-*.*s" % (displace, module, linelimit, len(desc), desc))
|
||||||
except:
|
except:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
sys.stderr.write("ERROR: module %s has a documentation error formatting or is missing documentation\n" % module)
|
sys.stderr.write("ERROR: module %s has a documentation error formatting or is missing documentation\n" % module)
|
||||||
|
|
||||||
|
if len(deprecated) > 0:
|
||||||
|
text.append("\nDEPRECATED:")
|
||||||
|
text.extend(deprecated)
|
||||||
return "\n".join(text)
|
return "\n".join(text)
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
@ -208,6 +221,11 @@ def main():
|
||||||
default=False,
|
default=False,
|
||||||
dest='list_dir',
|
dest='list_dir',
|
||||||
help='List available modules')
|
help='List available modules')
|
||||||
|
p.add_option("-c", "--list-columns",
|
||||||
|
action="store_true",
|
||||||
|
default=False,
|
||||||
|
dest='list_columns',
|
||||||
|
help='List modules in columns')
|
||||||
p.add_option("-s", "--snippet",
|
p.add_option("-s", "--snippet",
|
||||||
action="store_true",
|
action="store_true",
|
||||||
default=False,
|
default=False,
|
||||||
|
@ -221,18 +239,23 @@ def main():
|
||||||
for i in options.module_path.split(os.pathsep):
|
for i in options.module_path.split(os.pathsep):
|
||||||
utils.plugins.module_finder.add_directory(i)
|
utils.plugins.module_finder.add_directory(i)
|
||||||
|
|
||||||
if options.list_dir:
|
if options.list_dir or options.list_deprecated:
|
||||||
# list all modules
|
# list modules
|
||||||
paths = utils.plugins.module_finder._get_paths()
|
paths = utils.plugins.module_finder._get_paths()
|
||||||
module_list = []
|
module_list = []
|
||||||
deprecated_list = []
|
|
||||||
module_aliases = {}
|
|
||||||
for path in paths:
|
for path in paths:
|
||||||
# os.system("ls -C %s" % (path))
|
|
||||||
if os.path.isdir(path):
|
if os.path.isdir(path):
|
||||||
for module in os.listdir(path):
|
for module in os.listdir(path):
|
||||||
if module.startswith('_') or any(module.endswith(x) for x in BLACKLIST_EXTS):
|
if any(module.endswith(x) for x in BLACKLIST_EXTS):
|
||||||
continue
|
continue
|
||||||
|
elif module.startswith('__'):
|
||||||
|
continue
|
||||||
|
elif module.startswith('_'):
|
||||||
|
fullpath = '/'.join([path,module])
|
||||||
|
if os.path.islink(fullpath): # avoids aliases
|
||||||
|
continue
|
||||||
|
|
||||||
|
module = os.path.splitext(module)[0] # removes the extension
|
||||||
module_list.append(module)
|
module_list.append(module)
|
||||||
|
|
||||||
pager(get_module_list_text(module_list))
|
pager(get_module_list_text(module_list))
|
||||||
|
|
Loading…
Reference in a new issue