-
Notifications
You must be signed in to change notification settings - Fork 0
/
info.go
46 lines (38 loc) · 995 Bytes
/
info.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 cmd
import (
"encoding/json"
"errors"
"fmt"
"github.com/kennygrant/sanitize"
"github.com/spf13/cobra"
)
var didDetailsCmd = &cobra.Command{
Use: "info",
Short: "Display the current information available on an existing DID",
Example: "didctl info [DID reference name]",
Aliases: []string{"details", "inspect", "view", "doc"},
RunE: runDidDetailsCmd,
}
func init() {
rootCmd.AddCommand(didDetailsCmd)
}
func runDidDetailsCmd(_ *cobra.Command, args []string) error {
if len(args) != 1 {
return errors.New("you must specify a DID reference name")
}
// Get store handler
st, err := getClientStore()
if err != nil {
return err
}
// Retrieve identifier
name := sanitize.Name(args[0])
id, err := st.Get(name)
if err != nil {
return fmt.Errorf("no available record under the provided reference name: %s", name)
}
// Present its LD document as output
info, _ := json.MarshalIndent(id.Document(true), "", " ")
fmt.Printf("%s\n", info)
return nil
}