Answer
Whistle provides rich command-line tools that can complete most operations through the command line, improving work efficiency.
Basic Commands
1. Installation and Uninstallation
Global install whistle:
bashnpm install -g whistle
Uninstall whistle:
bashnpm uninstall -g whistle
Update whistle:
bashnpm update -g whistle
2. Start and Stop
Start whistle:
bashw2 start
Start with specified port:
bashw2 start -p 8080
Start with specified config file:
bashw2 start -f custom.rules
Start with specified storage directory:
bashw2 start -D /path/to/storage
Stop whistle:
bashw2 stop
Restart whistle:
bashw2 restart
3. View Status
View running status:
bashw2 status
View version information:
bashw2 -v
View help information:
bashw2 -h
Configuration Management Commands
1. Config File Operations
View current config file:
bashw2 rules
Edit config file:
bashw2 edit
Export config file:
bashw2 export rules.txt
Import config file:
bashw2 import rules.txt
2. Plugin Management
Install plugin:
bashw2 install plugin-name
Uninstall plugin:
bashw2 uninstall plugin-name
List installed plugins:
bashw2 list
Update plugin:
bashw2 update plugin-name
3. Certificate Management
Generate root certificate:
bashw2 ca
Download root certificate:
bashw2 ca download
Install root certificate:
bashw2 ca install
Uninstall root certificate:
bashw2 ca uninstall
Advanced Commands
1. Proxy Configuration
Set proxy authentication:
bashw2 auth username:password
Clear proxy authentication:
bashw2 auth clear
Set proxy timeout:
bashw2 timeout 30000
Set max connections:
bashw2 max-connections 100
2. Log Management
View logs:
bashw2 log
View real-time logs:
bashw2 log -f
Clear logs:
bashw2 log clear
Export logs:
bashw2 log export log.txt
3. Data Management
Clear all data:
bashw2 clean
Clear cache:
bashw2 clean cache
Clear logs:
bashw2 clean log
Clear config:
bashw2 clean config
Practical Tips
1. Quick Start
Create startup script:
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
Use script:
bash./start-whistle.sh
2. Environment Switching
Create environment switching script:
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
Use script:
bash./switch-env.sh dev ./switch-env.sh test ./switch-env.sh prod
3. Auto Backup
Create backup script:
backup-whistle.sh:
bash#!/bin/bash BACKUP_DIR=~/whistle-backup DATE=$(date +%Y%m%d_%H%M%S) mkdir -p $BACKUP_DIR # Backup config file cp ~/.whistle/rules $BACKUP_DIR/rules_$DATE # Backup plugin list w2 list > $BACKUP_DIR/plugins_$DATE echo "Backup completed: $BACKUP_DIR"
Use script:
bash./backup-whistle.sh
4. Batch Operations
Batch install plugins:
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"
Use script:
bash./install-plugins.sh
Command Line Debugging
1. Debug Mode
Start debug mode:
bashw2 start --debug
View verbose logs:
bashw2 log -v
2. Performance Analysis
View performance stats:
bashw2 stats
View memory usage:
bashw2 memory
View CPU usage:
bashw2 cpu
3. Problem Diagnosis
Diagnosis command:
bashw2 doctor
Check configuration:
bashw2 check
Validate rules:
bashw2 validate rules
Command Line Shortcuts
1. Common Shortcuts
- Ctrl + C: Stop current command
- Ctrl + L: Clear screen
- Ctrl + R: Search command history
- ↑ / ↓: Browse command history
- Tab: Auto-complete
2. Command Aliases
Create aliases:
Mac/Linux (bash):
bash# Add to ~/.bashrc alias ws='w2 start' alias wq='w2 stop' alias wr='w2 restart' alias wl='w2 log'
Mac/Linux (zsh):
bash# Add to ~/.zshrc alias ws='w2 start' alias wq='w2 stop' alias wr='w2 restart' alias wl='w2 log'
Windows (PowerShell):
powershell# Add to $PROFILE function ws { w2 start } function wq { w2 stop } function wr { w2 restart } function wl { w2 log }
Best Practices
-
Use Script Automation
- Create scripts for common operations
- Automate repetitive tasks
- Improve work efficiency
-
Regularly Backup Configuration
- Use scripts for auto backup
- Keep historical versions
- Facilitate rollback
-
Use Command Aliases
- Simplify common commands
- Improve input speed
- Reduce input errors
-
View Help Documentation
- Use
-hto view help - Read official documentation
- Learn about new features
- Use
-
Keep Command Line Updated
- Regularly update whistle
- Get new features
- Fix known issues