open_command.py¶
clew/wiki/open_command.py
`clew wiki open` — one click into a repository's wiki (round 3, P5a).
open_main
int clew.wiki.open_command.open_main(list[str] argv)
Open a repository's wiki: the running hub's page, else a freshly built static site.
Source · 30 lines
def open_main(argv: list[str]) -> int:
"""@brief Entry point. @return Exit status."""
from ..mcp_server.state import state_home, target_for
parser = argparse.ArgumentParser(prog="clew wiki open")
parser.add_argument("--repo-root", help="the repository (default: the current directory)")
parser.add_argument("--no-browser", action="store_true", help="print the URL only")
args = parser.parse_args(argv)
repo = Path(args.repo_root or Path.cwd()).resolve()
home = state_home()
target = target_for(repo, home)
hub = _live_hub(home)
if hub is not None:
base, _, query = hub.partition("?")
url = f"{base.rstrip('/')}/r/{target.slug}/" + (f"?{query}" if query else "")
else:
db = Path(target.db_path)
try:
_ensure_index(repo, db)
html = build_wiki(repo, db, db.parent / "wiki")
except (ValueError, OSError) as exc:
sys.stderr.write(f"clew wiki open: {exc}\n")
return 1
url = (html / "index.html").as_uri()
sys.stdout.write(url + "\n")
if not args.no_browser:
webbrowser.open(url)
return 0