package cmd import ( "fmt" "github.com/mirivlad/sshkeeper/internal/model" "github.com/spf13/cobra" ) var templateCmd = &cobra.Command{ Use: "template", Short: "Global command template management", } var templateListCmd = &cobra.Command{ Use: "list", Short: "List global command templates", Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { templates, err := appDB.ListCommandTemplates() if err != nil { return fmt.Errorf("list templates: %w", err) } if len(templates) == 0 { fmt.Println("No command templates.") return nil } for _, t := range templates { fmt.Printf(" %-20s %s\n", t.Name, t.Command) } return nil }, } var templateAddCmd = &cobra.Command{ Use: "add ", Short: "Add a global command template", Args: cobra.ExactArgs(2), RunE: func(cmd *cobra.Command, args []string) error { t := &model.CommandTemplate{Name: args[0], Command: args[1]} if err := appDB.CreateCommandTemplate(t); err != nil { return fmt.Errorf("add template: %w", err) } fmt.Println("Template added.") return nil }, } var templateEditCmd = &cobra.Command{ Use: "edit ", Short: "Edit a global command template", Args: cobra.ExactArgs(3), RunE: func(cmd *cobra.Command, args []string) error { t := &model.CommandTemplate{Name: args[1], Command: args[2]} if err := appDB.UpdateCommandTemplate(args[0], t); err != nil { return fmt.Errorf("edit template: %w", err) } fmt.Println("Template saved.") return nil }, } var templateDeleteCmd = &cobra.Command{ Use: "delete ", Short: "Delete a global command template", Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { if err := appDB.DeleteCommandTemplate(args[0]); err != nil { return fmt.Errorf("delete template: %w", err) } fmt.Println("Template deleted.") return nil }, } var runTemplateCmd = &cobra.Command{ Use: "run-template