A command-line tool for monitoring and managing Shopware applications with deployment telemetry.
- Execute deployment commands with transparent output
- Capture command execution metrics (output, return code, execution time)
- Read composer.json dependencies and include in telemetry
- Send telemetry data to monitoring service
- Support for custom monitoring endpoint via environment variable
- Authorization token support for secure telemetry submission
./shopmon-cli deploy -- <command># Execute a simple command
./shopmon-cli deploy -- echo "Hello World"
# Run PHP artisan commands
./shopmon-cli deploy -- php artisan migrate
# Execute composer commands
./shopmon-cli deploy -- composer install
# Multiple word commands
./shopmon-cli deploy -- npm run buildSHOPMON_BASE_URL: Override the default monitoring service URL (default:https://shopmon.fos.gg)SHOPMON_DEPLOY_TOKEN: Authorization token for the monitoring service (sent as Bearer token)
# With custom URL
SHOPMON_BASE_URL="http://localhost:8080" ./shopmon-cli deploy -- php artisan migrate
# With authorization token
SHOPMON_DEPLOY_TOKEN="your-secret-token" ./shopmon-cli deploy -- composer install
# With both URL and token
SHOPMON_BASE_URL="http://staging.example.com" \
SHOPMON_DEPLOY_TOKEN="staging-token" \
./shopmon-cli deploy -- npm run buildThe deploy command sends the following JSON payload to the monitoring service endpoint (/api/cli/deployment):
{
"command": "php foo",
"output": "the full output of the command",
"return_code": 0,
"start_date": "2024-06-01T12:00:00Z",
"end_date": "2024-06-01T12:00:01Z",
"execution_time": 1.23,
"composer": {
"php": ">=8.1",
"shopware/core": "6.5.0.0"
}
}When SHOPMON_DEPLOY_TOKEN is set, the request includes an Authorization: Bearer <token> header for authentication.
shopmon-cli/
├── cmd/ # Command definitions
│ ├── root.go
│ └── deploy.go
├── internal/
│ └── deployment/ # Core deployment logic
│ ├── types.go # Data structures
│ ├── executor.go # Command execution
│ ├── composer.go # Composer.json parsing
│ ├── telemetry.go # Telemetry client
│ ├── deployment.go # Main service orchestration
│ └── *_test.go # Unit tests
├── main.go
├── go.mod
└── go.sum
# Run all tests
go test ./...
# Run tests with coverage
go test -v ./internal/deployment/... -cover
# Run tests with coverage report
go test -v ./internal/deployment/... -coverprofile=coverage.out
go tool cover -html=coverage.outCurrent test coverage: 93.5%
# Build the binary
go build -o shopmon-cli .
# Build for different platforms
GOOS=linux GOARCH=amd64 go build -o shopmon-cli-linux
GOOS=darwin GOARCH=amd64 go build -o shopmon-cli-darwin
GOOS=windows GOARCH=amd64 go build -o shopmon-cli.exeThe application follows clean architecture principles with clear separation of concerns:
- cmd/: Contains the CLI command definitions using Cobra
- internal/deployment/: Core business logic separated into:
- Interfaces:
CommandExecutor,ComposerReader,TelemetryClientfor dependency injection and testing - Service: Main orchestration layer that coordinates between components
- Implementations: Default implementations of interfaces
- Mocks: Test doubles for unit testing
- Interfaces:
- Dependency Injection: All major components are injected as interfaces, making the code highly testable
- Transparent Execution: Command output is displayed in real-time to the user
- Error Resilience: Telemetry failures don't affect command execution
- Exit Code Preservation: The CLI exits with the same code as the executed command
The codebase includes comprehensive unit tests using the testify library:
- Command parsing and execution
- Composer.json reading and parsing
- Telemetry payload creation and sending
- Service orchestration
- Mock implementations for all interfaces
MIT