added option to list path to mytools dir
This commit is contained in:
parent
eb54e1b518
commit
c7d98f6d30
1 changed files with 17 additions and 4 deletions
21
mytools
21
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()
|
||||
|
|
Loading…
Add table
Reference in a new issue