答案
Whistle 提供了丰富的命令行工具,可以通过命令行完成大部分操作,提高工作效率。
基本命令
1. 安装和卸载
全局安装 whistle:
bashnpm install -g whistle
卸载 whistle:
bashnpm uninstall -g whistle
更新 whistle:
bashnpm update -g whistle
2. 启动和停止
启动 whistle:
bashw2 start
指定端口启动:
bashw2 start -p 8080
指定配置文件启动:
bashw2 start -f custom.rules
指定存储目录启动:
bashw2 start -D /path/to/storage
停止 whistle:
bashw2 stop
重启 whistle:
bashw2 restart
3. 查看状态
查看运行状态:
bashw2 status
查看版本信息:
bashw2 -v
查看帮助信息:
bashw2 -h
配置管理命令
1. 配置文件操作
查看当前配置文件:
bashw2 rules
编辑配置文件:
bashw2 edit
导出配置文件:
bashw2 export rules.txt
导入配置文件:
bashw2 import rules.txt
2. 插件管理
安装插件:
bashw2 install plugin-name
卸载插件:
bashw2 uninstall plugin-name
列出已安装插件:
bashw2 list
更新插件:
bashw2 update plugin-name
3. 证书管理
生成根证书:
bashw2 ca
下载根证书:
bashw2 ca download
安装根证书:
bashw2 ca install
卸载根证书:
bashw2 ca uninstall
高级命令
1. 代理配置
设置代理认证:
bashw2 auth username:password
清除代理认证:
bashw2 auth clear
设置代理超时:
bashw2 timeout 30000
设置最大连接数:
bashw2 max-connections 100
2. 日志管理
查看日志:
bashw2 log
查看实时日志:
bashw2 log -f
清空日志:
bashw2 log clear
导出日志:
bashw2 log export log.txt
3. 数据管理
清除所有数据:
bashw2 clean
清除缓存:
bashw2 clean cache
清除日志:
bashw2 clean log
清除配置:
bashw2 clean config
实用技巧
1. 快速启动
创建启动脚本:
start-whistle.sh (Mac/Linux):
bash#!/bin/bash w2 start -p 8899 echo "Whistle started on port 8899"
start-whistle.bat (Windows):
bash@echo off w2 start -p 8899 echo Whistle started on port 8899
使用脚本:
bash./start-whistle.sh
2. 环境切换
创建环境切换脚本:
switch-env.sh:
bash#!/bin/bash ENV=$1 case $ENV in dev) cp ~/.whistle/rules-dev ~/.whistle/rules w2 restart echo "Switched to development environment" ;; test) cp ~/.whistle/rules-test ~/.whistle/rules w2 restart echo "Switched to test environment" ;; prod) cp ~/.whistle/rules-prod ~/.whistle/rules w2 restart echo "Switched to production environment" ;; *) echo "Usage: switch-env.sh {dev|test|prod}" ;; esac
使用脚本:
bash./switch-env.sh dev ./switch-env.sh test ./switch-env.sh prod
3. 自动备份
创建备份脚本:
backup-whistle.sh:
bash#!/bin/bash BACKUP_DIR=~/whistle-backup DATE=$(date +%Y%m%d_%H%M%S) mkdir -p $BACKUP_DIR # 备份配置文件 cp ~/.whistle/rules $BACKUP_DIR/rules_$DATE # 备份插件列表 w2 list > $BACKUP_DIR/plugins_$DATE echo "Backup completed: $BACKUP_DIR"
使用脚本:
bash./backup-whistle.sh
4. 批量操作
批量安装插件:
install-plugins.sh:
bash#!/bin/bash PLUGINS=( "whistle.inspector" "whistle.weinre" "whistle.vase" ) for plugin in "${PLUGINS[@]}"; do echo "Installing $plugin..." w2 install $plugin done echo "All plugins installed"
使用脚本:
bash./install-plugins.sh
命令行调试
1. 调试模式
启动调试模式:
bashw2 start --debug
查看详细日志:
bashw2 log -v
2. 性能分析
查看性能统计:
bashw2 stats
查看内存使用:
bashw2 memory
查看 CPU 使用:
bashw2 cpu
3. 问题诊断
诊断命令:
bashw2 doctor
检查配置:
bashw2 check
验证规则:
bashw2 validate rules
命令行快捷键
1. 常用快捷键
- Ctrl + C:停止当前命令
- Ctrl + L:清屏
- Ctrl + R:搜索历史命令
- ↑ / ↓:浏览历史命令
- Tab:自动补全
2. 命令别名
创建别名:
Mac/Linux (bash):
bash# 添加到 ~/.bashrc alias ws='w2 start' alias wq='w2 stop' alias wr='w2 restart' alias wl='w2 log'
Mac/Linux (zsh):
bash# 添加到 ~/.zshrc alias ws='w2 start' alias wq='w2 stop' alias wr='w2 restart' alias wl='w2 log'
Windows (PowerShell):
powershell# 添加到 $PROFILE function ws { w2 start } function wq { w2 stop } function wr { w2 restart } function wl { w2 log }
最佳实践
-
使用脚本自动化
- 创建常用操作的脚本
- 自动化重复任务
- 提高工作效率
-
定期备份配置
- 使用脚本自动备份
- 保留历史版本
- 便于回滚
-
使用命令别名
- 简化常用命令
- 提高输入速度
- 减少输入错误
-
查看帮助文档
- 使用
-h查看帮助 - 阅读官方文档
- 了解最新功能
- 使用
-
保持命令行更新
- 定期更新 whistle
- 获取新功能
- 修复已知问题