-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbcui
More file actions
executable file
·65 lines (54 loc) · 2.47 KB
/
Copy pathbcui
File metadata and controls
executable file
·65 lines (54 loc) · 2.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env python3
"""bcui - local browser UI for bash_common commands."""
import argparse
import os
import sys
import webbrowser
def main():
script_dir = os.path.dirname(os.path.abspath(__file__))
venv_python = os.path.join(script_dir, ".venv", "bin", "python")
if os.path.exists(venv_python) and os.path.abspath(sys.executable) != os.path.abspath(venv_python):
os.execv(venv_python, [venv_python, __file__, *sys.argv[1:]])
sys.path.insert(0, script_dir)
parser = argparse.ArgumentParser(
prog="bcui",
description="Start the bash_common local web UI.",
)
parser.add_argument("--host", default="127.0.0.1",
help="host to bind (default: 127.0.0.1)")
parser.add_argument("--allow-lan", action="store_true",
help="allow binding to a non-localhost address")
parser.add_argument("--port", default=8765, type=int,
help="port to bind (default: 8765)")
parser.add_argument("--cwd", default=os.getcwd(),
help="default working directory for commands")
parser.add_argument("--no-browser", action="store_true",
help="do not open a browser automatically")
parser.add_argument("--debug", action="store_true",
help="run Flask in debug mode")
args = parser.parse_args()
localhost_names = {"127.0.0.1", "localhost", "::1"}
if args.host not in localhost_names and not args.allow_lan:
print("Error: refusing to expose the command runner on a non-localhost address.")
print("Re-run with --allow-lan if you intentionally want LAN access.")
return 1
try:
from webui.app import create_app
except ModuleNotFoundError as exc:
if exc.name == "flask":
print("Error: Flask is not installed. Run 'bcinit' to install dependencies.")
print("Or install manually with: .venv/bin/python -m pip install -r requirements.txt")
return 1
raise
app = create_app(script_dir, os.path.abspath(args.cwd))
url = f"http://{args.host}:{args.port}"
print(f"BC UI running at {url}")
if args.host not in localhost_names:
print("Warning: BC UI can run local commands and is reachable from other machines.")
print("Press Ctrl-C to stop.")
if not args.no_browser:
webbrowser.open(url)
app.run(host=args.host, port=args.port, debug=args.debug)
return 0
if __name__ == "__main__":
sys.exit(main())