SRS/cli.py

56 lines
1.6 KiB
Python
Raw Normal View History

2022-04-21 17:50:24 +09:00
#! /usr/bin/env python
import argparse
import subprocess
import sys
import os
def build(args):
2022-04-21 19:23:36 +09:00
parser = argparse.ArgumentParser(description='Compiling the documentation', prog="cli.py build")
2022-04-21 17:50:24 +09:00
parser.add_argument('-v', '--verbose', action='store_true', help='verbose mode')
parser.add_argument('--update_issues', action='store_true', help='update issues')
2022-04-21 19:23:36 +09:00
parser.add_argument('--outDir', default="build", help='output directory')
2022-04-21 17:50:24 +09:00
args = parser.parse_args(args)
if args.verbose:
print("build start")
if args.update_issues:
if args.verbose:
print("get issues")
2022-04-21 19:23:36 +09:00
p = subprocess.run(["deno", "run", "-A","tools/getIssue.ts", "--path",os.path.join(args.outDir,"/issues.json")])
2022-04-21 17:50:24 +09:00
p.check_returncode()
if args.verbose:
print("build issues")
2022-04-21 19:23:36 +09:00
p = subprocess.run(["deno", "run", "-A","tools/printDocument.ts", "--issue_path", "./build/issues.json", "--outDir", args.outDir])
2022-04-21 17:50:24 +09:00
p.check_returncode()
def help(_args):
global commandList
print("subcommands:")
for command in commandList.keys():
print("\t", command)
commandList = {
'build': build,
'help': help
}
def main():
args = sys.argv
if len(args) < 2:
print("no subcommand", file=sys.stderr)
help(args)
return
_command = args[0]
subCommand = args[1]
if subCommand not in commandList:
print("Command not found", file=sys.stderr)
help(args)
sys.exit(1)
args = args[2:]
os.makedirs("build", exist_ok=True)
commandList[subCommand](args)
if __name__ == '__main__':
main()