forked from plouc/go-gitlab-client
/
ls_ssh_keys.go
49 lines (39 loc) · 909 Bytes
/
ls_ssh_keys.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package cmd
import (
"fmt"
"github.com/fatih/color"
out "github.com/plouc/go-gitlab-client/cli/output"
"github.com/plouc/go-gitlab-client/gitlab"
"github.com/spf13/cobra"
)
func init() {
lsCmd.AddCommand(lsSshKeysCmd)
}
func fetchSshKeys() {
color.Yellow("Fetching current user ssh keys…")
o := &gitlab.PaginationOptions{}
o.Page = page
o.PerPage = perPage
loader.Start()
collection, meta, err := client.CurrentUserSshKeys(o)
loader.Stop()
if err != nil {
fmt.Println(err.Error())
return
}
if len(collection.Items) == 0 {
color.Red("No ssh key found")
} else {
out.SshKeys(output, outputFormat, collection)
}
printMeta(meta, true)
handlePaginatedResult(meta, fetchSshKeys)
}
var lsSshKeysCmd = &cobra.Command{
Use: "ssh-keys",
Aliases: []string{"sk"},
Short: "List current user ssh keys",
Run: func(cmd *cobra.Command, args []string) {
fetchSshKeys()
},
}