From 73c60b9f936b19d1cf0e024a164c6c839aedefcc Mon Sep 17 00:00:00 2001 From: mirivlad Date: Tue, 26 May 2026 17:48:13 +0800 Subject: [PATCH] Fix: test with password, group management, vault progress - Test in form now works with password before save (TestConnectionWithPassword) - Groups: show existing groups in form hint, group rename/delete commands - Vault: added progress indicators ('Unlocking vault...', 'Deriving key... done.') - Separate template.go for command template commands --- cmd/group.go | 131 ++++++++++++---------------------------- cmd/template.go | 101 +++++++++++++++++++++++++++++++ cmd/tui.go | 19 ++++++ internal/db/servers.go | 39 ++++++++++++ internal/tui/app.go | 34 ++++++++++- internal/vault/vault.go | 4 ++ 6 files changed, 234 insertions(+), 94 deletions(-) create mode 100644 cmd/template.go diff --git a/cmd/group.go b/cmd/group.go index 075a842..3a4e30e 100644 --- a/cmd/group.go +++ b/cmd/group.go @@ -2,6 +2,7 @@ package cmd import ( "fmt" + "strings" "github.com/spf13/cobra" ) @@ -15,123 +16,71 @@ var groupListCmd = &cobra.Command{ Use: "list", Short: "List server groups", RunE: func(cmd *cobra.Command, args []string) error { - servers, err := appDB.ListServers() + groups, err := appDB.GetGroups() if err != nil { - return fmt.Errorf("list servers: %w", err) - } - - groups := make(map[string]int) - for _, s := range servers { - g := s.GroupName - if g == "" { - g = "(no group)" - } - groups[g]++ + return fmt.Errorf("list groups: %w", err) } if len(groups) == 0 { - fmt.Println("No servers.") + fmt.Println("No groups. Use 'sshkeeper add --group ' to create one.") return nil } - for name, count := range groups { - fmt.Printf(" %-20s %d servers\n", name, count) + for _, g := range groups { + fmt.Printf(" %s\n", g) } return nil }, } -var templateCmd = &cobra.Command{ - Use: "template", - Short: "Command template management", -} - -var templateListCmd = &cobra.Command{ - Use: "list ", - Short: "List command templates for a server", - Args: cobra.ExactArgs(1), - RunE: func(cmd *cobra.Command, args []string) error { - alias := args[0] - _, err := appDB.GetServer(alias) - if err != nil { - return fmt.Errorf("server not found: %s", alias) - } - - templates, err := appDB.GetCommandTemplates(alias) - 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(" %-15s %s\n", t.Name, t.Command) - } - return nil - }, -} - -var templateAddCmd = &cobra.Command{ - Use: "add ", - Short: "Add a command template", - Args: cobra.ExactArgs(3), - RunE: func(cmd *cobra.Command, args []string) error { - alias := args[0] - name := args[1] - command := args[2] - - server, err := appDB.GetServer(alias) - if err != nil { - return fmt.Errorf("server not found: %s", alias) - } - - if err := appDB.AddCommandTemplate(server.ID, name, command); err != nil { - return fmt.Errorf("add template: %w", err) - } - - fmt.Println("Template added.") - return nil - }, -} - -var runTemplateCmd = &cobra.Command{ - Use: "run-template