vite/cli.py (view raw)
1import argparse
2import sys
3from vite import vite
4from huepy import *
5from vite import __version__
6
7
8def main():
9 desc = green("A simple and minimal static site generator.")
10 usage = lightblue("vite") + " [options]"
11 parser = argparse.ArgumentParser(description=desc, usage=usage)
12 parser.add_argument(
13 "-v",
14 "--version",
15 action="version",
16 version="{version}".format(version=__version__),
17 )
18 sp = parser.add_subparsers(
19 dest="cmd", help="Options to help create, build and serve your project."
20 )
21 # for cmd in ['init', 'new']:
22 sp_init = sp.add_parser("init")
23 sp_new = sp.add_parser("new")
24 for cmd in ["build", "serve"]:
25 sp.add_parser(cmd)
26 sp_init.add_argument("path")
27 sp_new.add_argument("path")
28 args = parser.parse_args()
29
30 if len(sys.argv) == 1:
31 parser.print_help()
32 sys.exit(1)
33 elif args.cmd == "init":
34 if args.path:
35 vite.create_project(args.path)
36 else:
37 parser.print_help()
38 elif args.cmd == "new":
39 if args.path:
40 vite.import_config()
41 vite.create_path(args.path)
42 else:
43 parser.print_help()
44 elif args.cmd == "build":
45 vite.import_config()
46 vite.builder()
47 elif args.cmd == "serve":
48 vite.import_config()
49 vite.server()
50 else:
51 parser.print_help()