diff --git a/mytools b/mytools index fc44975..806d67c 100755 --- a/mytools +++ b/mytools @@ -1,5 +1,6 @@ #!/usr/bin/env python3 # docstring=lists all tools and their docstrings +import argparse import os import os.path as path @@ -7,6 +8,8 @@ CFG = { "max_lines": 20, "offset": 20 } +SCRIPT_PATH = os.path.dirname(os.path.realpath(__file__)) + def parse_docstring(file_path, max_lines=CFG["max_lines"]): """ @@ -38,15 +41,14 @@ def offset(element, offset=CFG["offset"]): return " " * (offset - element_length) -def main(): +def list_tools(): """ lists all tools and their docstring from the same directory this sits in """ - script_path = os.path.dirname(os.path.realpath(__file__)) - list_dir = sorted(os.listdir(script_path)) + list_dir = sorted(os.listdir(SCRIPT_PATH)) for element in list_dir: - element_path = path.join(script_path, element) + element_path = path.join(SCRIPT_PATH, element) if path.isfile(element_path): print(element, end="") docstring = parse_docstring(element_path) @@ -55,5 +57,16 @@ def main(): print() +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("-p", "--path", help="output path to tools directory", action="store_true") + args = ap.parse_args() + + if args.path: + print(SCRIPT_PATH) + else: + list_tools() + + if __name__ == "__main__": main()