core/commands2: Added argument definitions to 'publish'
Matt Bell committed
Nov 4, 2014 at 23:44 UTC
79b88ee028794436153165bf0a763d5cb240bdee
1 file changed
+9
-8
core/commands2/publish.go
+9
-8
@@ -11,12 +11,16 @@ import (
11
u "github.com/jbenet/go-ipfs/util"
12
)
13
14
-type PublishOutput struct {
14
+type IpnsEntry struct {
15
Name string
16
Value string
17
}
18
19
var publishCmd = &cmds.Command{
20
+ Arguments: []cmds.Argument{
21
+ cmds.Argument{"name", cmds.ArgString, false, false},
22
+ cmds.Argument{"object", cmds.ArgString, true, false},
23
+ },
24
Help: "TODO",
25
Run: func(res cmds.Response, req cmds.Request) {
26
n := req.Context().Node
@@ -39,9 +43,6 @@ var publishCmd = &cmds.Command{
43
case 1:
44
// name = n.Identity.ID.String()
45
ref = args[0].(string)
42
-
43
- default:
44
- res.SetError(fmt.Errorf("Publish expects 1 or 2 args; got %d.", len(args)), cmds.ErrClient)
46
}
47
48
// TODO n.Keychain.Get(name).PrivKey
@@ -56,15 +57,15 @@ var publishCmd = &cmds.Command{
57
},
58
Marshallers: map[cmds.EncodingType]cmds.Marshaller{
59
cmds.Text: func(res cmds.Response) ([]byte, error) {
59
- v := res.Output().(*PublishOutput)
60
+ v := res.Output().(*IpnsEntry)
61
s := fmt.Sprintf("Published name %s to %s\n", v.Name, v.Value)
62
return []byte(s), nil
63
},
64
},
64
- Type: &PublishOutput{},
65
+ Type: &IpnsEntry{},
66
}
67
67
-func publish(n *core.IpfsNode, k crypto.PrivKey, ref string) (*PublishOutput, error) {
68
+func publish(n *core.IpfsNode, k crypto.PrivKey, ref string) (*IpnsEntry, error) {
69
pub := nsys.NewRoutingPublisher(n.Routing)
70
err := pub.Publish(k, ref)
71
if err != nil {
@@ -76,7 +77,7 @@ func publish(n *core.IpfsNode, k crypto.PrivKey, ref string) (*PublishOutput, er
77
return nil, err
78
}
79
79
- return &PublishOutput{
80
+ return &IpnsEntry{
81
Name: u.Key(hash).String(),
82
Value: ref,
83
}, nil