| 53 | } |
| 54 | |
| 55 | func 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 | |
| 100 | func truncateMiddle(maxWidth int, t string) string { |
| 101 | if len(t) <= maxWidth { |