sshkeeper: v0.2.0 — Phase 5: Search improvements (notes, tags, route, context)
This commit is contained in:
parent
c2edaa4224
commit
98492799ea
|
|
@ -2,13 +2,14 @@ package cmd
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var searchCmd = &cobra.Command{
|
||||
Use: "search <query>",
|
||||
Short: "Search servers",
|
||||
Short: "Search servers by alias, host, name, group, notes, tags, route",
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
query := args[0]
|
||||
|
|
@ -30,7 +31,24 @@ var searchCmd = &cobra.Command{
|
|||
statusChar = "!"
|
||||
}
|
||||
target := fmt.Sprintf("%s@%s:%d", s.User, s.Host, s.Port)
|
||||
fmt.Printf("[%s] %-20s %s\n", statusChar, s.Alias, target)
|
||||
|
||||
// Show route summary if available
|
||||
routeStr := "direct"
|
||||
if len(s.Route.Hops) > 0 {
|
||||
routeStr = s.Route.DisplaySummary(target)
|
||||
} else if s.ProxyJump != "" {
|
||||
routeStr = "via " + s.ProxyJump
|
||||
}
|
||||
|
||||
fmt.Printf("[%s] %-20s %-30s route: %s", statusChar, s.Alias, target, routeStr)
|
||||
|
||||
if len(s.Tags) > 0 {
|
||||
fmt.Printf(" tags: %s", strings.Join(s.Tags, ", "))
|
||||
}
|
||||
if s.Notes != "" {
|
||||
fmt.Printf(" notes: %s", s.Notes)
|
||||
}
|
||||
fmt.Println()
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
|||
|
|
@ -172,8 +172,9 @@ func (db *DB) SearchServers(query string) ([]*model.Server, error) {
|
|||
created_at, updated_at, last_connected_at,
|
||||
last_test_at, last_test_status, last_test_error
|
||||
FROM servers
|
||||
WHERE alias LIKE ? OR display_name LIKE ? OR host LIKE ? OR user LIKE ? OR group_name LIKE ?
|
||||
ORDER BY alias`, pattern, pattern, pattern, pattern, pattern)
|
||||
WHERE alias LIKE ? OR display_name LIKE ? OR host LIKE ? OR user LIKE ?
|
||||
OR group_name LIKE ? OR notes LIKE ? OR proxy_jump LIKE ?
|
||||
ORDER BY alias`, pattern, pattern, pattern, pattern, pattern, pattern, pattern)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -107,7 +107,20 @@ func (i serverItem) Description() string {
|
|||
return fmt.Sprintf("%s %s", routeStr, i.server.AuthMethod)
|
||||
}
|
||||
func (i serverItem) FilterValue() string {
|
||||
return i.server.Alias + " " + i.server.DisplayName + " " + i.server.Host + " " + i.server.User
|
||||
parts := []string{
|
||||
i.server.Alias,
|
||||
i.server.DisplayName,
|
||||
i.server.Host,
|
||||
i.server.User,
|
||||
i.server.GroupName,
|
||||
i.server.Notes,
|
||||
i.server.ProxyJump,
|
||||
strings.Join(i.server.Tags, " "),
|
||||
}
|
||||
for _, h := range i.server.Route.Hops {
|
||||
parts = append(parts, h.Alias, h.Raw)
|
||||
}
|
||||
return strings.Join(parts, " ")
|
||||
}
|
||||
|
||||
type templateItem struct {
|
||||
|
|
|
|||
Loading…
Reference in New Issue