core/commands2: Fixed commands to use string arguments
Matt Bell committed
Nov 16, 2014 at 23:28 UTC
d1f1d2f5bf2adcc726856de0c681b24ba8fc6651
12 files changed
+23
-101
cmd/ipfs2/tour.go
+2
-8
@@ -9,7 +9,6 @@ import (
9
10
cmds "github.com/jbenet/go-ipfs/commands"
11
config "github.com/jbenet/go-ipfs/config"
12
- internal "github.com/jbenet/go-ipfs/core/commands2/internal"
12
tour "github.com/jbenet/go-ipfs/tour"
13
)
14
@@ -43,14 +42,9 @@ func tourRunFunc(req cmds.Request) (interface{}, error) {
42
return nil, err
43
}
44
46
- strs, err := internal.CastToStrings(req.Arguments())
47
- if err != nil {
48
- return nil, err
49
- }
50
-
45
id := tour.TopicID(cfg.Tour.Last)
52
- if len(strs) > 0 {
53
- id = tour.TopicID(strs[0])
46
+ if len(req.Arguments()) > 0 {
47
+ id = tour.TopicID(req.Arguments()[0])
48
}
49
50
var w bytes.Buffer
core/commands2/block.go
+1
-4
@@ -52,10 +52,7 @@ It outputs to stdout, and <key> is a base58 encoded multihash.
52
return nil, err
53
}
54
55
- key, ok := req.Arguments()[0].(string)
56
- if !ok {
57
- return nil, u.ErrCast()
58
- }
55
+ key := req.Arguments()[0]
56
57
if !u.IsValidHash(key) {
58
return nil, cmds.Error{"Not a valid hash", cmds.ErrClient}
core/commands2/bootstrap.go
+2
-11
@@ -184,16 +184,7 @@ func bootstrapWritePeers(w io.Writer, prefix string, peers []*config.BootstrapPe
184
return nil
185
}
186
187
-func bootstrapInputToPeers(input []interface{}) ([]*config.BootstrapPeer, error) {
188
- inputAddrs := make([]string, len(input))
189
- for i, v := range input {
190
- addr, ok := v.(string)
191
- if !ok {
192
- return nil, u.ErrCast()
193
- }
194
- inputAddrs[i] = addr
195
- }
196
-
187
+func bootstrapInputToPeers(input []string) ([]*config.BootstrapPeer, error) {
188
split := func(addr string) (string, string) {
189
idx := strings.LastIndex(addr, "/")
190
if idx == -1 {
@@ -203,7 +194,7 @@ func bootstrapInputToPeers(input []interface{}) ([]*config.BootstrapPeer, error)
194
}
195
196
peers := []*config.BootstrapPeer{}
206
- for _, addr := range inputAddrs {
197
+ for _, addr := range input {
198
addrS, peeridS := split(addr)
199
200
// make sure addrS parses as a multiaddr.
core/commands2/cat.go
+1
-7
@@ -5,7 +5,6 @@ import (
5
6
cmds "github.com/jbenet/go-ipfs/commands"
7
core "github.com/jbenet/go-ipfs/core"
8
- "github.com/jbenet/go-ipfs/core/commands2/internal"
8
uio "github.com/jbenet/go-ipfs/unixfs/io"
9
)
10
@@ -29,12 +28,7 @@ it contains.
28
29
readers := make([]io.Reader, 0, len(req.Arguments()))
30
32
- paths, err := internal.CastToStrings(req.Arguments())
33
- if err != nil {
34
- return nil, err
35
- }
36
-
37
- readers, err = cat(node, paths)
31
+ readers, err = cat(node, req.Arguments())
32
if err != nil {
33
return nil, err
34
}
core/commands2/config.go
+2
-11
@@ -55,11 +55,7 @@ Set the value of the 'datastore.path' key:
55
},
56
Run: func(req cmds.Request) (interface{}, error) {
57
args := req.Arguments()
58
-
59
- key, ok := args[0].(string)
60
- if !ok {
61
- return nil, u.ErrCast()
62
- }
58
+ key := args[0]
59
60
filename, err := config.Filename(req.Context().ConfigRoot)
61
if err != nil {
@@ -68,12 +64,7 @@ Set the value of the 'datastore.path' key:
64
65
var value string
66
if len(args) == 2 {
71
- var ok bool
72
- value, ok = args[1].(string)
73
- if !ok {
74
- return nil, u.ErrCast()
75
- }
76
-
67
+ value = args[1]
68
return setConfig(filename, key, value)
69
70
} else {
core/commands2/log.go
+1
-5
@@ -31,11 +31,7 @@ output of a running daemon.
31
Run: func(req cmds.Request) (interface{}, error) {
32
33
args := req.Arguments()
34
- subsystem, ok1 := args[0].(string)
35
- level, ok2 := args[1].(string)
36
- if !ok1 || !ok2 {
37
- return nil, u.ErrCast()
38
- }
34
+ subsystem, level := args[0], args[1]
35
36
if subsystem == logAllKeyword {
37
subsystem = "*"
core/commands2/ls.go
+1
-5
@@ -4,7 +4,6 @@ import (
4
"fmt"
5
6
cmds "github.com/jbenet/go-ipfs/commands"
7
- "github.com/jbenet/go-ipfs/core/commands2/internal"
7
merkledag "github.com/jbenet/go-ipfs/merkledag"
8
)
9
@@ -42,10 +41,7 @@ it contains, with the following format:
41
return nil, err
42
}
43
45
- paths, err := internal.CastToStrings(req.Arguments())
46
- if err != nil {
47
- return nil, err
48
- }
44
+ paths := req.Arguments()
45
46
dagnodes := make([]*merkledag.Node, 0)
47
for _, path := range paths {
core/commands2/object.go
+7
-22
@@ -12,7 +12,6 @@ import (
12
cmds "github.com/jbenet/go-ipfs/commands"
13
core "github.com/jbenet/go-ipfs/core"
14
dag "github.com/jbenet/go-ipfs/merkledag"
15
- u "github.com/jbenet/go-ipfs/util"
15
)
16
17
// ErrObjectTooLarge is returned when too much data was read from stdin. current limit 512k
@@ -74,11 +73,7 @@ output is the raw data of the object.
73
return nil, err
74
}
75
77
- key, ok := req.Arguments()[0].(string)
78
- if !ok {
79
- return nil, u.ErrCast()
80
- }
81
-
76
+ key := req.Arguments()[0]
77
return objectData(n, key)
78
},
79
}
@@ -102,11 +97,7 @@ multihash.
97
return nil, err
98
}
99
105
- key, ok := req.Arguments()[0].(string)
106
- if !ok {
107
- return nil, u.ErrCast()
108
- }
109
-
100
+ key := req.Arguments()[0]
101
return objectLinks(n, key)
102
},
103
Marshalers: cmds.MarshalerMap{
@@ -148,10 +139,7 @@ This command outputs data in the following encodings:
139
return nil, err
140
}
141
151
- key, ok := req.Arguments()[0].(string)
152
- if !ok {
153
- return nil, u.ErrCast()
154
- }
142
+ key := req.Arguments()[0]
143
144
object, err := objectGet(n, key)
145
if err != nil {
@@ -214,15 +202,12 @@ Data should be in the format specified by <encoding>.
202
return nil, err
203
}
204
217
- input, ok := req.Arguments()[0].(io.Reader)
218
- if !ok {
219
- return nil, u.ErrCast()
205
+ input, err := req.Files().NextFile()
206
+ if err != nil && err != io.EOF {
207
+ return nil, err
208
}
209
222
- encoding, ok := req.Arguments()[1].(string)
223
- if !ok {
224
- return nil, u.ErrCast()
225
- }
210
+ encoding := req.Arguments()[0]
211
212
output, err := objectPut(n, input, encoding)
213
if err != nil {
core/commands2/pin.go
+2
-13
@@ -5,7 +5,6 @@ import (
5
6
cmds "github.com/jbenet/go-ipfs/commands"
7
"github.com/jbenet/go-ipfs/core"
8
- "github.com/jbenet/go-ipfs/core/commands2/internal"
8
"github.com/jbenet/go-ipfs/merkledag"
9
)
10
@@ -50,12 +49,7 @@ on disk.
49
recursive = false
50
}
51
53
- paths, err := internal.CastToStrings(req.Arguments())
54
- if err != nil {
55
- return nil, err
56
- }
57
-
58
- _, err = pin(n, paths, recursive)
52
+ _, err = pin(n, req.Arguments(), recursive)
53
if err != nil {
54
return nil, err
55
}
@@ -95,12 +89,7 @@ collected if needed.
89
recursive = false // default
90
}
91
98
- paths, err := internal.CastToStrings(req.Arguments())
99
- if err != nil {
100
- return nil, err
101
- }
102
-
103
- _, err = unpin(n, paths, recursive)
92
+ _, err = unpin(n, req.Arguments(), recursive)
93
if err != nil {
94
return nil, err
95
}
core/commands2/publish.go
+2
-2
@@ -67,11 +67,11 @@ Publish a <ref> to another public key:
67
switch len(args) {
68
case 2:
69
// name = args[0]
70
- ref = args[1].(string)
70
+ ref = args[1]
71
return nil, errors.New("keychains not yet implemented")
72
case 1:
73
// name = n.Identity.ID.String()
74
- ref = args[0].(string)
74
+ ref = args[0]
75
}
76
77
// TODO n.Keychain.Get(name).PrivKey
core/commands2/refs.go
+1
-7
@@ -6,7 +6,6 @@ import (
6
mh "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multihash"
7
cmds "github.com/jbenet/go-ipfs/commands"
8
"github.com/jbenet/go-ipfs/core"
9
- "github.com/jbenet/go-ipfs/core/commands2/internal"
9
dag "github.com/jbenet/go-ipfs/merkledag"
10
u "github.com/jbenet/go-ipfs/util"
11
)
@@ -57,12 +56,7 @@ Note: list all refs recursively with -r.
56
recursive = false
57
}
58
60
- paths, err := internal.CastToStrings(req.Arguments())
61
- if err != nil {
62
- return nil, err
63
- }
64
-
65
- return getRefs(n, paths, unique, recursive)
59
+ return getRefs(n, req.Arguments(), unique, recursive)
60
},
61
Type: &RefsOutput{},
62
Marshalers: cmds.MarshalerMap{
core/commands2/resolve.go
+1
-6
@@ -4,7 +4,6 @@ import (
4
"errors"
5
6
cmds "github.com/jbenet/go-ipfs/commands"
7
- u "github.com/jbenet/go-ipfs/util"
7
)
8
9
var resolveCmd = &cmds.Command{
@@ -59,11 +58,7 @@ Resolve te value of another name:
58
name = n.Identity.ID().String()
59
60
} else {
62
- var ok bool
63
- name, ok = req.Arguments()[0].(string)
64
- if !ok {
65
- return nil, u.ErrCast()
66
- }
61
+ name = req.Arguments()[0]
62
}
63
64
output, err := n.Namesys.Resolve(name)