mihomo-cli 1.1.0 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +42 -0
- package/README.md +52 -2
- package/index.js +135 -74
- package/package.json +1 -1
- package/src/overwrite.js +0 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,47 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [1.2.1] - 2026-04-05
|
|
4
|
+
|
|
5
|
+
### 优化
|
|
6
|
+
|
|
7
|
+
- 简化帮助中的命令列表,统一一行格式
|
|
8
|
+
|
|
9
|
+
### 文档
|
|
10
|
+
|
|
11
|
+
- README 添加覆写配置和自动重启说明
|
|
12
|
+
- CLAUDE.md 精简和完善,增加发布检查清单
|
|
13
|
+
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
## [1.2.0] - 2026-04-05
|
|
17
|
+
|
|
18
|
+
### 新增功能
|
|
19
|
+
|
|
20
|
+
#### 配置变更自动重启
|
|
21
|
+
- **sub use 自动重启**:切换默认订阅后,如果 mihomo 正在运行则自动重启
|
|
22
|
+
- **ow on/off 自动重启**:启用/禁用覆写配置后,如果 mihomo 正在运行则自动重启
|
|
23
|
+
- **状态检查**:操作前检查是否已是目标状态,避免重复操作
|
|
24
|
+
|
|
25
|
+
### 重构
|
|
26
|
+
|
|
27
|
+
#### 命名规范统一
|
|
28
|
+
- **函数重命名**:统一使用全称单数
|
|
29
|
+
- `findSubsFuzzy` → `findSubscriptionFuzzy`
|
|
30
|
+
- `pickSingleSub` → `pickSingleSubscription`
|
|
31
|
+
- `printSubList` → `printSubscriptionList`
|
|
32
|
+
- `cmdSub` → `cmdSubscription`
|
|
33
|
+
- `cmdDirs` → `cmdDirectory`
|
|
34
|
+
- `DIR_TARGETS` → `DIRECTORY_TARGETS`
|
|
35
|
+
- **帮助文档统一**:
|
|
36
|
+
- 示例统一使用 `mihomo` 而非 `mihomo-cli`
|
|
37
|
+
- 命令列表使用全称单数 `directory` 而非 `directories`
|
|
38
|
+
- 提示语中的命令示例添加 `mihomo` 前缀
|
|
39
|
+
|
|
40
|
+
### 修复
|
|
41
|
+
|
|
42
|
+
- 修复缺失的 `path` 模块导入
|
|
43
|
+
- 统一引号风格(命令示例使用双引号)
|
|
44
|
+
|
|
3
45
|
## [1.1.0] - 2026-04-05
|
|
4
46
|
|
|
5
47
|
### 新增功能
|
package/README.md
CHANGED
|
@@ -7,6 +7,8 @@
|
|
|
7
7
|
- 🌐 **订阅管理** - 添加/更新订阅,支持流量统计和到期时间显示
|
|
8
8
|
- 🔄 **自动更新** - 启动时自动检查并更新过期订阅
|
|
9
9
|
- 🔍 **模糊匹配** - `sub use` / `sub web` 支持订阅名称模糊匹配
|
|
10
|
+
- 📝 **覆写配置** - 在订阅基础上进行自定义覆写,支持强制覆盖、数组合并
|
|
11
|
+
- 🔄 **智能重启** - `sub use` 切换订阅、`ow on/off` 切换覆写后自动重启
|
|
10
12
|
- 🚀 **进程管理** - 启动/停止/切换模式,自动清理残留进程
|
|
11
13
|
- 🔄 **双模式支持** - Mixed 模式和 TUN 透明代理模式
|
|
12
14
|
- 📊 **状态监控** - 查看运行状态、内存占用
|
|
@@ -94,16 +96,25 @@ mihomo ui yacd # YACD
|
|
|
94
96
|
| `mihomo sub add <url> [name]` | 添加订阅 |
|
|
95
97
|
| `mihomo sub update` | 更新所有订阅 |
|
|
96
98
|
| `mihomo sub update <name>` | 更新指定订阅(支持模糊匹配) |
|
|
97
|
-
| `mihomo sub use <name>` |
|
|
99
|
+
| `mihomo sub use <name>` | 设置默认订阅(支持模糊匹配,自动重启) |
|
|
98
100
|
| `mihomo sub web [name]` | 打开订阅页面(无参打开默认) |
|
|
99
101
|
|
|
102
|
+
### 覆写配置
|
|
103
|
+
|
|
104
|
+
| 命令 | 说明 |
|
|
105
|
+
|------|------|
|
|
106
|
+
| `mihomo ow` / `mihomo ow list` | 查看覆写配置状态和文件列表 |
|
|
107
|
+
| `mihomo ow on` | 启用覆写配置(自动重启) |
|
|
108
|
+
| `mihomo ow off` | 禁用覆写配置(自动重启) |
|
|
109
|
+
|
|
100
110
|
### 其他命令
|
|
101
111
|
|
|
102
112
|
| 命令 | 说明 |
|
|
103
113
|
|------|------|
|
|
104
114
|
| `mihomo kernel [镜像\|--no-mirror]` | 更新内核 |
|
|
105
115
|
| `mihomo ui [zash\|dash\|yacd]` | 打开 Web UI |
|
|
106
|
-
| `mihomo
|
|
116
|
+
| `mihomo dir` | 显示数据目录位置 |
|
|
117
|
+
| `mihomo dir open [target]` | 打开指定目录(`root`, `subs`, `logs`, `overwrites` 等) |
|
|
107
118
|
| `mihomo reset [--full]` | 重置用户数据 (--full 同时删除内核) |
|
|
108
119
|
| `mihomo version` | 显示版本信息 |
|
|
109
120
|
| `mihomo help` | 显示帮助信息 |
|
|
@@ -165,6 +176,7 @@ mihomo kernel --no-mirror
|
|
|
165
176
|
├── subscriptions/
|
|
166
177
|
│ ├── cache.json # 订阅动态缓存(更新时间、流量、到期时间等)
|
|
167
178
|
│ └── <name>.yaml # 订阅原始配置
|
|
179
|
+
├── overwrites/ # 覆写配置(按文件名排序加载)
|
|
168
180
|
├── core/
|
|
169
181
|
│ └── mihomo # mihomo 内核二进制
|
|
170
182
|
├── logs/
|
|
@@ -178,6 +190,44 @@ mihomo kernel --no-mirror
|
|
|
178
190
|
|
|
179
191
|
可通过环境变量 `MIHOMO_CLI_DIR` 自定义数据目录位置。
|
|
180
192
|
|
|
193
|
+
## 覆写配置
|
|
194
|
+
|
|
195
|
+
覆写配置允许你在订阅配置基础上进行自定义修改,而不会影响订阅本身。
|
|
196
|
+
|
|
197
|
+
### 使用方法
|
|
198
|
+
|
|
199
|
+
1. 在 `~/.mihomo-cli/overwrites/` 目录下创建 `.yaml` 或 `.yml` 文件
|
|
200
|
+
2. 文件按**文件名顺序**加载,后面的文件会覆盖前面的配置
|
|
201
|
+
3. 使用 `mihomo ow on` 启用覆写配置(会自动重启)
|
|
202
|
+
|
|
203
|
+
### 特殊语法
|
|
204
|
+
|
|
205
|
+
覆写配置支持以下特殊操作符:
|
|
206
|
+
|
|
207
|
+
| 语法 | 作用 | 示例 |
|
|
208
|
+
|------|------|------|
|
|
209
|
+
| `key!` | 强制覆盖整个对象(不深度合并) | `dns!`: { ... } |
|
|
210
|
+
| `+key` | 数组前置插入 | `+proxies`: [...] |
|
|
211
|
+
| `key+` | 数组追加 | `rules+`: [...] |
|
|
212
|
+
| `<+key>` | 键名以 `+` 开头时转义 | `<+.google.cn>`: ... |
|
|
213
|
+
|
|
214
|
+
### 示例
|
|
215
|
+
|
|
216
|
+
```yaml
|
|
217
|
+
# ~/.mihomo-cli/overwrites/01-custom.yaml
|
|
218
|
+
|
|
219
|
+
# 强制覆盖 dns 配置
|
|
220
|
+
dns!:
|
|
221
|
+
enable: true
|
|
222
|
+
enhanced-mode: fake-ip
|
|
223
|
+
nameserver:
|
|
224
|
+
- 223.5.5.5
|
|
225
|
+
|
|
226
|
+
# 追加规则
|
|
227
|
+
rules+:
|
|
228
|
+
- "DOMAIN-SUFFIX,example.com,DIRECT"
|
|
229
|
+
```
|
|
230
|
+
|
|
181
231
|
## Web UI
|
|
182
232
|
|
|
183
233
|
内置三个常用 Web UI:
|
package/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
+
const path = require('path');
|
|
3
4
|
const { spawn } = require('child_process');
|
|
4
5
|
|
|
5
6
|
const config = require('./src/config');
|
|
@@ -60,7 +61,7 @@ function printShortHelp() {
|
|
|
60
61
|
' subscription update 更新订阅\n' +
|
|
61
62
|
' subscription use <name> 切换默认订阅\n' +
|
|
62
63
|
' overwrite [on|off] 覆写配置(别名 ow)\n' +
|
|
63
|
-
'
|
|
64
|
+
' directory 数据目录(别名 dir)\n' +
|
|
64
65
|
' kernel 更新内核\n' +
|
|
65
66
|
' reset 重置配置\n' +
|
|
66
67
|
' version 版本信息\n');
|
|
@@ -72,7 +73,7 @@ function printHelp() {
|
|
|
72
73
|
'命令别名: mihomo, mmc, mh\n' +
|
|
73
74
|
'\n' +
|
|
74
75
|
'用法:\n' +
|
|
75
|
-
' mihomo
|
|
76
|
+
' mihomo <命令> [选项]\n' +
|
|
76
77
|
'\n' +
|
|
77
78
|
'控制:\n' +
|
|
78
79
|
' start [tun|mixed] 启动/切换代理 (默认 mixed)\n' +
|
|
@@ -85,14 +86,11 @@ function printHelp() {
|
|
|
85
86
|
' logs [编号] [-n N] [-o] 日志列表(0=当前,1+=归档)\n' +
|
|
86
87
|
'\n' +
|
|
87
88
|
'订阅:\n' +
|
|
88
|
-
' subscription add
|
|
89
|
-
' subscription update [name] 更新订阅(无参更新所有)\n' +
|
|
90
|
-
' subscription use <name> 设置默认订阅\n' +
|
|
91
|
-
' subscription web [name] 打开订阅页面\n' +
|
|
89
|
+
' subscription [add|update|use|web] 订阅管理(别名 sub)\n' +
|
|
92
90
|
'\n' +
|
|
93
91
|
'配置:\n' +
|
|
94
92
|
' overwrite [on|off] 覆写配置(别名 ow)\n' +
|
|
95
|
-
'
|
|
93
|
+
' directory [open] 数据目录(别名 dir)\n' +
|
|
96
94
|
'\n' +
|
|
97
95
|
'系统:\n' +
|
|
98
96
|
' kernel [镜像|--no-mirror] 更新内核\n' +
|
|
@@ -101,10 +99,10 @@ function printHelp() {
|
|
|
101
99
|
' version, -v 显示版本\n' +
|
|
102
100
|
'\n' +
|
|
103
101
|
'示例:\n' +
|
|
104
|
-
' mihomo
|
|
105
|
-
' mihomo
|
|
106
|
-
' mihomo
|
|
107
|
-
' mihomo
|
|
102
|
+
' mihomo start # 启动/重启 Mixed 模式\n' +
|
|
103
|
+
' mihomo start tun # 切换到 TUN 透明代理模式\n' +
|
|
104
|
+
' mihomo sub add <url> # 添加订阅 (sub 是 subscription 别名)\n' +
|
|
105
|
+
' mihomo ui # 打开 Web UI\n' +
|
|
108
106
|
'\n' +
|
|
109
107
|
'模式说明:\n' +
|
|
110
108
|
' mixed HTTP + SOCKS5 混合端口 (默认)\n' +
|
|
@@ -189,7 +187,7 @@ function getActiveSubscription() {
|
|
|
189
187
|
return subs[0];
|
|
190
188
|
}
|
|
191
189
|
|
|
192
|
-
function
|
|
190
|
+
function findSubscriptionFuzzy(subs, pattern) {
|
|
193
191
|
const lowerPattern = pattern.toLowerCase();
|
|
194
192
|
let exact = [];
|
|
195
193
|
let prefix = [];
|
|
@@ -211,7 +209,7 @@ function findSubsFuzzy(subs, pattern) {
|
|
|
211
209
|
return includes;
|
|
212
210
|
}
|
|
213
211
|
|
|
214
|
-
function
|
|
212
|
+
function pickSingleSubscription(subs, pattern, actionName) {
|
|
215
213
|
if (subs.length === 0) {
|
|
216
214
|
console.error('错误: 未找到匹配 "' + pattern + '" 的订阅');
|
|
217
215
|
process.exit(1);
|
|
@@ -297,7 +295,7 @@ function viewLogWithTail(logPath, options) {
|
|
|
297
295
|
|
|
298
296
|
async function cmdStart(args) {
|
|
299
297
|
if (!config.hasKernel()) {
|
|
300
|
-
console.error('错误: 未找到内核,请运行
|
|
298
|
+
console.error('错误: 未找到内核,请运行 "mihomo kernel"');
|
|
301
299
|
process.exit(1);
|
|
302
300
|
}
|
|
303
301
|
|
|
@@ -422,7 +420,7 @@ function cmdLogs(args) {
|
|
|
422
420
|
|
|
423
421
|
if (!logPath) {
|
|
424
422
|
console.error('错误: 未找到日志 "' + targetName + '"');
|
|
425
|
-
console.log('使用 "mihomo
|
|
423
|
+
console.log('使用 "mihomo logs" 查看可用日志列表');
|
|
426
424
|
process.exit(1);
|
|
427
425
|
}
|
|
428
426
|
|
|
@@ -461,16 +459,16 @@ function cmdLogs(args) {
|
|
|
461
459
|
console.log(' ' + num + '. ' + name);
|
|
462
460
|
console.log(' 时间: ' + time + ' 大小: ' + size);
|
|
463
461
|
if (!log.isCurrent) {
|
|
464
|
-
console.log(' 查看: mihomo
|
|
462
|
+
console.log(' 查看: mihomo logs ' + idx + ' 或 mihomo logs -o ' + idx);
|
|
465
463
|
}
|
|
466
464
|
console.log('');
|
|
467
465
|
});
|
|
468
466
|
|
|
469
467
|
console.log('用法:');
|
|
470
|
-
console.log(' mihomo
|
|
471
|
-
console.log(' mihomo
|
|
472
|
-
console.log(' mihomo
|
|
473
|
-
console.log(' mihomo
|
|
468
|
+
console.log(' mihomo logs 0 # 查看当前日志 (最后 100 行)');
|
|
469
|
+
console.log(' mihomo logs 1 # 查看第 1 个归档日志');
|
|
470
|
+
console.log(' mihomo logs 1 -n 200 # 查看 200 行');
|
|
471
|
+
console.log(' mihomo logs 1 -o # 用系统默认程序打开');
|
|
474
472
|
console.log('');
|
|
475
473
|
}
|
|
476
474
|
|
|
@@ -549,10 +547,10 @@ async function cmdKernel(args) {
|
|
|
549
547
|
});
|
|
550
548
|
|
|
551
549
|
console.log('\n用法:');
|
|
552
|
-
console.log(' mihomo
|
|
553
|
-
console.log(' mihomo
|
|
554
|
-
console.log(' mihomo
|
|
555
|
-
console.log(' mihomo
|
|
550
|
+
console.log(' mihomo kernel # 使用默认镜像');
|
|
551
|
+
console.log(' mihomo kernel hk.gh-proxy.org # 使用指定镜像');
|
|
552
|
+
console.log(' mihomo kernel --mirror hk.gh-proxy.org');
|
|
553
|
+
console.log(' mihomo kernel --no-mirror # 直连,不使用镜像');
|
|
556
554
|
console.log('');
|
|
557
555
|
|
|
558
556
|
try {
|
|
@@ -576,7 +574,7 @@ async function cmdKernel(args) {
|
|
|
576
574
|
}
|
|
577
575
|
}
|
|
578
576
|
|
|
579
|
-
async function
|
|
577
|
+
async function printSubscriptionList() {
|
|
580
578
|
const updateResult = await subscription.autoUpdateStaleSubscriptions();
|
|
581
579
|
if (updateResult.total > 0) {
|
|
582
580
|
console.log('');
|
|
@@ -586,7 +584,7 @@ async function printSubList() {
|
|
|
586
584
|
if (subs.length === 0) {
|
|
587
585
|
console.log('没有订阅');
|
|
588
586
|
console.log('');
|
|
589
|
-
console.log('添加订阅: mihomo
|
|
587
|
+
console.log('添加订阅: mihomo sub add <url> [name]');
|
|
590
588
|
console.log('');
|
|
591
589
|
return;
|
|
592
590
|
}
|
|
@@ -620,17 +618,17 @@ async function printSubList() {
|
|
|
620
618
|
}
|
|
621
619
|
});
|
|
622
620
|
console.log('');
|
|
623
|
-
console.log('切换默认: sub use <name>');
|
|
624
|
-
console.log('更新订阅: sub update [name]');
|
|
625
|
-
console.log('打开页面: sub web [name]');
|
|
621
|
+
console.log('切换默认: mihomo sub use <name>');
|
|
622
|
+
console.log('更新订阅: mihomo sub update [name]');
|
|
623
|
+
console.log('打开页面: mihomo sub web [name]');
|
|
626
624
|
console.log('');
|
|
627
625
|
}
|
|
628
626
|
|
|
629
|
-
async function
|
|
627
|
+
async function cmdSubscription(args) {
|
|
630
628
|
const action = args[1];
|
|
631
629
|
|
|
632
630
|
if (!action || action === 'list') {
|
|
633
|
-
await
|
|
631
|
+
await printSubscriptionList();
|
|
634
632
|
return;
|
|
635
633
|
}
|
|
636
634
|
|
|
@@ -656,7 +654,7 @@ async function cmdSub(args) {
|
|
|
656
654
|
process.exit(1);
|
|
657
655
|
}
|
|
658
656
|
console.log('');
|
|
659
|
-
await
|
|
657
|
+
await printSubscriptionList();
|
|
660
658
|
return;
|
|
661
659
|
}
|
|
662
660
|
|
|
@@ -686,12 +684,12 @@ async function cmdSub(args) {
|
|
|
686
684
|
});
|
|
687
685
|
if (ok === 0) process.exit(1);
|
|
688
686
|
console.log('');
|
|
689
|
-
await
|
|
687
|
+
await printSubscriptionList();
|
|
690
688
|
return;
|
|
691
689
|
}
|
|
692
690
|
|
|
693
|
-
const matches =
|
|
694
|
-
const target =
|
|
691
|
+
const matches = findSubscriptionFuzzy(subs, name);
|
|
692
|
+
const target = pickSingleSubscription(matches, name, '更新');
|
|
695
693
|
|
|
696
694
|
console.log('更新订阅: ' + target.name);
|
|
697
695
|
try {
|
|
@@ -705,7 +703,7 @@ async function cmdSub(args) {
|
|
|
705
703
|
process.exit(1);
|
|
706
704
|
}
|
|
707
705
|
console.log('');
|
|
708
|
-
await
|
|
706
|
+
await printSubscriptionList();
|
|
709
707
|
return;
|
|
710
708
|
}
|
|
711
709
|
|
|
@@ -722,8 +720,24 @@ async function cmdSub(args) {
|
|
|
722
720
|
process.exit(1);
|
|
723
721
|
}
|
|
724
722
|
|
|
725
|
-
const matches =
|
|
726
|
-
const target =
|
|
723
|
+
const matches = findSubscriptionFuzzy(subs, name);
|
|
724
|
+
const target = pickSingleSubscription(matches, name, '切换');
|
|
725
|
+
|
|
726
|
+
// 检查是否已是当前默认订阅
|
|
727
|
+
const currentDefault = getActiveSubscription();
|
|
728
|
+
const isAlreadyDefault = currentDefault && currentDefault.name === target.name;
|
|
729
|
+
|
|
730
|
+
if (isAlreadyDefault) {
|
|
731
|
+
console.log('"' + target.name + '" 已是当前默认订阅');
|
|
732
|
+
console.log('');
|
|
733
|
+
await printSubscriptionList();
|
|
734
|
+
return;
|
|
735
|
+
}
|
|
736
|
+
|
|
737
|
+
// 检查当前运行状态和模式
|
|
738
|
+
const status = processMgr.getStatus();
|
|
739
|
+
const cfgInfo = config.getConfigInfo();
|
|
740
|
+
const currentMode = cfgInfo && cfgInfo.tun ? 'tun' : 'mixed';
|
|
727
741
|
|
|
728
742
|
const success = config.setDefaultSubscription(target.name);
|
|
729
743
|
if (success) {
|
|
@@ -732,8 +746,16 @@ async function cmdSub(args) {
|
|
|
732
746
|
console.error('错误: 未找到订阅 "' + name + '"');
|
|
733
747
|
process.exit(1);
|
|
734
748
|
}
|
|
749
|
+
|
|
750
|
+
// 如果正在运行,自动重启
|
|
751
|
+
if (status.running) {
|
|
752
|
+
console.log('');
|
|
753
|
+
await cmdStart(['start', currentMode]);
|
|
754
|
+
return;
|
|
755
|
+
}
|
|
756
|
+
|
|
735
757
|
console.log('');
|
|
736
|
-
await
|
|
758
|
+
await printSubscriptionList();
|
|
737
759
|
return;
|
|
738
760
|
}
|
|
739
761
|
|
|
@@ -748,8 +770,8 @@ async function cmdSub(args) {
|
|
|
748
770
|
|
|
749
771
|
let target;
|
|
750
772
|
if (name) {
|
|
751
|
-
const matches =
|
|
752
|
-
target =
|
|
773
|
+
const matches = findSubscriptionFuzzy(subs, name);
|
|
774
|
+
target = pickSingleSubscription(matches, name, '打开');
|
|
753
775
|
} else {
|
|
754
776
|
target = subs[0];
|
|
755
777
|
}
|
|
@@ -782,7 +804,7 @@ async function cmdSub(args) {
|
|
|
782
804
|
}
|
|
783
805
|
|
|
784
806
|
console.error('错误: 未知的订阅命令');
|
|
785
|
-
console.log('用法: mihomo
|
|
807
|
+
console.log('用法: mihomo sub [list|add|update|use|web]');
|
|
786
808
|
process.exit(1);
|
|
787
809
|
}
|
|
788
810
|
|
|
@@ -829,7 +851,6 @@ async function cmdReset(args) {
|
|
|
829
851
|
|
|
830
852
|
function printOverwriteList() {
|
|
831
853
|
const info = overwrite.listOverwriteFiles();
|
|
832
|
-
console.log('');
|
|
833
854
|
console.log('状态: ' + (info.enabled ? '已启用' : '已禁用'));
|
|
834
855
|
console.log('目录: ' + info.dir);
|
|
835
856
|
console.log('');
|
|
@@ -850,38 +871,87 @@ function printOverwriteList() {
|
|
|
850
871
|
});
|
|
851
872
|
console.log('');
|
|
852
873
|
}
|
|
853
|
-
console.log('启用覆写: ow on');
|
|
854
|
-
console.log('禁用覆写: ow off');
|
|
874
|
+
console.log('启用覆写: mihomo ow on');
|
|
875
|
+
console.log('禁用覆写: mihomo ow off');
|
|
855
876
|
console.log('');
|
|
856
877
|
}
|
|
857
878
|
|
|
858
|
-
function cmdOverwrite(args) {
|
|
879
|
+
async function cmdOverwrite(args) {
|
|
859
880
|
const action = args && args[1];
|
|
860
881
|
|
|
882
|
+
// 检查当前运行状态和模式
|
|
883
|
+
const status = processMgr.getStatus();
|
|
884
|
+
const cfgInfo = config.getConfigInfo();
|
|
885
|
+
const currentMode = cfgInfo && cfgInfo.tun ? 'tun' : 'mixed';
|
|
886
|
+
|
|
861
887
|
if (action === 'on' || action === 'enable') {
|
|
888
|
+
// 如果已经启用,提示后直接返回
|
|
889
|
+
if (overwrite.isOverwriteEnabled()) {
|
|
890
|
+
console.log('覆写配置已是启用状态');
|
|
891
|
+
console.log('');
|
|
892
|
+
printOverwriteList();
|
|
893
|
+
return;
|
|
894
|
+
}
|
|
895
|
+
|
|
862
896
|
overwrite.setOverwriteEnabled(true);
|
|
863
897
|
console.log('已启用覆写配置');
|
|
898
|
+
|
|
899
|
+
// 如果正在运行,自动重启
|
|
900
|
+
if (status.running) {
|
|
901
|
+
console.log('');
|
|
902
|
+
await cmdStart(['start', currentMode]);
|
|
903
|
+
return;
|
|
904
|
+
}
|
|
905
|
+
|
|
864
906
|
console.log('');
|
|
865
907
|
printOverwriteList();
|
|
866
908
|
return;
|
|
867
909
|
}
|
|
868
910
|
|
|
869
911
|
if (action === 'off' || action === 'disable') {
|
|
912
|
+
// 如果已经禁用,提示后直接返回
|
|
913
|
+
if (!overwrite.isOverwriteEnabled()) {
|
|
914
|
+
console.log('覆写配置已是禁用状态');
|
|
915
|
+
console.log('');
|
|
916
|
+
printOverwriteList();
|
|
917
|
+
return;
|
|
918
|
+
}
|
|
919
|
+
|
|
870
920
|
overwrite.setOverwriteEnabled(false);
|
|
871
921
|
console.log('已禁用覆写配置');
|
|
922
|
+
|
|
923
|
+
// 如果正在运行,自动重启
|
|
924
|
+
if (status.running) {
|
|
925
|
+
console.log('');
|
|
926
|
+
await cmdStart(['start', currentMode]);
|
|
927
|
+
return;
|
|
928
|
+
}
|
|
929
|
+
|
|
872
930
|
console.log('');
|
|
873
931
|
printOverwriteList();
|
|
874
932
|
return;
|
|
875
933
|
}
|
|
876
934
|
|
|
877
935
|
// 无参数、list、ls 都显示文件列表
|
|
936
|
+
console.log('');
|
|
878
937
|
printOverwriteList();
|
|
879
938
|
}
|
|
880
939
|
|
|
881
|
-
|
|
940
|
+
// 目录目标映射(精确匹配)
|
|
941
|
+
const DIRECTORY_TARGETS = {
|
|
942
|
+
'root': { path: null, label: '根目录' },
|
|
943
|
+
'subs': { path: config.DIRS.subscriptions, label: '订阅目录' },
|
|
944
|
+
'logs': { path: config.DIRS.logs, label: '日志目录' },
|
|
945
|
+
'data': { path: config.DIRS.data, label: 'mihomo 数据目录' },
|
|
946
|
+
'runtime': { path: config.DIRS.runtime, label: '运行时目录' },
|
|
947
|
+
'overwrites': { path: config.DIRS.overwrites, label: '覆写目录' },
|
|
948
|
+
'settings': { path: config.PATHS.settingsFile, label: '设置文件' },
|
|
949
|
+
'kernel': { path: config.DIRS.core, label: '内核目录' },
|
|
950
|
+
};
|
|
951
|
+
|
|
952
|
+
function cmdDirectory(args) {
|
|
882
953
|
const action = args && args[1];
|
|
883
954
|
|
|
884
|
-
// dirs open [root|subs|logs|data|runtime|config|kernel]
|
|
885
955
|
if (action === 'open') {
|
|
886
956
|
const target = args[2];
|
|
887
957
|
|
|
@@ -890,23 +960,10 @@ function cmdDirs(args) {
|
|
|
890
960
|
return;
|
|
891
961
|
}
|
|
892
962
|
|
|
893
|
-
const
|
|
894
|
-
'subs': { path: config.DIRS.subscriptions, label: '订阅目录' },
|
|
895
|
-
'subscriptions': { path: config.DIRS.subscriptions, label: '订阅目录' },
|
|
896
|
-
'logs': { path: config.DIRS.logs, label: '日志目录' },
|
|
897
|
-
'data': { path: config.DIRS.data, label: 'mihomo 数据目录' },
|
|
898
|
-
'runtime': { path: config.DIRS.runtime, label: '运行时目录' },
|
|
899
|
-
};
|
|
900
|
-
|
|
901
|
-
const fileMap = {
|
|
902
|
-
'config': { path: config.PATHS.settingsFile, label: '设置文件' },
|
|
903
|
-
'settings': { path: config.PATHS.settingsFile, label: '设置文件' },
|
|
904
|
-
'kernel': { path: config.DIRS.core, label: '内核目录' },
|
|
905
|
-
};
|
|
906
|
-
|
|
907
|
-
const targetInfo = dirMap[target] || fileMap[target];
|
|
963
|
+
const targetInfo = DIRECTORY_TARGETS[target.toLowerCase()];
|
|
908
964
|
if (targetInfo) {
|
|
909
|
-
|
|
965
|
+
const path = targetInfo.path || config.USER_DATA_DIR;
|
|
966
|
+
openDir(path, targetInfo.label);
|
|
910
967
|
return;
|
|
911
968
|
}
|
|
912
969
|
|
|
@@ -918,7 +975,8 @@ function cmdDirs(args) {
|
|
|
918
975
|
console.log(' logs 日志目录');
|
|
919
976
|
console.log(' data mihomo 数据目录');
|
|
920
977
|
console.log(' runtime 运行时目录');
|
|
921
|
-
console.log('
|
|
978
|
+
console.log(' overwrites 覆写目录');
|
|
979
|
+
console.log(' settings 设置文件 (settings.json)');
|
|
922
980
|
console.log(' kernel 内核目录');
|
|
923
981
|
console.log('');
|
|
924
982
|
process.exit(1);
|
|
@@ -941,10 +999,13 @@ function cmdDirs(args) {
|
|
|
941
999
|
console.log(' - cache.db, Geo*.dat 等 (mihomo 自行管理)');
|
|
942
1000
|
console.log('');
|
|
943
1001
|
console.log('打开目录:');
|
|
944
|
-
console.log(' mihomo
|
|
945
|
-
console.log(' mihomo
|
|
946
|
-
console.log(' mihomo
|
|
947
|
-
console.log(' mihomo
|
|
1002
|
+
console.log(' mihomo dir open 打开根目录');
|
|
1003
|
+
console.log(' mihomo dir open subs 打开订阅目录');
|
|
1004
|
+
console.log(' mihomo dir open logs 打开日志目录');
|
|
1005
|
+
console.log(' mihomo dir open runtime 打开运行时目录');
|
|
1006
|
+
console.log(' mihomo dir open overwrites 打开覆写目录');
|
|
1007
|
+
console.log(' mihomo dir open settings 打开设置文件');
|
|
1008
|
+
console.log(' mihomo dir open kernel 打开内核目录');
|
|
948
1009
|
console.log('');
|
|
949
1010
|
console.log('环境变量:');
|
|
950
1011
|
console.log(' MIHOMO_CLI_DIR: 自定义根目录位置');
|
|
@@ -998,24 +1059,24 @@ async function main() {
|
|
|
998
1059
|
case 'sub':
|
|
999
1060
|
case 'subscription':
|
|
1000
1061
|
case 'subscriptions':
|
|
1001
|
-
await
|
|
1062
|
+
await cmdSubscription(args);
|
|
1002
1063
|
break;
|
|
1003
1064
|
case 'dir':
|
|
1004
1065
|
case 'dirs':
|
|
1005
1066
|
case 'directory':
|
|
1006
1067
|
case 'directories':
|
|
1007
|
-
|
|
1068
|
+
cmdDirectory(args);
|
|
1008
1069
|
break;
|
|
1009
1070
|
case 'reset':
|
|
1010
1071
|
await cmdReset(args);
|
|
1011
1072
|
break;
|
|
1012
|
-
case 'overwrite':
|
|
1013
1073
|
case 'ow':
|
|
1014
|
-
|
|
1074
|
+
case 'overwrite':
|
|
1075
|
+
await cmdOverwrite(args);
|
|
1015
1076
|
break;
|
|
1016
1077
|
default:
|
|
1017
1078
|
console.error('未知命令: ' + cmd);
|
|
1018
|
-
console.error('使用 "mihomo
|
|
1079
|
+
console.error('使用 "mihomo help" 查看帮助');
|
|
1019
1080
|
process.exit(1);
|
|
1020
1081
|
}
|
|
1021
1082
|
}
|
package/package.json
CHANGED
package/src/overwrite.js
CHANGED
|
@@ -247,12 +247,8 @@ function listOverwriteFiles() {
|
|
|
247
247
|
}
|
|
248
248
|
|
|
249
249
|
module.exports = {
|
|
250
|
-
parseOverrideKey,
|
|
251
|
-
deepMergeWithOverrides,
|
|
252
|
-
getOverwritesDir,
|
|
253
250
|
isOverwriteEnabled,
|
|
254
251
|
setOverwriteEnabled,
|
|
255
|
-
loadOverwriteFiles,
|
|
256
252
|
applyOverwrites,
|
|
257
253
|
listOverwriteFiles,
|
|
258
254
|
};
|