-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcoldoc
executable file
·82 lines (67 loc) · 1.93 KB
/
coldoc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env python
from __future__ import print_function
import argparse
import glob
import re
PURPLE = '\033[95m'
CYAN = '\033[96m'
DARKCYAN = '\033[36m'
BLUE = '\033[94m'
GREEN = '\033[92m'
YELLOW = '\033[93m'
RED = '\033[91m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'
END = '\033[0m'
def pretty_print(colors, text, cr=True):
if type(colors) == list:
pre = ''.join(colors)
else:
pre = colors
if cr:
print(pre + text + END)
else:
print(pre + text + END, end="")
def pretty_format(colors, text):
if type(colors) == list:
pre = ''.join(colors)
else:
pre = colors
return(pre + text + END)
def main():
parser = argparse.ArgumentParser(
description='Generates documentation for Meteor Collections.'
)
parser.add_argument(
'source',
help='The glob-pattern file[s] (js) to read from',
nargs='?',
default=''
)
args = parser.parse_args()
files = glob.glob(args.source)
if files == []:
files = glob.glob('./lib/collections/' + args.source + "*")
for f in files:
content = open(f, 'r').read().split('*/')[0][3:].split('\n')
# print the title of the file
pretty_print([BOLD, GREEN], f.split('/')[-1][:-3])
# print the help text
for line in content:
line = "\t" + line
if line != "" and line[-1] == ":":
pretty_print([PURPLE, UNDERLINE], line)
elif re.search('(\w*) \((.*)\): (.*)', line):
groups = re.search('(\w*) \((.*)\): (.*)', line)
print('\t\t', end="")
print(
pretty_format(YELLOW, groups.group(1)),
"(",
pretty_format(DARKCYAN, groups.group(2)),
")",
groups.group(3)
)
else:
print(line)
if __name__ == "__main__":
main()