Skip to content

Commit e02d71b

Browse files
author
messica
committed
feat: compatible old singbox protocol, optimize the format of source config
1 parent a9a272c commit e02d71b

13 files changed

Lines changed: 406 additions & 303 deletions

File tree

README.md

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ A modern, extensible proxy configuration conversion tool supporting conversion a
66

77
- **Multi-protocol support**: Supports Clash, Sing-box, V2Ray and other proxy configuration formats
88
- **Multi-source integration**: Supports integration of multiple input sources with unified interpolation rules ✨
9-
- **Unified input rules**: Single source and multiple sources use the same `--source` parameter format
9+
- **URL-style source**: Source uses standard URL form `<path|url>?type=...&name=...&flag=...` for easy extension
1010
- **Powerful interpolation system**: Advanced template interpolation rules for complex node selection and filtering ✨
1111
- **Plugin architecture**: Easy to extend new protocol support
1212
- **Modern CLI**: User-friendly command line interface based on clap 4.x
@@ -37,16 +37,12 @@ cargo install --git https://github.com/your-username/proxy-convert.git
3737
### Basic Usage
3838

3939
```bash
40-
# Single source
41-
proxy-convert convert \
42-
--source "clash1@clash@./clash.yaml"
40+
# Recommended: URL-style (path/url + query params)
41+
proxy-convert convert --source "./clash.yaml?type=clash"
42+
proxy-convert convert --source "https://example.com/sub?type=clash&name=my&flag=clash" -o config.json
4343

44-
# Multiple sources
45-
proxy-convert convert \
46-
--source "clash1@clash@./clash.yaml" \
47-
--source "singbox1@sing-box@./singbox.json" \
48-
--template template.json \
49-
--output config.json
44+
# Legacy: name@type@source or type@source
45+
proxy-convert convert --source "clash1@clash@./clash.yaml" --source "singbox1@sing-box@./singbox.json" -o config.json
5046

5147
# Validate config file
5248
proxy-convert validate config.json
@@ -66,26 +62,23 @@ proxy-convert version
6662

6763
This ensures consistent user experience regardless of whether you use a single input source or multiple input sources.
6864

69-
### Source Format
65+
### Source Format (standard URL-style)
7066

71-
```conf
72-
name@type@source
67+
```text
68+
<path|url>?type=clash&name=...&flag=...
7369
```
7470

75-
- `name`: Source name, used for template reference
76-
- `type`: Subscription type (clash/sing-box/v2ray/auto)
77-
- `source`: File path or URL
71+
- Path or URL + `?` and query params (standard URL): `type` (required), `name` (optional), `flag` (optional).
72+
- Examples: `./config.yaml?type=clash`, `https://example.com/sub?type=clash&name=my&flag=clash`
73+
- Config file `sources` use the same format (list of such strings).
7874

7975
### Examples
8076

8177
```bash
82-
# File sources
83-
--source "clash1@clash@./clash.yaml"
84-
--source "singbox1@sing-box@./singbox.json"
85-
86-
# URL sources
87-
--source "sub1@clash@https://example.com/sub"
88-
--source "v2ray1@v2ray@https://example.com/v2ray.txt"
78+
--source "./clash.yaml?type=clash"
79+
--source "https://example.com/sub?type=clash&name=my&flag=clash"
80+
--source "examples/sources/Eternal Network?type=singbox"
81+
# With config: --config examples/config.yaml -o config.json
8982
```
9083

9184
## 📋 Interpolation Rules System
@@ -224,10 +217,7 @@ proxy-convert convert [OPTIONS] --source <SOURCE> [--source <SOURCE>...]
224217

225218
**Arguments:**
226219

227-
- `--source <SOURCE>`: Input source in format `name@type@source`
228-
- `name`: Source name, used for template reference
229-
- `type`: Subscription type (clash/sing-box/v2ray/auto)
230-
- `source`: File path or URL
220+
- `--source <SOURCE>`: Input source: `<path|url>?type=...&name=...&flag=...` (type required in query)
231221

232222
**Options:**
233223

@@ -291,6 +281,10 @@ output_format: json
291281
default_input_format: clash
292282
default_output_format: singbox
293283
template_dir: ~/.config/proxy-convert/templates
284+
# sources: same format as --source, e.g. ["path?type=clash&name=my"]
285+
# sources:
286+
# - "./clash.yaml?type=clash&name=clash1"
287+
# - "https://example.com/sub?type=singbox&name=sub1"
294288
```
295289

296290
### Environment Variables
@@ -341,7 +335,7 @@ The project supports multi-source integration with unified interpolation rules:
341335

342336
#### 1. Input Source Management
343337

344-
- **Unified format**: All sources use `name@type@source` format
338+
- **Source format**: `<path|url>?type=...&name=...&flag=...` (same for CLI and config)
345339
- **Type detection**: Automatic detection of clash, sing-box, v2ray formats
346340
- **Source naming**: Each source has a unique name for template reference
347341

README.zh-CN.md

Lines changed: 28 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -58,28 +58,26 @@ cargo install --git https://github.com/your-username/proxy-convert.git
5858
```
5959

6060
**选项:**
61-
- `--source <SOURCE>`:输入来源,格式:`name@type@source`
61+
- `--source <SOURCE>`:输入来源,见下方「来源格式说明」
6262
- `-t, --template <TEMPLATE>`:模板文件路径
6363
- `-o, --output <OUTPUT>`:输出文件路径(默认:config.json)
6464
- `-f, --format <FORMAT>`:输出格式(json/pretty/yaml,默认:pretty)
6565
- `-F, --force`:强制覆盖输出文件
6666
- `-l, --log-level <LOG_LEVEL>`:日志级别(默认:info)
6767
- `-v, --verbose`:显示详细信息
6868

69-
- 来源格式说明
69+
- **来源格式说明**(标准 URL 规范,命令行与配置文件一致)
7070

71-
```bash
72-
name@type@source
71+
```text
72+
<path|url>?type=clash&name=...&flag=...
7373
```
7474
75-
- `name`:来源名称,用于模板引用(可选,见下方说明)
76-
- `type`:订阅类型(clash/sing-box/v2ray/auto)
77-
- `source`:文件路径或URL
78-
79-
**重要说明:**
80-
- 如果只有一个来源,可以省略 `name`,直接使用 `type@source` 格式
81-
- 当省略 `name` 时,生成的节点标签不会添加来源前缀
82-
- 多个来源时必须指定 `name` 以区分不同来源
75+
- path 或 url 后加 `?` 与查询参数(与标准 URL 一致):
76+
- `type`:**必填**,订阅类型(clash / sing-box / v2ray)
77+
- `name`:可选,来源名称,用于模板引用
78+
- `flag`:可选,请求 URL 时的 flag 参数(空表示 `&flag=`)
79+
- 示例:`./config.yaml?type=clash`、`https://example.com/sub?type=clash&name=my&flag=clash`、`examples/sources/Eternal Network?type=singbox`
80+
- 配置文件 `sources` 也使用相同格式的字符串列表(见下方配置示例)。
8381
8482
- **验证配置文件**:验证配置文件的格式和内容正确性
8583
@@ -102,25 +100,22 @@ cargo install --git https://github.com/your-username/proxy-convert.git
102100
#### 使用示例
103101

104102
```bash
105-
# 单个来源(省略 name)
106-
proxy-convert convert \
107-
--source "clash@./clash.yaml"
103+
# 单源
104+
proxy-convert convert --source "./clash.yaml?type=clash"
108105

109-
# 单个来源(指定 name)
106+
# 多源(可带 name、flag
110107
proxy-convert convert \
111-
--source "clash1@clash@./clash.yaml"
108+
--source "https://example.com/sub?type=clash&name=my&flag=clash" \
109+
--source "examples/sources/Eternal Network?type=singbox" \
110+
-o config.json
112111

113-
# 多个来源(必须指定 name)
114-
proxy-convert convert \
115-
--source "clash1@clash@./clash.yaml" \
116-
--source "singbox1@sing-box@./singbox.json" \
117-
--template template.json \
118-
--output config.json
112+
# 使用配置文件(sources 格式与 --source 一致)
113+
proxy-convert convert --config examples/config.yaml -o config.json
119114

120115
# 其他命令
121-
proxy-convert validate config.json # 验证配置文件
122-
proxy-convert template singbox --output template.json # 生成模板
123-
proxy-convert version # 显示版本信息
116+
proxy-convert validate config.json
117+
proxy-convert template singbox --output template.json
118+
proxy-convert version
124119
```
125120

126121
## 📋 插值规则系统 ✨
@@ -242,7 +237,7 @@ proxy-convert version # 显示版本信息
242237
**单个来源的情况:**
243238

244239
- 如果只有一个来源且没有指定 `name`,节点标签保持原样
245-
- 例如:`--source "clash@./clash.yaml"` 时,节点标签不会添加前缀
240+
- 例如:单源且未指定 `name`(如 `--source "./clash.yaml?type=clash"`时,节点标签不会添加前缀
246241

247242
**标签前缀的作用:**
248243

@@ -322,14 +317,10 @@ output: config.json
322317
# 模板目录
323318
template_dir: ~/.config/proxy-convert/templates
324319

325-
# 来源配置(可选,也可以通过命令行参数指定)
326-
source:
327-
- name: clash1
328-
type: clash
329-
path_or_url: ./clash.yaml
330-
- name: singbox1
331-
type: sing-box
332-
path_or_url: ./singbox.json
320+
# 来源配置(可选,与 --source 格式一致:<path|url>?type=...&name=...&flag=...)
321+
sources:
322+
- "./clash.yaml?type=clash&name=clash1"
323+
- "./singbox.json?type=singbox&name=singbox1"
333324
```
334325
335326
**配置项说明:**
@@ -344,7 +335,7 @@ source:
344335
- `output_format`:输出格式(json/pretty/yaml)
345336
- `output`:默认输出文件路径
346337
- `template_dir`:模板文件目录
347-
- `source`:预定义的来源列表
338+
- `sources`:预定义的来源列表(每项为 URL 格式字符串,与命令行 `--source` 一致)
348339

349340
### 环境变量
350341

@@ -423,7 +414,7 @@ src/
423414

424415
#### 1. 输入源管理
425416

426-
- **统一格式**所有来源使用 `name@type@source` 格式
417+
- **来源格式**:统一使用 URL 形式 `<path|url>?type=...&name=...&flag=...`(命令行与配置文件一致)
427418
- **类型检测**:自动检测 clash、sing-box、v2ray 格式
428419
- **来源命名**:每个来源都有唯一名称用于模板引用
429420

src/commands/cli.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@ pub struct Cli {
2424
pub enum Commands {
2525
/// Convert subscription configuration
2626
Convert {
27-
/// Input sources in format: source-name@source-type@<path|url>
28-
/// Single source: --source "clash1@clash@./clash.yaml"
29-
/// Multiple sources: --source "clash1@clash@./clash.yaml" --source "sub1@sing-box@https://example.com/sub"
27+
/// Input sources: <path|url>?type=clash&name=...&flag=... (type required in query)
3028
#[arg(long = "source", value_name = "SOURCE")]
3129
sources: Vec<String>,
3230

0 commit comments

Comments
 (0)