# Revoke CLI
Command-line tool for managing Revoke microservices infrastructure.
## Installation
```bash
cargo install --path .
```
## Usage
### Service Management
```bash
# List all services
revoke service list
# Register a new service
revoke service register my-service -a 127.0.0.1 -p 8080 -t api -t v1
# Deregister a service
revoke service deregister service-id
# Get service details
revoke service info my-service
# Check service health
revoke service check my-service
```
### Configuration Management
```bash
# Get configuration value
revoke config get database.url
# Set configuration value
revoke config set database.url "postgres://localhost/mydb"
# Delete configuration
revoke config delete database.url
# List configurations
revoke config list --prefix database
# Watch configuration changes
revoke config watch database.url
# Export configuration
revoke config export -o config.yaml -f yaml
# Import configuration
revoke config import config.yaml
```
### Gateway Management
```bash
# List routes
revoke gateway routes
# Add a route
revoke gateway add-route /api/users user-service -m GET -m POST
# Remove a route
revoke gateway remove-route route-id
# View statistics
revoke gateway stats
# Test configuration
revoke gateway test -c gateway.yaml
```
### Distributed Tracing
```bash
# List recent traces
revoke trace list -r 1h -l 100
# Get trace details
revoke trace get trace-id
# Search traces
revoke trace search "error" -r 24h
# Export traces
revoke trace export traces.json -f json -r 1h
```
### Health Monitoring
```bash
# Check system health
revoke health check --detailed
# Check specific service
revoke health service my-service
# Monitor health status
revoke health monitor -i 5 -s user-service -s order-service
```
### Project Management
```bash
# Initialize a new project
revoke init my-project --template microservice
# Start development environment
revoke dev --all
# Start specific services
revoke dev -s user-service -s order-service
```
## Configuration
The CLI tool can be configured through:
1. Command-line flag `--config`
2. Environment variable `REVOKE_CONFIG`
3. Default config file `~/.config/revoke/config.toml`
Example configuration file:
```toml
consul_address = "http://localhost:8500"
config_namespace = "revoke"
trace_endpoint = "http://localhost:4317"
default_timeout = 30
```
## Global Options
- `-c, --config <FILE>`: Specify config file
- `-v, --verbose`: Increase verbosity (can be used multiple times)
## Output Formats
Many commands support different output formats:
- `table`: Table format (default)
- `json`: JSON format
- `yaml`: YAML format
Example:
```bash
revoke service list --format json
```
## Environment Variables
- `REVOKE_CONFIG`: Config file path
- `CONSUL_ADDR`: Consul address
- `RUST_LOG`: Log level
## Examples
### Complete Service Deployment Workflow
```bash
# 1. Initialize project
revoke init my-service --template microservice
# 2. Change to project directory
cd my-service
# 3. Start development environment
revoke dev --all
# 4. Check service status
revoke service list
revoke health check
# 5. Configure service
revoke config set my-service.database.url "postgres://localhost/mydb"
revoke config set my-service.cache.ttl "300"
# 6. View service traces
revoke trace list -s my-service
```
### Monitoring and Debugging
```bash
# Real-time health monitoring
revoke health monitor --all
# View gateway statistics
revoke gateway stats
# Search error traces
revoke trace search "status_code:500" -r 1h
# Export configuration backup
revoke config export -o backup.yaml
```
## Project Templates
The `init` command supports several templates:
- `basic`: Minimal Rust project
- `microservice`: Service with HTTP API
- `gateway`: API gateway project
- `full-stack`: Complete microservices setup
### Template Features
#### Microservice Template
- Axum HTTP server
- Service registration
- Health endpoints
- Configuration integration
- Distributed tracing
#### Gateway Template
- Pingora-based gateway
- Route configuration
- Load balancing setup
- Circuit breaker configuration
#### Full-stack Template
- Multiple services
- Gateway configuration
- Docker Compose setup
- Development scripts
## Advanced Usage
### Custom Commands
Create custom commands by extending the CLI:
```rust
use clap::Parser;
use revoke_cli::commands::CustomCommand;
#[derive(Parser)]
struct MyCommand {
#[arg(short, long)]
name: String,
}
impl CustomCommand for MyCommand {
async fn execute(&self) -> Result<()> {
println!("Hello, {}!", self.name);
Ok(())
}
}
```
### Scripting
The CLI is designed to be scriptable:
```bash
#!/bin/bash
# Deploy script
for service in $services; do
echo "Checking $service..."
revoke service check $service
if [ $? -ne 0 ]; then
echo "Service $service is unhealthy!"
exit 1
fi
done
echo "All services are healthy!"
```
## Troubleshooting
### Common Issues
1. **Connection refused**: Check if Consul is running
2. **Service not found**: Verify service name and registration
3. **Permission denied**: Check file permissions for config files
4. **Command not found**: Ensure `~/.cargo/bin` is in PATH
### Debug Mode
Enable debug logging:
```bash
RUST_LOG=debug revoke service list
```
### Getting Help
```bash
# General help
revoke --help
# Command-specific help
revoke service --help
revoke service list --help
```