主函数
()
| 178 | |
| 179 | |
| 180 | def main(): |
| 181 | """主函数""" |
| 182 | import argparse |
| 183 | import os |
| 184 | |
| 185 | parser = argparse.ArgumentParser(description="OpenAI/Codex CLI 自动注册系统 Web UI") |
| 186 | parser.add_argument("--host", help="监听主机 (也可通过 APP_HOST / WEBUI_HOST 环境变量设置)") |
| 187 | parser.add_argument("--port", type=int, help="监听端口 (也可通过 APP_PORT / WEBUI_PORT 环境变量设置)") |
| 188 | parser.add_argument("--debug", action="store_true", help="启用调试模式 (也可通过 DEBUG=1 环境变量设置)") |
| 189 | parser.add_argument("--reload", action="store_true", help="启用热重载") |
| 190 | parser.add_argument("--log-level", help="日志级别 (也可通过 LOG_LEVEL 环境变量设置)") |
| 191 | parser.add_argument("--access-password", help="Web UI 访问密钥 (也可通过 APP_ACCESS_PASSWORD / WEBUI_ACCESS_PASSWORD 环境变量设置)") |
| 192 | args = parser.parse_args() |
| 193 | |
| 194 | # 更新配置 |
| 195 | from src.config.settings import update_settings |
| 196 | |
| 197 | updates = {} |
| 198 | |
| 199 | # 优先使用命令行参数,如果没有则尝试从环境变量获取 |
| 200 | host = args.host or os.environ.get("APP_HOST") or os.environ.get("WEBUI_HOST") |
| 201 | if host: |
| 202 | updates["webui_host"] = host |
| 203 | |
| 204 | port = args.port or os.environ.get("APP_PORT") or os.environ.get("WEBUI_PORT") |
| 205 | if port: |
| 206 | updates["webui_port"] = int(port) |
| 207 | |
| 208 | debug = args.debug or os.environ.get("DEBUG", "").lower() in ("1", "true", "yes") |
| 209 | if debug: |
| 210 | updates["debug"] = debug |
| 211 | |
| 212 | log_level = args.log_level or os.environ.get("LOG_LEVEL") |
| 213 | if log_level: |
| 214 | updates["log_level"] = log_level |
| 215 | |
| 216 | access_password = args.access_password or os.environ.get("APP_ACCESS_PASSWORD") or os.environ.get("WEBUI_ACCESS_PASSWORD") |
| 217 | if access_password: |
| 218 | updates["webui_access_password"] = access_password |
| 219 | |
| 220 | if updates: |
| 221 | update_settings(**updates) |
| 222 | |
| 223 | # 启动 Web UI |
| 224 | start_webui() |
| 225 | |
| 226 | |
| 227 | if __name__ == "__main__": |
no test coverage detected