Merge pull request #516 from Lucas-C/serve-open-browser

sigal serve --browser : open in your default browser
This commit is contained in:
Simon Conseil
2024-04-30 19:21:01 +02:00
committed by GitHub

View File

@@ -25,6 +25,7 @@ import pathlib
import socketserver
import sys
import time
import webbrowser
from http import server
import click
@@ -227,7 +228,8 @@ def build(
show_default=True,
help="Configuration file",
)
def serve(destination, port, config):
@option("-b", "--browser", is_flag=True, help="Open in your default browser")
def serve(destination, port, config, browser):
"""Run a simple web server."""
if os.path.exists(destination):
pass
@@ -253,6 +255,9 @@ def serve(destination, port, config):
httpd = socketserver.TCPServer(("", port), Handler, False)
print(f" * Running on http://127.0.0.1:{port}/")
if browser:
webbrowser.open(f"http://127.0.0.1:{port}/")
try:
httpd.allow_reuse_address = True
httpd.server_bind()