Skip to content

Commit

Permalink
Add some docstrings.
Browse files Browse the repository at this point in the history
  • Loading branch information
Isaak-Malers committed Feb 23, 2024
1 parent 1af388b commit b81b1c9
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions CliFunction.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,9 @@ def add_target(self, to_add):
self.targets.append(to_add)

def function_help(self, func, pad: str = "") -> str:
"""
Given a function, and a "pad" returns the help string for the function, with indentation equal to the padding.
"""
header = f"{pad}{func.__name__} -- {func.__doc__.strip()}"
# pylint: disable=unused-variable
names, varargs, varkw, defaults, kwonlyargs, kwonlydefaults, annotations = inspect.getfullargspec(func)
Expand All @@ -225,6 +228,9 @@ def function_help(self, func, pad: str = "") -> str:
return header + f"\n\t{pad}" + args_string

def man(self, pad: str = ""):
"""
Returns the manuel for this instance of a Cli Function object. Padding allows for indenting recursively nested CLI function objects.
"""
header = f"{pad}{self.headingName}"
function_docs = []
for func in self.targets:
Expand All @@ -237,11 +243,18 @@ def man(self, pad: str = ""):


def cli_function(target_to_add):
"""
Decorates a function, and at import time registers that function with the CLI tool.
This allows the cli function to know what functions are available and should be exposed.
"""
targets.add_target(target_to_add)
return target_to_add


def cli(args: [str] = None):
"""
Runs the CLI tool for the current file
"""
if args is None:
args = sys.argv

Expand Down

0 comments on commit b81b1c9

Please sign in to comment.