Skip to content

Commit 7fed0ba

Browse files
Improve API documentation
1 parent 13d2d82 commit 7fed0ba

File tree

3 files changed

+24
-16
lines changed

3 files changed

+24
-16
lines changed

cloudinary_cli/utils/utils.py

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import builtins
33
import json
44
import os
5+
from collections import OrderedDict
56
from csv import DictWriter
67
from functools import reduce
78
from hashlib import md5
@@ -11,7 +12,7 @@
1112
import click
1213
import cloudinary
1314
from jinja2 import Environment, FileSystemLoader
14-
15+
from docstring_parser import parse
1516
from cloudinary_cli.defaults import logger, TEMPLATE_FOLDER
1617

1718
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):
4142

4243

4344
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+
])
5864

5965

6066
def print_api_help(api, block_list=not_callable, allow_list=()):

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ jinja2
44
click
55
click-log
66
requests
7+
docstring-parser

setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@
4141
"jinja2",
4242
"click",
4343
"click-log",
44-
"requests"
44+
"requests",
45+
"docstring-parser"
4546
],
4647
include_package_data=True,
4748
zip_safe=False

0 commit comments

Comments
 (0)