From cf223ce9e16ef907ce95f398e13a553a80e8628e Mon Sep 17 00:00:00 2001 From: "Cimon Lucas (LCM)" Date: Tue, 30 Apr 2024 08:51:39 +0200 Subject: [PATCH] sigal serve --browser : open in your default browser --- src/sigal/__main__.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/sigal/__main__.py b/src/sigal/__main__.py index 3053451..35c3934 100644 --- a/src/sigal/__main__.py +++ b/src/sigal/__main__.py @@ -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()