/
organizations.go
47 lines (39 loc) · 1.12 KB
/
organizations.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
package main
import (
"context"
"github.com/krystal/go-katapult"
"github.com/krystal/go-katapult/core"
"github.com/spf13/cobra"
)
type organisationsListClient interface {
List(
ctx context.Context,
) ([]*core.Organization, *katapult.Response, error)
}
const organizationsListFormat = `{{ Table (StringSlice "Name" "Subdomain") (MultipleRows . "Name" "SubDomain") }}`
func organizationsCmd(client organisationsListClient) *cobra.Command {
cmd := &cobra.Command{
Use: "org",
Aliases: []string{"orgs", "organization", "organizations"},
Short: "Manage organizations",
Long: "Get information about and manage organizations.",
}
list := &cobra.Command{
Use: "list",
Aliases: []string{"ls"},
Short: "Get list of organizations",
Long: "Get list of organizations.",
RunE: outputWrapper(func(cmd *cobra.Command, args []string) (Output, error) {
orgs, _, err := client.List(cmd.Context())
if err != nil {
return nil, err
}
return &genericOutput{
item: orgs,
defaultTextTemplate: organizationsListFormat,
}, nil
}),
}
cmd.AddCommand(list)
return cmd
}