39 lines
778 B
Python
Executable File
39 lines
778 B
Python
Executable File
#!/usr/local/bin/python
|
|
|
|
from importlib import import_module
|
|
|
|
from click import argument, command
|
|
|
|
|
|
@command()
|
|
@argument("path")
|
|
def pyhelp(path: str):
|
|
"""
|
|
Print the object documentation from docstring.
|
|
|
|
:param path: The full path to the module, function or class.
|
|
"""
|
|
|
|
module_path = path.rsplit(".", 1)[0]
|
|
object_name = path.split(".")[-1]
|
|
|
|
try:
|
|
module = import_module(module_path)
|
|
except ModuleNotFoundError:
|
|
module = None
|
|
|
|
if module:
|
|
if module_path == object_name:
|
|
_object = module
|
|
else:
|
|
_object = getattr(module, object_name, None)
|
|
else:
|
|
_object = getattr(__builtins__, object_name, None)
|
|
|
|
if _object:
|
|
help(_object)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
pyhelp()
|