1.4 KiB
1.4 KiB
Deployment CLI Tool Example
Complete deployment automation CLI demonstrating:
- Context management with shared state
- Environment validation in Before hook
- Command categories (Build, Deploy, Monitor)
- Confirmation prompts for destructive actions
Usage
# Set environment variables
export DEPLOY_ENV=staging
export AWS_REGION=us-west-2
# Build application
deploy --env staging build
deploy -e production build --tag v1.2.3
# Run tests
deploy --env staging test
# Deploy
deploy --env staging deploy
deploy -e production deploy --auto-approve
# Rollback
deploy --env production rollback
# Monitor
deploy --env production logs --follow
deploy -e staging status
Features Demonstrated
- Context Management: Shared DeployContext across commands
- Environment Validation: Before hook validates target environment
- Required Flags: --env is required for all operations
- Confirmation Prompts: Deploy asks for confirmation (unless --auto-approve)
- Command Categories: Build, Deploy, Monitor
- Environment Variables: DEPLOY_ENV, AWS_REGION fallbacks
- Shared State: Context passed to all commands via metadata
Context Pattern
type DeployContext struct {
Environment string
AWSRegion string
Verbose bool
}
// Store in Before hook
ctx := &DeployContext{...}
c.App.Metadata["ctx"] = ctx
// Retrieve in command
ctx := c.App.Metadata["ctx"].(*DeployContext)