🤖 feat: implement Cobra CLI with subcommands

- Add new CLI structure in cmd/cli/
- Implement version, server, and greet commands
- Update build script to compile new CLI binary
- Add Cobra dependency to go.mod
- Update ADR 0015 to reflect implementation status
- Update README and AGENTS.md with CLI usage
- Maintain backward compatibility with existing binaries

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
2026-04-05 11:33:13 +02:00
parent a5344d6ed8
commit 4d0c3a748e
7 changed files with 189 additions and 15 deletions

View File

@@ -1,10 +1,10 @@
# 15. CLI Subcommands and Flag Management with Cobra
**Date:** 2026-04-05
**Status:** 🟡 Proposed
**Status:** ✅ Implemented
**Authors:** DanceLessonsCoach Team
**Decision Date:** TBD
**Implementation Status:** Not Started
**Decision Date:** 2026-04-05
**Implementation Status:** Phase 1 Complete
## Context
@@ -44,7 +44,10 @@ We will adopt **Cobra** as our CLI framework. Cobra is a mature, widely-used lib
### Implementation Plan
#### Phase 1: Basic Integration (Next Sprint)
#### Phase 1: Basic Integration (✅ COMPLETED)
**Implemented in:** `cmd/cli/main.go`
```go
var rootCmd = &cobra.Command{
Use: "dance-lessons-coach",
@@ -80,10 +83,24 @@ var serverCmd = &cobra.Command{
},
}
var greetCmd = &cobra.Command{
Use: "greet [name]",
Short: "Greet someone by name",
Args: cobra.MaximumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
name := ""
if len(args) > 0 {
name = args[0]
}
fmt.Printf("Hello %s!\n", name)
},
}
func init() {
rootCmd.AddCommand(versionCmd)
rootCmd.AddCommand(serverCmd)
rootCmd.AddCommand(greetCmd)
// Add flags to server command
serverCmd.Flags().String("config", "", "Config file path")
serverCmd.Flags().String("env", "", "Environment (dev, staging, prod)")
@@ -97,6 +114,19 @@ func main() {
}
```
**Current Commands:**
- `version`: Print version information
- `server`: Start the DanceLessonsCoach server
- `greet [name]`: Greet someone by name
- `help`: Built-in help system
- `completion`: Shell completion scripts (automatic)
**Current Flags:**
- `--config`: Config file path (server command)
- `--env`: Environment (dev, staging, prod) (server command)
- `--debug`: Enable debug logging (server command)
- `--help`: Help for any command (built-in)
#### Phase 2: Advanced Features (Future)
- **Subcommand groups**: `server`, `db`, `migrate`, `tools`
- **Persistent flags**: Global flags like `--config`, `--env`
@@ -170,10 +200,10 @@ dance-lessons-coach config validate
-**Integration**: Works with existing config system
**What's still needed?**
- **Implementation**: Actual cobra integration
-**Migration**: Move existing flags to cobra
-**Documentation**: Update docs with new CLI
-**Testing**: Ensure all functionality works
- **Implementation**: Actual cobra integration (Phase 1 complete)
-**Migration**: Move existing flags to cobra (Phase 2)
-**Documentation**: Update docs with new CLI (Phase 2)
-**Testing**: Ensure all functionality works (Phase 2)
### Future Enhancements