-
Notifications
You must be signed in to change notification settings - Fork 4
/
list.go
48 lines (39 loc) · 867 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
45
46
47
48
package keys
import (
"fmt"
"io/ioutil"
"path/filepath"
"strings"
"github.com/mosaicnetworks/monetd/src/configuration"
"github.com/spf13/cobra"
)
// newListCmd returns the command that lists keyfiles
func newListCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "list",
Short: "list keyfiles",
Long: "List keyfiles in [datadir]/keystore.",
RunE: list,
}
return cmd
}
// list prints all the *.json files in [datadir]/keystore
func list(cmd *cobra.Command, args []string) error {
keystore := filepath.Join(configuration.Global.DataDir, "keystore")
files, err := ioutil.ReadDir(keystore)
if err != nil {
fmt.Println(err)
return nil
}
for _, file := range files {
if filepath.Ext(file.Name()) == ".json" {
fmt.Println(
strings.TrimSuffix(
file.Name(),
filepath.Ext(file.Name()),
),
)
}
}
return nil
}