乐闻世界logo
搜索文章和话题

whistle 有哪些常用的命令行工具和快捷操作?

2月21日 16:25

答案

Whistle 提供了丰富的命令行工具,可以通过命令行完成大部分操作,提高工作效率。

基本命令

1. 安装和卸载

全局安装 whistle:

bash
npm install -g whistle

卸载 whistle:

bash
npm uninstall -g whistle

更新 whistle:

bash
npm update -g whistle

2. 启动和停止

启动 whistle:

bash
w2 start

指定端口启动:

bash
w2 start -p 8080

指定配置文件启动:

bash
w2 start -f custom.rules

指定存储目录启动:

bash
w2 start -D /path/to/storage

停止 whistle:

bash
w2 stop

重启 whistle:

bash
w2 restart

3. 查看状态

查看运行状态:

bash
w2 status

查看版本信息:

bash
w2 -v

查看帮助信息:

bash
w2 -h

配置管理命令

1. 配置文件操作

查看当前配置文件:

bash
w2 rules

编辑配置文件:

bash
w2 edit

导出配置文件:

bash
w2 export rules.txt

导入配置文件:

bash
w2 import rules.txt

2. 插件管理

安装插件:

bash
w2 install plugin-name

卸载插件:

bash
w2 uninstall plugin-name

列出已安装插件:

bash
w2 list

更新插件:

bash
w2 update plugin-name

3. 证书管理

生成根证书:

bash
w2 ca

下载根证书:

bash
w2 ca download

安装根证书:

bash
w2 ca install

卸载根证书:

bash
w2 ca uninstall

高级命令

1. 代理配置

设置代理认证:

bash
w2 auth username:password

清除代理认证:

bash
w2 auth clear

设置代理超时:

bash
w2 timeout 30000

设置最大连接数:

bash
w2 max-connections 100

2. 日志管理

查看日志:

bash
w2 log

查看实时日志:

bash
w2 log -f

清空日志:

bash
w2 log clear

导出日志:

bash
w2 log export log.txt

3. 数据管理

清除所有数据:

bash
w2 clean

清除缓存:

bash
w2 clean cache

清除日志:

bash
w2 clean log

清除配置:

bash
w2 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. 调试模式

启动调试模式:

bash
w2 start --debug

查看详细日志:

bash
w2 log -v

2. 性能分析

查看性能统计:

bash
w2 stats

查看内存使用:

bash
w2 memory

查看 CPU 使用:

bash
w2 cpu

3. 问题诊断

诊断命令:

bash
w2 doctor

检查配置:

bash
w2 check

验证规则:

bash
w2 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 }

最佳实践

  1. 使用脚本自动化

    • 创建常用操作的脚本
    • 自动化重复任务
    • 提高工作效率
  2. 定期备份配置

    • 使用脚本自动备份
    • 保留历史版本
    • 便于回滚
  3. 使用命令别名

    • 简化常用命令
    • 提高输入速度
    • 减少输入错误
  4. 查看帮助文档

    • 使用 -h 查看帮助
    • 阅读官方文档
    • 了解最新功能
  5. 保持命令行更新

    • 定期更新 whistle
    • 获取新功能
    • 修复已知问题
标签:Whistle