diff options
Diffstat (limited to 'cli')
| -rw-r--r-- | cli/__init__.py | 3 | ||||
| -rw-r--r-- | cli/build.py | 11 | ||||
| -rw-r--r-- | cli/serve.py | 15 |
3 files changed, 27 insertions, 2 deletions
diff --git a/cli/__init__.py b/cli/__init__.py index c6f8f27..e7d137f 100644 --- a/cli/__init__.py +++ b/cli/__init__.py @@ -3,8 +3,9 @@ import os from .base import cli from .build import build +from .serve import serve -__all__ = [cli, build] +__all__ = [cli, build, serve] # ugly workaround to avoid build failures in Python 3.8 if "NETLIFY" not in os.environ: diff --git a/cli/build.py b/cli/build.py index 526e086..38874fe 100644 --- a/cli/build.py +++ b/cli/build.py @@ -1,3 +1,5 @@ +import click + from jinja2 import Environment, PackageLoader, select_autoescape from os import listdir, mkdir from pathlib import Path @@ -16,7 +18,8 @@ TEMPLATES = ["index.html"] @cli.command() -def build(): +@click.option("--verbose", "-v", is_flag=True) +def build(verbose): # copy static files if not BUILD_DIR.exists(): mkdir(BUILD_DIR) @@ -39,6 +42,12 @@ def build(): names = list(sorted(names, key=lambda x: x.domain)) candidates = list(sorted(candidates, key=lambda x: x.domain)) + if verbose: + names_str = [x.domain for x in names] + candidates_str = [x.domain for x in candidates] + print(f"Got {names_str=}") + print(f"Got {candidates_str=}") + def render_link(value, classes): name = unidecode(value.name).lower().split(" ") domain = unidecode(value.domain).replace(".", "") diff --git a/cli/serve.py b/cli/serve.py new file mode 100644 index 0000000..9910294 --- /dev/null +++ b/cli/serve.py @@ -0,0 +1,15 @@ +from http.server import HTTPServer, SimpleHTTPRequestHandler + +from .base import cli + + +@cli.command() +def serve(): + class BuildHTTPRequestHandler(SimpleHTTPRequestHandler): + def __init__(self, *args, **kwargs): + super().__init__(*args, directory="build", **kwargs) + + print("Local server running on http://localhost:8000") + server_address = ("", 8000) + httpd = HTTPServer(server_address, BuildHTTPRequestHandler) + httpd.serve_forever() |
