sigal serve --browser : open in your default browser
This commit is contained in:
@@ -25,6 +25,7 @@ import pathlib
|
|||||||
import socketserver
|
import socketserver
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
|
import webbrowser
|
||||||
from http import server
|
from http import server
|
||||||
|
|
||||||
import click
|
import click
|
||||||
@@ -227,7 +228,8 @@ def build(
|
|||||||
show_default=True,
|
show_default=True,
|
||||||
help="Configuration file",
|
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."""
|
"""Run a simple web server."""
|
||||||
if os.path.exists(destination):
|
if os.path.exists(destination):
|
||||||
pass
|
pass
|
||||||
@@ -253,6 +255,9 @@ def serve(destination, port, config):
|
|||||||
httpd = socketserver.TCPServer(("", port), Handler, False)
|
httpd = socketserver.TCPServer(("", port), Handler, False)
|
||||||
print(f" * Running on http://127.0.0.1:{port}/")
|
print(f" * Running on http://127.0.0.1:{port}/")
|
||||||
|
|
||||||
|
if browser:
|
||||||
|
webbrowser.open(f"http://127.0.0.1:{port}/")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
httpd.allow_reuse_address = True
|
httpd.allow_reuse_address = True
|
||||||
httpd.server_bind()
|
httpd.server_bind()
|
||||||
|
|||||||
Reference in New Issue
Block a user