diff options
Diffstat (limited to 'internal/crud/cli_new.go')
| -rw-r--r-- | internal/crud/cli_new.go | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/internal/crud/cli_new.go b/internal/crud/cli_new.go index 8823c4f..8e56490 100644 --- a/internal/crud/cli_new.go +++ b/internal/crud/cli_new.go @@ -184,10 +184,8 @@ func PromptRecipientKeys(defaultPubKeyBytes []byte) ([][]byte, bool, error) { if addMore { for { - fmt.Println("Enter public keys (comma-separated for multiple):") - fmt.Println("Examples: ~/keys/bob.pub, ./tommy.key") - fmt.Println(" ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AA..., ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAZ...") - fmt.Println(" bob@github, james@gitlab") + fmt.Println("Enter public keys (\033[1mcomma-separated for multiple\033[0m):") + fmt.Println("Example: ~/keys/bob.pub, ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AA..., bob@github, james@gitlab") fmt.Print("Public Keys: ") utils.StdinScanner.Scan() if err := utils.StdinScanner.Err(); err != nil { @@ -205,8 +203,6 @@ func PromptRecipientKeys(defaultPubKeyBytes []byte) ([][]byte, bool, error) { continue } - var keyBytes []byte - if strings.Contains(part, "@") && !strings.HasPrefix(part, "ssh-") { parts := strings.Split(part, "@") if len(parts) != 2 { @@ -214,22 +210,31 @@ func PromptRecipientKeys(defaultPubKeyBytes []byte) ([][]byte, bool, error) { } username, service := parts[0], parts[1] - keyBytes, err = utils.GetPubKeyFromService(username, service) + body, err := utils.GetPubKeyFromService(username, service) if err != nil { return nil, false, fmt.Errorf("failed to get public key from %s: %v", part, err) } + selectedKeys, err := selectServiceKeys(part, body) + if err != nil { + fmt.Printf("Warning: %s: %v\n", service, err) + continue + } + for _, k := range selectedKeys { + pubKeys = append(pubKeys, bytes.TrimSpace(k)) + } + continue } + var keyBytes []byte if strings.HasPrefix(part, "ssh-") { keyBytes = []byte(part) - } else if len(keyBytes) == 0 { + } else { var err error keyBytes, err = os.ReadFile(part) if err != nil { return nil, false, fmt.Errorf("failed to read public key file %s: %v", part, err) } } - pubKeys = append(pubKeys, bytes.TrimSpace(keyBytes)) } |