@cryptotaxi247 / kubo / commits / cac6b376c

allow ipfs id to work on self

License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com>

Jeromy committed Oct 18, 2015 at 10:14 UTC cac6b376c3c30cbd2ab7fb84a393400ae3a7a71c
1 file changed +12 -9
core/commands/id.go
+12 -9
@@ -62,7 +62,18 @@ ipfs id supports the format option for output with the following keys:
62 return
63 }
64
65 - if len(req.Arguments()) == 0 {
65 + var id peer.ID
66 + if len(req.Arguments()) > 0 {
67 + id = peer.ID(b58.Decode(req.Arguments()[0]))
68 + if len(id) == 0 {
69 + res.SetError(cmds.ClientError("Invalid peer id"), cmds.ErrClient)
70 + return
71 + }
72 + } else {
73 + id = node.Identity
74 + }
75 +
76 + if id == node.Identity {
77 output, err := printSelf(node)
78 if err != nil {
79 res.SetError(err, cmds.ErrNormal)
@@ -72,14 +83,6 @@ ipfs id supports the format option for output with the following keys:
83 return
84 }
85
75 - pid := req.Arguments()[0]
76 -
77 - id := peer.ID(b58.Decode(pid))
78 - if len(id) == 0 {
79 - res.SetError(cmds.ClientError("Invalid peer id"), cmds.ErrClient)
80 - return
81 - }
82 -
86 // TODO handle offline mode with polymorphism instead of conditionals
87 if !node.OnlineMode() {
88 res.SetError(errors.New(offlineIdErrorMessage), cmds.ErrClient)