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.

clew/wiki/open_command.py:31

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

Activity · 25 steps
lines 33–33from ..mcp_server.state import state_home, target_forlines 35–35parser = argparse.ArgumentParser(prog="clew wiki open")lines 36–36parser.add_argument("--repo-root", help="the repository (default: the current directory)")lines 37–37parser.add_argument("--no-browser", action="store_true", help="print the URL only")lines 38–38args = parser.parse_args(argv)lines 39–39repo = Path(args.repo_root or Path.cwd()).resolve()lines 40–40home = state_home()lines 41–41target = target_for(repo, home)lines 42–42hub = _live_hub(home)lines 43–43◇ if hub is not Nonelines 44–44base, _, query = hub.partition("?")lines 45–45url = f"{base.rstrip('/')}/r/{target.slug}/" + (f"?{query}" if query else "")lines 46–46elselines 47–47db = Path(target.db_path)lines 48–48trylines 49–49_ensure_index(repo, db)lines 50–50html = build_wiki(repo, db, db.parent / "wiki")lines 51–51except (ValueError, OSError) as exclines 52–52sys.stderr.write(f"clew wiki open: {exc}\n")lines 53–53return 1lines 54–54url = (html / "index.html").as_uri()lines 55–55sys.stdout.write(url + "\n")lines 56–56◇ if not args.no_browserlines 57–57webbrowser.open(url)lines 58–58return 0

Requirements

REQ-DDB-WIKI-037