MCPcopy Index your code
hub / github.com/cli/cli / listRun

Function listRun

pkg/cmd/ssh-key/list/list.go:49–104  ·  view source on GitHub ↗
(opts *ListOptions)

Source from the content-addressed store, hash-verified

47}
48
49func listRun(opts *ListOptions) error {
50 apiClient, err := opts.HTTPClient()
51 if err != nil {
52 return err
53 }
54
55 cfg, err := opts.Config()
56 if err != nil {
57 return err
58 }
59
60 host, _ := cfg.Authentication().DefaultHost()
61 sshAuthKeys, authKeyErr := shared.UserKeys(apiClient, host, "")
62 if authKeyErr != nil {
63 printError(opts.IO.ErrOut, authKeyErr)
64 }
65
66 sshSigningKeys, signKeyErr := shared.UserSigningKeys(apiClient, host, "")
67 if signKeyErr != nil {
68 printError(opts.IO.ErrOut, signKeyErr)
69 }
70
71 if authKeyErr != nil && signKeyErr != nil {
72 return cmdutil.SilentError
73 }
74
75 sshKeys := append(sshAuthKeys, sshSigningKeys...)
76
77 if len(sshKeys) == 0 {
78 return cmdutil.NewNoResultsError("no SSH keys present in the GitHub account")
79 }
80
81 t := tableprinter.New(opts.IO, tableprinter.WithHeader("TITLE", "ID", "KEY", "TYPE", "ADDED"))
82 cs := opts.IO.ColorScheme()
83 now := time.Now()
84
85 for _, sshKey := range sshKeys {
86 id := strconv.FormatInt(sshKey.ID, 10)
87 if t.IsTTY() {
88 t.AddField(sshKey.Title)
89 t.AddField(id)
90 t.AddField(sshKey.Key, tableprinter.WithTruncate(truncateMiddle))
91 t.AddField(sshKey.Type)
92 t.AddTimeField(now, sshKey.CreatedAt, cs.Muted)
93 } else {
94 t.AddField(sshKey.Title)
95 t.AddField(sshKey.Key)
96 t.AddTimeField(now, sshKey.CreatedAt, cs.Muted)
97 t.AddField(id)
98 t.AddField(sshKey.Type)
99 }
100 t.EndRow()
101 }
102
103 return t.Render()
104}
105
106func truncateMiddle(maxWidth int, t string) string {

Callers 2

TestListRunFunction · 0.70
NewCmdListFunction · 0.70

Calls 13

UserKeysFunction · 0.92
UserSigningKeysFunction · 0.92
NewNoResultsErrorFunction · 0.92
NewFunction · 0.92
WithHeaderFunction · 0.92
ColorSchemeMethod · 0.80
IsTTYMethod · 0.80
AddTimeFieldMethod · 0.80
printErrorFunction · 0.70
ConfigMethod · 0.65
DefaultHostMethod · 0.65
AuthenticationMethod · 0.65

Tested by 1

TestListRunFunction · 0.56