Skip to content

Commit f6a3d1c

Browse files
committed
feat(cli): port complete cli package changes, .env.example, and astrbot_paths from dev branch
1 parent b749f62 commit f6a3d1c

20 files changed

+2131
-283
lines changed

.env.example

Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
# ==========================================
2+
# AstrBot Instance Configuration: ${INSTANCE_NAME}
3+
# AstrBot 实例配置文件:${INSTANCE_NAME}
4+
# ==========================================
5+
# 将此文件复制为 .env 并根据需要修改。
6+
# Copy this file to .env and modify as needed.
7+
# 注意:在此处设置的变量将覆盖默认配置。
8+
# Note: Variables set here override application defaults.
9+
10+
# ------------------------------------------
11+
# 实例标识 / Instance Identity
12+
# ------------------------------------------
13+
14+
# 实例名称(用于日志和服务名)
15+
# Instance name (used in logs/service names)
16+
INSTANCE_NAME="${INSTANCE_NAME}"
17+
18+
# ------------------------------------------
19+
# 核心配置 / Core Configuration
20+
# ------------------------------------------
21+
22+
# AstrBot 根目录路径
23+
# AstrBot root directory path
24+
# 默认 Default: 当前工作目录,桌面客户端为 ~/.astrbot,服务器为 /var/lib/astrbot/<instance>/
25+
# 示例 Example: /var/lib/astrbot/mybot
26+
ASTRBOT_ROOT="${ASTRBOT_ROOT}"
27+
28+
# 日志等级
29+
# Log level
30+
# 可选值 Values: DEBUG, INFO, WARNING, ERROR, CRITICAL
31+
# 默认 Default: INFO
32+
# ASTRBOT_LOG_LEVEL=INFO
33+
34+
# 启用插件热重载(开发时有用)
35+
# Enable plugin hot reload (useful for development)
36+
# 可选值 Values: 0 (禁用 disabled), 1 (启用 enabled)
37+
# 默认 Default: 0
38+
# ASTRBOT_RELOAD=0
39+
40+
# 禁用匿名使用统计
41+
# Disable anonymous usage statistics
42+
# 可选值 Values: 0 (启用统计 enabled), 1 (禁用统计 disabled)
43+
# 默认 Default: 0
44+
ASTRBOT_DISABLE_METRICS=0
45+
46+
# 覆盖 Python 可执行文件路径(用于本地代码执行功能)
47+
# Override Python executable path (for local code execution)
48+
# 示例 Example: /usr/bin/python3, /home/user/.pyenv/shims/python
49+
# PYTHON=/usr/bin/python3
50+
51+
# 启用演示模式(可能限制部分功能)
52+
# Enable demo mode (may restrict certain features)
53+
# 可选值 Values: True, False
54+
# 默认 Default: False
55+
# DEMO_MODE=False
56+
57+
# 启用测试模式(影响日志和部分行为)
58+
# Enable testing mode (affects logging and behavior)
59+
# 可选值 Values: True, False
60+
# 默认 Default: False
61+
# TESTING=False
62+
63+
# 标记:是否通过桌面客户端执行(主要用于内部)
64+
# Flag: running via desktop client (internal use)
65+
# 可选值 Values: 0, 1
66+
# ASTRBOT_DESKTOP_CLIENT=0
67+
68+
# 标记:是否通过 systemd 服务执行
69+
# Flag: running via systemd service
70+
# 可选值 Values: 0, 1
71+
ASTRBOT_SYSTEMD=1
72+
73+
# ------------------------------------------
74+
# 管理面板配置 / Dashboard Configuration
75+
# ------------------------------------------
76+
77+
# 启用或禁用 WebUI 管理面板
78+
# Enable or disable WebUI dashboard
79+
# 可选值 Values: True, False
80+
# 默认 Default: True
81+
ASTRBOT_DASHBOARD_ENABLE=True
82+
83+
# 允许跨域请求的来源域名(多个用逗号分隔,允许所有则用 *)
84+
# Allowed CORS origins for WebUI dashboard (comma-separated, or * for all)
85+
# 示例 Example: https://dash.astrbot.men
86+
# 默认 Default: *
87+
# ASTRBOT_CORS_ALLOW_ORIGIN="*"
88+
89+
# ------------------------------------------
90+
# 国际化配置 / Internationalization Configuration
91+
# ------------------------------------------
92+
93+
# CLI 界面语言
94+
# CLI interface language
95+
# 可选值 Values: zh (中文), en (英文)
96+
# 默认 Default: zh (跟随系统 locale / follows system locale)
97+
# ASTRBOT_CLI_LANG=zh
98+
99+
# ------------------------------------------
100+
# 网络配置 / Network Configuration
101+
# ------------------------------------------
102+
103+
# API 绑定主机
104+
# API bind host
105+
# 示例 Example: 0.0.0.0 (所有接口 all interfaces), 127.0.0.1 (仅本地 localhost only)
106+
ASTRBOT_HOST="${ASTRBOT_HOST}"
107+
108+
# API 绑定端口
109+
# API bind port
110+
# 示例 Example: 3000, 6185, 8080
111+
ASTRBOT_PORT="${ASTRBOT_PORT}"
112+
113+
# 是否为 API 启用 SSL/TLS
114+
# Enable SSL/TLS for API
115+
# 可选值 Values: true, false
116+
# 默认 Default: false
117+
ASTRBOT_SSL_ENABLE=false
118+
119+
# SSL 证书路径(PEM 格式)
120+
# SSL certificate path (PEM format)
121+
# 示例 Example: /etc/astrbot/certs/myinstance/fullchain.pem
122+
ASTRBOT_SSL_CERT=""
123+
124+
# SSL 私钥路径(PEM 格式)
125+
# SSL private key path (PEM format)
126+
# 示例 Example: /etc/astrbot/certs/myinstance/privkey.pem
127+
ASTRBOT_SSL_KEY=""
128+
129+
# SSL CA 证书链路径(可选,用于客户端验证)
130+
# SSL CA certificates bundle (optional, for client verification)
131+
# 示例 Example: /etc/ssl/certs/ca-certificates.crt
132+
ASTRBOT_SSL_CA_CERTS=""
133+
134+
# ------------------------------------------
135+
# 代理配置 / Proxy Configuration
136+
# ------------------------------------------
137+
138+
# HTTP 代理地址
139+
# HTTP proxy URL
140+
# 示例 Example: http://127.0.0.1:7890, socks5://127.0.0.1:1080
141+
# http_proxy=
142+
143+
# HTTPS 代理地址
144+
# HTTPS proxy URL
145+
# 示例 Example: http://127.0.0.1:7890, socks5://127.0.0.1:1080
146+
# https_proxy=
147+
148+
# 不走代理的主机列表(逗号分隔)
149+
# Hosts to bypass proxy (comma-separated)
150+
# 示例 Example: localhost,127.0.0.1,192.168.0.0/16,.local
151+
# no_proxy=localhost,127.0.0.1
152+
153+
# ------------------------------------------
154+
# 第三方集成 / Third-party Integrations
155+
# ------------------------------------------
156+
157+
# 阿里云 DashScope API 密钥(用于 Rerank 服务)
158+
# Alibaba DashScope API Key (for Rerank service)
159+
# 获取地址 Get from: https://dashscope.console.aliyun.com/
160+
# 示例 Example: sk-xxxxxxxxxxxx
161+
# DASHSCOPE_API_KEY=
162+
163+
# Coze 集成
164+
# Coze integration
165+
# 获取地址 Get from: https://www.coze.com/
166+
# COZE_API_KEY=
167+
# COZE_BOT_ID=
168+
169+
# 计算机控制相关的数据目录(用于截图/文件存储)
170+
# Computer control data directory (for screenshots/file storage)
171+
# 示例 Example: /var/lib/astrbot/bay_data
172+
# BAY_DATA_DIR=
173+
174+
# ------------------------------------------
175+
# 平台特定配置 / Platform-specific Configuration
176+
# ------------------------------------------
177+
178+
# QQ 官方机器人测试模式开关
179+
# QQ official bot test mode
180+
# 可选值 Values: on, off
181+
# 默认 Default: off
182+
# TEST_MODE=off
183+
184+
# End of template / 模板结束

astrbot/cli/__init__.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,10 @@
1-
__version__ = "4.22.2"
1+
from importlib import metadata
2+
3+
try:
4+
__version__ = metadata.version("AstrBot")
5+
except metadata.PackageNotFoundError:
6+
__version__ = "unknown"
7+
8+
from astrbot.cli.__main__ import cli
9+
10+
__all__ = ["cli"]

astrbot/cli/__main__.py

Lines changed: 70 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
"""AstrBot CLI entry point"""
22

3+
import os
34
import sys
45

56
import click
7+
from click.shell_completion import get_completion_class
68

79
from . import __version__
8-
from .commands import conf, init, plug, run
10+
from .commands import bk, conf, init, plug, run, uninstall
11+
from .i18n import t
912

1013
logo_tmpl = r"""
1114
___ _______.___________..______ .______ ______ .___________.
@@ -20,29 +23,55 @@
2023
@click.group()
2124
@click.version_option(__version__, prog_name="AstrBot")
2225
def cli() -> None:
23-
"""The AstrBot CLI"""
26+
"""Astrbot
27+
Agentic IM Chatbot infrastructure that integrates lots of IM platforms, LLMs, plugins and AI feature, and can be your openclaw alternative. ✨
28+
"""
2429
click.echo(logo_tmpl)
25-
click.echo("Welcome to AstrBot CLI!")
26-
click.echo(f"AstrBot CLI version: {__version__}")
30+
click.echo(t("cli_welcome"))
31+
click.echo(t("cli_version", version=__version__))
2732

2833

2934
@click.command()
3035
@click.argument("command_name", required=False, type=str)
31-
def help(command_name: str | None) -> None:
36+
@click.option(
37+
"--all", "-a", is_flag=True, help="Show help for all commands recursively."
38+
)
39+
def help(command_name: str | None, all: bool) -> None:
3240
"""Display help information for commands
3341
3442
If COMMAND_NAME is provided, display detailed help for that command.
3543
Otherwise, display general help information.
3644
"""
3745
ctx = click.get_current_context()
46+
47+
if all:
48+
49+
def print_recursive_help(command, parent_ctx):
50+
name = command.name
51+
if parent_ctx is None:
52+
name = "astrbot"
53+
54+
cmd_ctx = click.Context(command, info_name=name, parent=parent_ctx)
55+
click.echo(command.get_help(cmd_ctx))
56+
click.echo("\n" + "-" * 50 + "\n")
57+
58+
if isinstance(command, click.Group):
59+
for subcommand in command.commands.values():
60+
print_recursive_help(subcommand, cmd_ctx)
61+
62+
print_recursive_help(cli, None)
63+
return
64+
3865
if command_name:
3966
# Find the specified command
4067
command = cli.get_command(ctx, command_name)
4168
if command:
4269
# Display help for the specific command
43-
click.echo(command.get_help(ctx))
70+
parent = ctx.parent if ctx.parent else ctx
71+
cmd_ctx = click.Context(command, info_name=command.name, parent=parent)
72+
click.echo(command.get_help(cmd_ctx))
4473
else:
45-
click.echo(f"Unknown command: {command_name}")
74+
click.echo(t("cli_unknown_command", command=command_name))
4675
sys.exit(1)
4776
else:
4877
# Display general help information
@@ -54,6 +83,40 @@ def help(command_name: str | None) -> None:
5483
cli.add_command(help)
5584
cli.add_command(plug)
5685
cli.add_command(conf)
86+
cli.add_command(uninstall)
87+
cli.add_command(bk)
88+
89+
90+
@click.command()
91+
@click.argument("shell", required=False, type=click.Choice(["bash", "zsh", "fish"]))
92+
def completion(shell: str | None) -> None:
93+
"""Generate shell completion script"""
94+
if shell is None:
95+
shell_path = os.environ.get("SHELL", "")
96+
if "zsh" in shell_path:
97+
shell = "zsh"
98+
elif "bash" in shell_path:
99+
shell = "bash"
100+
elif "fish" in shell_path:
101+
shell = "fish"
102+
else:
103+
click.echo(
104+
"Could not detect shell. Please specify one of: bash, zsh, fish",
105+
err=True,
106+
)
107+
sys.exit(1)
108+
109+
comp_cls = get_completion_class(shell)
110+
if comp_cls is None:
111+
click.echo(f"No completion support for shell: {shell}", err=True)
112+
sys.exit(1)
113+
comp = comp_cls(
114+
cli, ctx_args={}, prog_name="astrbot", complete_var="_ASTRBOT_COMPLETE"
115+
)
116+
click.echo(comp.source())
117+
118+
119+
cli.add_command(completion)
57120

58121
if __name__ == "__main__":
59122
cli()

astrbot/cli/commands/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
from .cmd_bk import bk
12
from .cmd_conf import conf
23
from .cmd_init import init
34
from .cmd_plug import plug
45
from .cmd_run import run
6+
from .cmd_uninstall import uninstall
57

6-
__all__ = ["conf", "init", "plug", "run"]
8+
__all__ = ["bk", "conf", "init", "plug", "run", "uninstall"]

0 commit comments

Comments
 (0)