-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtaph.py
executable file
·76 lines (64 loc) · 3.19 KB
/
taph.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
#!/usr/bin/env python3
# taph: The Antora Project Helper.
# For more information, see: https://github.com/internetisaiah/taph.
import subprocess
import argparse
from scripts.beautify import main as beautify
from scripts.minify import main as minify
from scripts.csv import main as csv
from scripts.edit import main as edit
from scripts.antora import main as antora
# Dictionary mapping optional arguments to corresponding functions in './scripts'.
APH_SCRIPTS = {
'beautify': beautify,
'minify': minify,
'csv': csv,
'edit': edit,
'antora': antora
}
# The Antora project's root directory.
PROJECT_ROOT = subprocess.check_output(['git', 'rev-parse', '--show-toplevel']).decode('utf-8').strip()
# APH argument parser using Python's 'argparse'.
def main():
parser = argparse.ArgumentParser(description="Manage your Antora project with APH.")
# Argument(s)
parser.add_argument("directory",
nargs='?',
default=PROJECT_ROOT,
help="your antora project's root directory "
"(default: the value of 'git rev-parse --show-toplevel')")
parser.add_argument("-q", "--quiet",
help="suppress all 'taph' notifications in the terminal",
action="store_true")
parser.add_argument("-a", "--antora",
help="run 'antora' for all antora playbooks in the project",
action="store_true")
parser.add_argument("-b", "--beautify",
help="beautify your logs by creating an asciidoc table containing cross-references "
"to each file which can be opened from your ide's preview window",
action="store_true")
parser.add_argument("-m", "--minify",
help="copy all css content from your ui bundle directory into a single, minified file: 'site.css'",
action="store_true")
parser.add_argument("-c", "--csv",
help="generate a '.csv' file containing the urls for the documents in your project's "
"output directory which can be imported later into a spreadsheet",
action="store_true")
parser.add_argument("-e", "--edit",
help="make the following edits to each '.adoc' file in './docs/modules/': "
"fix newlines, fix urls, "
"add modules to asciidoc attributes,"
"add missing spaces after periods",
action="store_true")
args = parser.parse_args()
# Check the given optional argument(s) and run the matching function(s) from the 'aph_scripts' dictionary.
for arg, script in APH_SCRIPTS.items():
if getattr(args, arg):
script()
if not args.quiet:
print(f"'{arg}' ran successfully.")
# If no optional argument(s) given, notify user.
if not any([getattr(args, key) for key in APH_SCRIPTS.keys()]):
print("At least one optional argument is required for 'taph'. For more information, see '--help'.")
if __name__ == "__main__":
main()