Skip to content

Commit cac6b37

Browse files
committedOct 18, 2015
allow ipfs id to work on self
License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com>
1 parent 4de5eaa commit cac6b37

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed
 

‎core/commands/id.go

+12-9
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,18 @@ ipfs id supports the format option for output with the following keys:
6262
return
6363
}
6464

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 {
6677
output, err := printSelf(node)
6778
if err != nil {
6879
res.SetError(err, cmds.ErrNormal)
@@ -72,14 +83,6 @@ ipfs id supports the format option for output with the following keys:
7283
return
7384
}
7485

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-
8386
// TODO handle offline mode with polymorphism instead of conditionals
8487
if !node.OnlineMode() {
8588
res.SetError(errors.New(offlineIdErrorMessage), cmds.ErrClient)

0 commit comments

Comments
 (0)
Please sign in to comment.