-
Notifications
You must be signed in to change notification settings - Fork 5
/
list.go
44 lines (37 loc) · 831 Bytes
/
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
package cmd
import (
"fmt"
"os"
"text/tabwriter"
"github.com/spf13/cobra"
)
var listCmd = &cobra.Command{
Use: "list",
Short: "List registered DIDs",
Example: "algoid list",
Aliases: []string{"ls"},
RunE: runListCmd,
}
func init() {
rootCmd.AddCommand(listCmd)
}
func runListCmd(_ *cobra.Command, _ []string) error {
// Get store handler
st, err := getClientStore()
if err != nil {
return err
}
// Get list of entries
list := st.List()
if len(list) == 0 {
log.Warning("no DIDs registered for the moment")
return nil
}
// Show list of registered entries
table := tabwriter.NewWriter(os.Stdout, 8, 0, 4, ' ', tabwriter.TabIndent)
_, _ = fmt.Fprintf(table, "%s\t%s\n", "Name", "DID")
for k, id := range list {
_, _ = fmt.Fprintf(table, "%s\t%s\n", k, id.DID())
}
return table.Flush()
}