forked from canonical/documentation-builder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.py
168 lines (155 loc) · 4.55 KB
/
cli.py
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# Core modules
import argparse
import sys
import pkg_resources
# Local modules
from .builder import Builder
def parse_arguments(arguments):
"""
Parse command-line options for documentation-parser command-line script
"""
parser = argparse.ArgumentParser(
description=(
"A tool to build documentation HTML files from markdown files, "
"either from a local directory or a remote repository."
)
)
parser.add_argument(
'--base-directory',
help=(
"The base path for the documentation repository "
"(defaults to current directory)"
)
)
parser.add_argument(
'--source-folder',
help=(
"Path inside the base directory to the folder containing "
"the markdown source files (default: .)"
)
)
parser.add_argument(
'--media-path',
help=(
"Path to the folder containing media files relative to "
"the current directory "
"(defaults to a 'media' folder inside the source folder)"
)
)
parser.add_argument(
'--output-path',
help="Destination path for the built HTML files (default: ./build)"
)
parser.add_argument(
'--output-media-path',
help=(
"Where to put media files "
"(defaults to a 'media' folder inside the output directory)"
)
)
parser.add_argument(
'--template-path',
help=(
"Path to an alternate wrapping template for the built HTML files "
"(defaults to using the built-in template)"
)
)
parser.add_argument(
'--site-root',
help=(
"A URL path to the root of the site, for use in the 'home' "
"link in the template (defaults to none)"
)
)
parser.add_argument(
'--media-url',
help=(
"Override prefix for linking to media inside the built HTML files "
"(defaults to using relative paths, e.g.: ../media)"
)
)
parser.add_argument(
'--tag-manager-code',
help=(
"If you supply a tag manager code, the default template will "
"render Google tag manager snippets into the built HTML."
)
)
parser.add_argument(
'--force',
action="store_true",
help=("Rebuild all files (assume all files have changed)")
)
parser.add_argument(
'--build-version-branches',
action='store_true',
help=(
"Build each branch mentioned in the `versions` file into a "
"subfolder"
)
)
parser.add_argument(
'--search-url',
help=(
"The URL endpoint for performing searches from the header. "
"The header search field will only be included if this is "
"provided."
)
)
parser.add_argument(
'--search-placeholder',
help=(
"Placeholder text for including in the header search field. "
"Default: 'Search documentation'."
)
)
parser.add_argument(
'--search-domain',
dest='search_domains',
action='append',
help=(
"Pass this 'domain' query parameter along with the search "
"string when performing searches."
)
)
parser.add_argument(
'--no-link-extensions',
action='store_true',
help="Don't include '.html' extension in internal links"
)
parser.add_argument(
'--no-cleanup',
action='store_true',
help="Don't clean up temporary directory after cloning repository"
)
parser.add_argument(
'--quiet',
action='store_true',
help="Suppress output"
)
parser.add_argument(
'--version',
action='store_true',
help="Show the currently installed version of documentation-builder."
)
arguments = vars(parser.parse_args(arguments))
if arguments['version']:
print(
pkg_resources.get_distribution(
"ubuntudesign.documentation_builder"
).version
)
sys.exit()
else:
del arguments['version']
# Return only defined arguments
return {name: value for name, value in arguments.items() if value}
def main(system_arguments):
"""
The starting point for the documentation-parser.
Intended to be run through the command-line.
"""
arguments = parse_arguments(system_arguments)
Builder(**arguments)
if __name__ == "__main__":
main(sys.argv[1:])