-
Notifications
You must be signed in to change notification settings - Fork 6
/
list.go
55 lines (45 loc) · 1.73 KB
/
list.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
package certmanager
import (
"context"
"fmt"
"github.com/ionos-cloud/ionosctl/v6/internal/constants"
"github.com/ionos-cloud/ionosctl/v6/internal/core"
"github.com/ionos-cloud/ionosctl/v6/internal/printer/json2table/jsonpaths"
"github.com/ionos-cloud/ionosctl/v6/internal/printer/jsontabwriter"
"github.com/ionos-cloud/ionosctl/v6/internal/printer/tabheaders"
"github.com/spf13/cobra"
)
func CertListCmd() *core.Command {
cmd := core.NewCommand(context.TODO(), nil, core.CommandBuilder{
Namespace: "certmanager",
Resource: "certificates",
Verb: "list",
Aliases: []string{"l"},
ShortDesc: "List all Certificates",
LongDesc: "Use this command to retrieve all Certificates.",
Example: "ionosctl certificate-manager list",
PreCmdRun: core.NoPreRun,
CmdRun: CmdList,
InitClient: true,
})
cmd.Command.Flags().StringSlice(constants.ArgCols, nil, tabheaders.ColsMessage(defaultCertificateCols))
_ = cmd.Command.RegisterFlagCompletionFunc(constants.ArgCols, func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
return defaultCertificateCols, cobra.ShellCompDirectiveNoFileComp
})
return cmd
}
func CmdList(c *core.CommandConfig) error {
fmt.Fprintf(c.Command.Command.ErrOrStderr(), jsontabwriter.GenerateVerboseOutput("Getting Certificates..."))
certs, _, err := c.CertificateManagerServices.Certs().List()
if err != nil {
return err
}
cols, _ := c.Command.Command.Flags().GetStringSlice(constants.ArgCols)
out, err := jsontabwriter.GenerateOutput("items", jsonpaths.CertManagerCertificate, certs,
tabheaders.GetHeadersAllDefault(defaultCertificateCols, cols))
if err != nil {
return err
}
fmt.Fprintf(c.Command.Command.OutOrStdout(), out)
return nil
}