🤖 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:
77
cmd/cli/main.go
Normal file
77
cmd/cli/main.go
Normal file
@@ -0,0 +1,77 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"DanceLessonsCoach/pkg/config"
|
||||
"DanceLessonsCoach/pkg/server"
|
||||
"DanceLessonsCoach/pkg/version"
|
||||
"github.com/rs/zerolog/log"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var rootCmd = &cobra.Command{
|
||||
Use: "dance-lessons-coach",
|
||||
Short: "DanceLessonsCoach - API server and CLI tools",
|
||||
Long: `DanceLessonsCoach provides greeting services and API management.
|
||||
|
||||
To begin working with DanceLessonsCoach, run:
|
||||
dance-lessons-coach server --help`,
|
||||
SilenceUsage: true,
|
||||
}
|
||||
|
||||
var versionCmd = &cobra.Command{
|
||||
Use: "version",
|
||||
Short: "Print version information",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
fmt.Println(version.Full())
|
||||
},
|
||||
}
|
||||
|
||||
var serverCmd = &cobra.Command{
|
||||
Use: "server",
|
||||
Short: "Start the DanceLessonsCoach server",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
// Load config and start server
|
||||
cfg, err := config.LoadConfig()
|
||||
if err != nil {
|
||||
log.Fatal().Err(err).Msg("Failed to load configuration")
|
||||
}
|
||||
server := server.NewServer(cfg, context.Background())
|
||||
if err := server.Run(); err != nil {
|
||||
log.Fatal().Err(err).Msg("Server failed")
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
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)")
|
||||
serverCmd.Flags().Bool("debug", false, "Enable debug logging")
|
||||
}
|
||||
|
||||
func main() {
|
||||
if err := rootCmd.Execute(); err != nil {
|
||||
log.Fatal().Err(err).Msg("CLI execution failed")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user