fix(ssh-key): title keys by their comment and recognize private keys

ssh-key create - required --title although the key carries a comment,
and a private key failed with "supply exactly one valid SSH public key".
The title now defaults to the key comment, then the computer's name, the
file argument is optional (stdin when piped), and a private key points to
its .pub file. Adding a registered key names the key it duplicates.

ssh-key list shows ID, TITLE, FINGERPRINT and ADDED with a header, view
shows the key instead of its list row, delete asks with the key's title
and fingerprint, and mutations print ✓ lines. create gains the gh alias
add and -t for --title, key IDs complete, and every command has examples.

Signed-off-by: bircni <bircni@icloud.com>
This commit is contained in:
bircni committed 2026-10-11 23:42:49 +02:00
1 parent ab3e91acd1
commit f21c05ead4
5 files changed
+292 -85

No files matched your search

+9 -8
View File
@@ -5,6 +5,7 @@ package services
import (
"context"
"net/http"
gitea "gitea.dev/sdk"
"gitea.dev/tea/internal/transport"
@@ -27,15 +28,15 @@ func sshKeyFrom(key *gitea.PublicKey) SSHKey {
// SSHKeys manages public keys for the authenticated account.
type SSHKeys struct{ Client *transport.Client }
// List returns a non-nil page of public keys.
func (s SSHKeys) List(ctx context.Context, limit, page int) ([]SSHKey, error) {
keys, _, err := call(ctx, s.Client, func(ctx context.Context, c *gitea.Client) ([]*gitea.PublicKey, *gitea.Response, error) {
return c.Users.ListMyPublicKeys(ctx, gitea.ListPublicKeysOptions{ListOptions: listOptions(limit, page)})
// List returns a page of public keys.
func (s SSHKeys) List(ctx context.Context, limit, page int) (Page[SSHKey], error) {
keys, err := listPage(limit, page, func(limit, page int) ([]*gitea.PublicKey, http.Header, error) {
keys, resp, err := call(ctx, s.Client, func(ctx context.Context, c *gitea.Client) ([]*gitea.PublicKey, *gitea.Response, error) {
return c.Users.ListMyPublicKeys(ctx, gitea.ListPublicKeysOptions{ListOptions: listOptions(limit, page)})
})
return keys, headerOf(resp), err
})
if err != nil {
return nil, err
}
return convertAll(keys, sshKeyFrom), nil
return convertPage(keys, sshKeyFrom), err
}
// View retrieves a public key by ID.