-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlist_keys.go
46 lines (40 loc) · 964 Bytes
/
list_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
package main
import (
"encoding/json"
"fmt"
"net/http"
"os"
"github.com/encloud-tech/encloud/pkg/api"
"github.com/encloud-tech/encloud/pkg/types"
"github.com/spf13/cobra"
)
func ListKeysCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "keys",
Short: "List keys",
Long: `List generated keys with number of associated files`,
Run: func(cmd *cobra.Command, args []string) {
keys, err := api.ListKeys()
if err != nil {
fmt.Fprintf(cmd.OutOrStderr(), err.Error())
os.Exit(-1)
}
response := types.ListKeysResponse{
Status: "success",
StatusCode: http.StatusCreated,
Message: "Keys fetched successfully.",
Data: keys,
}
encoded, err := json.MarshalIndent(response, "", " ")
if err != nil {
fmt.Fprintf(cmd.OutOrStderr(), err.Error())
os.Exit(-1)
}
fmt.Fprintf(cmd.OutOrStdout(), string(encoded))
},
}
return cmd
}
func init() {
RootCmd.AddCommand(ListKeysCmd())
}