sigal serve --browser : open in your default browser

This commit is contained in:
Cimon Lucas (LCM)
2024-04-30 08:51:39 +02:00
parent eea2c56f9b
commit cf223ce9e1

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()