Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sigal serve --browser : open in your default browser #516

Merged
merged 1 commit into from
Apr 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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 @@
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}/")

Check warning on line 259 in src/sigal/__main__.py

View check run for this annotation

Codecov / codecov/patch

src/sigal/__main__.py#L258-L259

Added lines #L258 - L259 were not covered by tests

try:
httpd.allow_reuse_address = True
httpd.server_bind()
Expand Down