Commit 700e9bbf authored by Joseph Walton-Rivers's avatar Joseph Walton-Rivers 🐦

make cli work with serve command

parent bcba9a9f
Pipeline #1274 failed with stages
in 43 seconds
......@@ -6,4 +6,4 @@ recursive-include test *.html
recursive-include test *.py
exclude .gitlab-ci.yml
prune docs/
prune docs
#! /usr/bin/env python3
import argparse
from j2static.webserver import serve
_options = {
'generate': lambda: print("generate"),
'serve': serve
}
def main():
"""Main Entrypoint for CLI"""
parser = argparse.ArgumentParser("static site generator.")
parser.add_argument('action', choices=_options.keys())
args = parser.parse_args()
chosen_action = _options[args.action]
chosen_action()
if __name__ == "__main__":
main()
......@@ -13,7 +13,3 @@ env = Environment(
def render(name):
template = env.get_template(name)
return template.render()
def main():
print("test")
......@@ -6,7 +6,7 @@
# in real time.
##
import main
import j2static.main
from http.server import BaseHTTPRequestHandler
import socketserver
......@@ -21,11 +21,12 @@ class TemplateHTTPServer(BaseHTTPRequestHandler):
self.send_header('Content-type', 'text/html')
self.end_headers()
data = main.render('index.html')
data = j2static.main.render('index.html')
self.wfile.write(data.encode())
Handler = TemplateHTTPServer
httpd = socketserver.TCPServer(("", PORT), Handler)
httpd.serve_forever()
httpd.close()
def serve():
Handler = TemplateHTTPServer
httpd = socketserver.TCPServer(("", PORT), Handler)
httpd.serve_forever()
httpd.close()
......@@ -32,7 +32,7 @@ setup(
package_dir={'j2static': 'j2static'},
entry_points={
'console_scripts': [
'j2static=j2static:main',
'j2static=j2static.cli:main',
],
},
)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment