forked from plouc/go-gitlab-client
/
ls_namespaces.go
56 lines (44 loc) · 1.13 KB
/
ls_namespaces.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
50
51
52
53
54
55
56
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"
)
var namespacesSearch string
func init() {
lsCmd.AddCommand(lsNamespacesCmd)
lsNamespacesCmd.Flags().StringVarP(&namespacesSearch, "search", "s", "", "Returns a list of namespaces the user is authorized to see based on the search criteria")
}
func fetchNamespaces() {
color.Yellow("Fetching namespaces…")
o := &gitlab.NamespacesOptions{}
o.Page = page
o.PerPage = perPage
if namespacesSearch != "" {
o.Search = namespacesSearch
}
loader.Start()
collection, meta, err := client.Namespaces(o)
loader.Stop()
if err != nil {
fmt.Println(err.Error())
return
}
if len(collection.Items) == 0 {
color.Red("No namespace found")
} else {
out.Namespaces(output, outputFormat, collection)
}
printMeta(meta, true)
handlePaginatedResult(meta, fetchNamespaces)
}
var lsNamespacesCmd = &cobra.Command{
Use: "namespaces",
Aliases: []string{"ns"},
Short: "List namespaces",
Run: func(cmd *cobra.Command, args []string) {
fetchNamespaces()
},
}