Skip to content

Commit

Permalink
Merge pull request #516 from Lucas-C/serve-open-browser
Browse files Browse the repository at this point in the history
sigal serve --browser : open in your default browser
  • Loading branch information
saimn committed Apr 30, 2024
2 parents eea2c56 + cf223ce commit cf15fcc
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/sigal/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import socketserver
import sys
import time
import webbrowser
from http import server

import click
Expand Down Expand Up @@ -227,7 +228,8 @@ def format_stats(_type):
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
Expand All @@ -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()
Expand Down

0 comments on commit cf15fcc

Please sign in to comment.