MCPcopy
hub / github.com/cli/cli / listRun

Function listRun

pkg/cmd/repo/deploy-key/list/list.go:55–98  ·  view source on GitHub ↗
(opts *ListOptions)

Source from the content-addressed store, hash-verified

53}
54
55func listRun(opts *ListOptions) error {
56 apiClient, err := opts.HTTPClient()
57 if err != nil {
58 return err
59 }
60
61 repo, err := opts.BaseRepo()
62 if err != nil {
63 return err
64 }
65
66 deployKeys, err := repoKeys(apiClient, repo)
67 if err != nil {
68 return err
69 }
70
71 if len(deployKeys) == 0 {
72 return cmdutil.NewNoResultsError(fmt.Sprintf("no deploy keys found in %s", ghrepo.FullName(repo)))
73 }
74
75 if opts.Exporter != nil {
76 return opts.Exporter.Write(opts.IO, deployKeys)
77 }
78
79 t := tableprinter.New(opts.IO, tableprinter.WithHeader("ID", "TITLE", "TYPE", "KEY", "CREATED AT"))
80 cs := opts.IO.ColorScheme()
81 now := time.Now()
82
83 for _, deployKey := range deployKeys {
84 sshID := strconv.Itoa(deployKey.ID)
85 t.AddField(sshID)
86 t.AddField(deployKey.Title)
87 sshType := "read-only"
88 if !deployKey.ReadOnly {
89 sshType = "read-write"
90 }
91 t.AddField(sshType)
92 t.AddField(deployKey.Key, tableprinter.WithTruncate(truncateMiddle))
93 t.AddTimeField(now, deployKey.CreatedAt, cs.Muted)
94 t.EndRow()
95 }
96
97 return t.Render()
98}
99
100func truncateMiddle(maxWidth int, t string) string {
101 if len(t) <= maxWidth {

Callers 2

TestListRunFunction · 0.70
NewCmdListFunction · 0.70

Calls 10

NewNoResultsErrorFunction · 0.92
FullNameFunction · 0.92
NewFunction · 0.92
WithHeaderFunction · 0.92
repoKeysFunction · 0.85
ColorSchemeMethod · 0.80
AddTimeFieldMethod · 0.80
BaseRepoMethod · 0.65
WriteMethod · 0.65
RenderMethod · 0.65

Tested by 1

TestListRunFunction · 0.56