|
2 | 2 | import builtins |
3 | 3 | import json |
4 | 4 | import os |
| 5 | +from collections import OrderedDict |
5 | 6 | from csv import DictWriter |
6 | 7 | from functools import reduce |
7 | 8 | from hashlib import md5 |
|
11 | 12 | import click |
12 | 13 | import cloudinary |
13 | 14 | from jinja2 import Environment, FileSystemLoader |
14 | | - |
| 15 | +from docstring_parser import parse |
15 | 16 | from cloudinary_cli.defaults import logger, TEMPLATE_FOLDER |
16 | 17 |
|
17 | 18 | not_callable = ('is_appengine_sandbox', 'call_tags_api', 'call_context_api', 'call_cacheable_api', 'call_api', |
@@ -41,20 +42,25 @@ def is_builtin_class_instance(obj): |
41 | 42 |
|
42 | 43 |
|
43 | 44 | def get_help_str(module, block_list=(), allow_list=()): |
44 | | - funcs = list(filter( |
45 | | - lambda f: |
46 | | - callable(module.__dict__[f]) |
47 | | - and not is_builtin_class_instance(module.__dict__[f]) |
48 | | - and f[0].islower() |
49 | | - and (f not in block_list and block_list) |
50 | | - and (f in allow_list or not allow_list), |
51 | | - module.__dict__.keys())) |
52 | | - |
53 | | - funcs.sort() |
54 | | - |
55 | | - template = "{0:" + str(len(max(funcs, key=len)) + 1) + "}({1})" # Gets the maximal length of the functions' names |
56 | | - |
57 | | - return '\n'.join([template.format(f, ", ".join(list(signature(module.__dict__[f]).parameters))) for f in funcs]) |
| 45 | + funcs = {} |
| 46 | + for f in module.__dict__.keys(): |
| 47 | + if callable(module.__dict__[f]) \ |
| 48 | + and not is_builtin_class_instance(module.__dict__[f]) \ |
| 49 | + and f[0].islower() \ |
| 50 | + and (f not in block_list and block_list) \ |
| 51 | + and (f in allow_list or not allow_list): |
| 52 | + funcs[f] = {"params": ", ".join(signature(module.__dict__[f]).parameters), |
| 53 | + "desc": parse(module.__dict__[f].__doc__).short_description} |
| 54 | + |
| 55 | + funcs = OrderedDict(sorted(funcs.items())) |
| 56 | + |
| 57 | + template = "{0:" + str(len(max(funcs.keys(), key=len)) + 1) + "}({1:30} {2}" # Gets the max length of the functions' names |
| 58 | + |
| 59 | + return '\n'.join( |
| 60 | + [ |
| 61 | + template.format(f, p["params"] + ")", p["desc"] if p["desc"] is not None else "") |
| 62 | + for f, p in funcs.items() |
| 63 | + ]) |
58 | 64 |
|
59 | 65 |
|
60 | 66 | def print_api_help(api, block_list=not_callable, allow_list=()): |
|
0 commit comments