package main
import (
"fmt"
"os"
"github.com/raystack/salt/cli/commander"
"github.com/spf13/cobra"
)
func main() {
// Create root command
rootCmd := &cobra.Command{
Use: "mycli",
Short: "A modern CLI application",
Long: `A CLI tool with rich features including help topics and hooks.`,
}
// Add commands
deployCmd := &cobra.Command{
Use: "deploy",
Short: "Deploy your application",
Annotations: map[string]string{
"group": "core",
"client": "true",
},
RunE: func(cmd *cobra.Command, args []string) error {
return deploy()
},
}
rootCmd.AddCommand(deployCmd)
// Create manager with features
manager := commander.New(
rootCmd,
commander.WithTopics([]commander.HelpTopic{
{
Name: "environment",
Short: "Environment variables reference",
Long: "Available environment variables:\n API_KEY - Your API key\n DEBUG - Enable debug mode",
Example: "API_KEY=xxx DEBUG=true mycli deploy",
},
}),
commander.WithHooks([]commander.HookBehavior{
{
Name: "client-setup",
Behavior: func(cmd *cobra.Command) {
cmd.PreRunE = func(cmd *cobra.Command, args []string) error {
fmt.Println("Setting up client...")
return nil
}
},
},
}),
)
// Initialize all features
manager.Init()
// Execute
if err := rootCmd.Execute(); err != nil {
if commander.IsCommandErr(err) {
os.Exit(1)
}
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
os.Exit(1)
}
}
func deploy() error {
fmt.Println("Deploying application...")
return nil
}