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

What are the common command-line tools and shortcuts of whistle?

2月21日 16:25

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:

bash
npm install -g whistle

Uninstall whistle:

bash
npm uninstall -g whistle

Update whistle:

bash
npm update -g whistle

2. Start and Stop

Start whistle:

bash
w2 start

Start with specified port:

bash
w2 start -p 8080

Start with specified config file:

bash
w2 start -f custom.rules

Start with specified storage directory:

bash
w2 start -D /path/to/storage

Stop whistle:

bash
w2 stop

Restart whistle:

bash
w2 restart

3. View Status

View running status:

bash
w2 status

View version information:

bash
w2 -v

View help information:

bash
w2 -h

Configuration Management Commands

1. Config File Operations

View current config file:

bash
w2 rules

Edit config file:

bash
w2 edit

Export config file:

bash
w2 export rules.txt

Import config file:

bash
w2 import rules.txt

2. Plugin Management

Install plugin:

bash
w2 install plugin-name

Uninstall plugin:

bash
w2 uninstall plugin-name

List installed plugins:

bash
w2 list

Update plugin:

bash
w2 update plugin-name

3. Certificate Management

Generate root certificate:

bash
w2 ca

Download root certificate:

bash
w2 ca download

Install root certificate:

bash
w2 ca install

Uninstall root certificate:

bash
w2 ca uninstall

Advanced Commands

1. Proxy Configuration

Set proxy authentication:

bash
w2 auth username:password

Clear proxy authentication:

bash
w2 auth clear

Set proxy timeout:

bash
w2 timeout 30000

Set max connections:

bash
w2 max-connections 100

2. Log Management

View logs:

bash
w2 log

View real-time logs:

bash
w2 log -f

Clear logs:

bash
w2 log clear

Export logs:

bash
w2 log export log.txt

3. Data Management

Clear all data:

bash
w2 clean

Clear cache:

bash
w2 clean cache

Clear logs:

bash
w2 clean log

Clear config:

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

bash
w2 start --debug

View verbose logs:

bash
w2 log -v

2. Performance Analysis

View performance stats:

bash
w2 stats

View memory usage:

bash
w2 memory

View CPU usage:

bash
w2 cpu

3. Problem Diagnosis

Diagnosis command:

bash
w2 doctor

Check configuration:

bash
w2 check

Validate rules:

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

  1. Use Script Automation

    • Create scripts for common operations
    • Automate repetitive tasks
    • Improve work efficiency
  2. Regularly Backup Configuration

    • Use scripts for auto backup
    • Keep historical versions
    • Facilitate rollback
  3. Use Command Aliases

    • Simplify common commands
    • Improve input speed
    • Reduce input errors
  4. View Help Documentation

    • Use -h to view help
    • Read official documentation
    • Learn about new features
  5. Keep Command Line Updated

    • Regularly update whistle
    • Get new features
    • Fix known issues
标签:Whistle