mirror of
https://github.com/zensical/zensical.git
synced 2026-05-03 17:40:31 +00:00
Merge pull request #108 from zensical/fix/dev_addr
zensical:fix - allow to set dev_addr in configuration
This commit is contained in:
+1
-25
@@ -26,10 +26,6 @@ from __future__ import annotations
|
||||
import click
|
||||
import os
|
||||
import shutil
|
||||
import threading
|
||||
import time
|
||||
import webbrowser
|
||||
import urllib.request
|
||||
|
||||
from click import ClickException
|
||||
from zensical import build, serve, version
|
||||
@@ -40,21 +36,6 @@ from zensical import build, serve, version
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
|
||||
# Wait for the server to be available before opening the browser - we'll remove
|
||||
# this hack once the server can signal that it's ready for serving.
|
||||
def open_browser(url):
|
||||
def _open_browser(url):
|
||||
while True:
|
||||
try:
|
||||
with urllib.request.urlopen(url):
|
||||
webbrowser.open(url)
|
||||
break
|
||||
except Exception:
|
||||
time.sleep(1)
|
||||
|
||||
threading.Thread(target=_open_browser, args=(url,), daemon=True).start()
|
||||
|
||||
|
||||
@click.version_option(version=version(), message="%(version)s")
|
||||
@click.group()
|
||||
def cli():
|
||||
@@ -141,17 +122,12 @@ def execute_serve(config_file: str | None, **kwargs):
|
||||
break
|
||||
else:
|
||||
raise ClickException("No config file found in the current folder.")
|
||||
|
||||
# Obtain development server address and open in browser, if desired
|
||||
dev_addr = kwargs.get("dev_addr") or "localhost:8000"
|
||||
if kwargs.get("open", False):
|
||||
open_browser(f"http://{dev_addr}")
|
||||
if kwargs.get("strict", False):
|
||||
print("Warning: Strict mode is currently unsupported.")
|
||||
|
||||
# Build project in Rust runtime, calling back into Python when necessary,
|
||||
# e.g., to parse MkDocs configuration format or render Markdown
|
||||
serve(os.path.abspath(config_file), dev_addr)
|
||||
serve(os.path.abspath(config_file), kwargs)
|
||||
|
||||
|
||||
@cli.command(name="new")
|
||||
|
||||
Reference in New Issue
Block a user