Commit d1f1d2f5 authored by Matt Bell's avatar Matt Bell

core/commands2: Fixed commands to use string arguments

parent f8be2681
......@@ -9,7 +9,6 @@ import (
cmds "github.com/jbenet/go-ipfs/commands"
config "github.com/jbenet/go-ipfs/config"
internal "github.com/jbenet/go-ipfs/core/commands2/internal"
tour "github.com/jbenet/go-ipfs/tour"
)
......@@ -43,14 +42,9 @@ func tourRunFunc(req cmds.Request) (interface{}, error) {
return nil, err
}
strs, err := internal.CastToStrings(req.Arguments())
if err != nil {
return nil, err
}
id := tour.TopicID(cfg.Tour.Last)
if len(strs) > 0 {
id = tour.TopicID(strs[0])
if len(req.Arguments()) > 0 {
id = tour.TopicID(req.Arguments()[0])
}
var w bytes.Buffer
......
......@@ -52,10 +52,7 @@ It outputs to stdout, and <key> is a base58 encoded multihash.
return nil, err
}
key, ok := req.Arguments()[0].(string)
if !ok {
return nil, u.ErrCast()
}
key := req.Arguments()[0]
if !u.IsValidHash(key) {
return nil, cmds.Error{"Not a valid hash", cmds.ErrClient}
......
......@@ -184,16 +184,7 @@ func bootstrapWritePeers(w io.Writer, prefix string, peers []*config.BootstrapPe
return nil
}
func bootstrapInputToPeers(input []interface{}) ([]*config.BootstrapPeer, error) {
inputAddrs := make([]string, len(input))
for i, v := range input {
addr, ok := v.(string)
if !ok {
return nil, u.ErrCast()
}
inputAddrs[i] = addr
}
func bootstrapInputToPeers(input []string) ([]*config.BootstrapPeer, error) {
split := func(addr string) (string, string) {
idx := strings.LastIndex(addr, "/")
if idx == -1 {
......@@ -203,7 +194,7 @@ func bootstrapInputToPeers(input []interface{}) ([]*config.BootstrapPeer, error)
}
peers := []*config.BootstrapPeer{}
for _, addr := range inputAddrs {
for _, addr := range input {
addrS, peeridS := split(addr)
// make sure addrS parses as a multiaddr.
......
......@@ -5,7 +5,6 @@ import (
cmds "github.com/jbenet/go-ipfs/commands"
core "github.com/jbenet/go-ipfs/core"
"github.com/jbenet/go-ipfs/core/commands2/internal"
uio "github.com/jbenet/go-ipfs/unixfs/io"
)
......@@ -29,12 +28,7 @@ it contains.
readers := make([]io.Reader, 0, len(req.Arguments()))
paths, err := internal.CastToStrings(req.Arguments())
if err != nil {
return nil, err
}
readers, err = cat(node, paths)
readers, err = cat(node, req.Arguments())
if err != nil {
return nil, err
}
......
......@@ -55,11 +55,7 @@ Set the value of the 'datastore.path' key:
},
Run: func(req cmds.Request) (interface{}, error) {
args := req.Arguments()
key, ok := args[0].(string)
if !ok {
return nil, u.ErrCast()
}
key := args[0]
filename, err := config.Filename(req.Context().ConfigRoot)
if err != nil {
......@@ -68,12 +64,7 @@ Set the value of the 'datastore.path' key:
var value string
if len(args) == 2 {
var ok bool
value, ok = args[1].(string)
if !ok {
return nil, u.ErrCast()
}
value = args[1]
return setConfig(filename, key, value)
} else {
......
......@@ -31,11 +31,7 @@ output of a running daemon.
Run: func(req cmds.Request) (interface{}, error) {
args := req.Arguments()
subsystem, ok1 := args[0].(string)
level, ok2 := args[1].(string)
if !ok1 || !ok2 {
return nil, u.ErrCast()
}
subsystem, level := args[0], args[1]
if subsystem == logAllKeyword {
subsystem = "*"
......
......@@ -4,7 +4,6 @@ import (
"fmt"
cmds "github.com/jbenet/go-ipfs/commands"
"github.com/jbenet/go-ipfs/core/commands2/internal"
merkledag "github.com/jbenet/go-ipfs/merkledag"
)
......@@ -42,10 +41,7 @@ it contains, with the following format:
return nil, err
}
paths, err := internal.CastToStrings(req.Arguments())
if err != nil {
return nil, err
}
paths := req.Arguments()
dagnodes := make([]*merkledag.Node, 0)
for _, path := range paths {
......
......@@ -12,7 +12,6 @@ import (
cmds "github.com/jbenet/go-ipfs/commands"
core "github.com/jbenet/go-ipfs/core"
dag "github.com/jbenet/go-ipfs/merkledag"
u "github.com/jbenet/go-ipfs/util"
)
// 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.
return nil, err
}
key, ok := req.Arguments()[0].(string)
if !ok {
return nil, u.ErrCast()
}
key := req.Arguments()[0]
return objectData(n, key)
},
}
......@@ -102,11 +97,7 @@ multihash.
return nil, err
}
key, ok := req.Arguments()[0].(string)
if !ok {
return nil, u.ErrCast()
}
key := req.Arguments()[0]
return objectLinks(n, key)
},
Marshalers: cmds.MarshalerMap{
......@@ -148,10 +139,7 @@ This command outputs data in the following encodings:
return nil, err
}
key, ok := req.Arguments()[0].(string)
if !ok {
return nil, u.ErrCast()
}
key := req.Arguments()[0]
object, err := objectGet(n, key)
if err != nil {
......@@ -214,15 +202,12 @@ Data should be in the format specified by <encoding>.
return nil, err
}
input, ok := req.Arguments()[0].(io.Reader)
if !ok {
return nil, u.ErrCast()
input, err := req.Files().NextFile()
if err != nil && err != io.EOF {
return nil, err
}
encoding, ok := req.Arguments()[1].(string)
if !ok {
return nil, u.ErrCast()
}
encoding := req.Arguments()[0]
output, err := objectPut(n, input, encoding)
if err != nil {
......
......@@ -5,7 +5,6 @@ import (
cmds "github.com/jbenet/go-ipfs/commands"
"github.com/jbenet/go-ipfs/core"
"github.com/jbenet/go-ipfs/core/commands2/internal"
"github.com/jbenet/go-ipfs/merkledag"
)
......@@ -50,12 +49,7 @@ on disk.
recursive = false
}
paths, err := internal.CastToStrings(req.Arguments())
if err != nil {
return nil, err
}
_, err = pin(n, paths, recursive)
_, err = pin(n, req.Arguments(), recursive)
if err != nil {
return nil, err
}
......@@ -95,12 +89,7 @@ collected if needed.
recursive = false // default
}
paths, err := internal.CastToStrings(req.Arguments())
if err != nil {
return nil, err
}
_, err = unpin(n, paths, recursive)
_, err = unpin(n, req.Arguments(), recursive)
if err != nil {
return nil, err
}
......
......@@ -67,11 +67,11 @@ Publish a <ref> to another public key:
switch len(args) {
case 2:
// name = args[0]
ref = args[1].(string)
ref = args[1]
return nil, errors.New("keychains not yet implemented")
case 1:
// name = n.Identity.ID.String()
ref = args[0].(string)
ref = args[0]
}
// TODO n.Keychain.Get(name).PrivKey
......
......@@ -6,7 +6,6 @@ import (
mh "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multihash"
cmds "github.com/jbenet/go-ipfs/commands"
"github.com/jbenet/go-ipfs/core"
"github.com/jbenet/go-ipfs/core/commands2/internal"
dag "github.com/jbenet/go-ipfs/merkledag"
u "github.com/jbenet/go-ipfs/util"
)
......@@ -57,12 +56,7 @@ Note: list all refs recursively with -r.
recursive = false
}
paths, err := internal.CastToStrings(req.Arguments())
if err != nil {
return nil, err
}
return getRefs(n, paths, unique, recursive)
return getRefs(n, req.Arguments(), unique, recursive)
},
Type: &RefsOutput{},
Marshalers: cmds.MarshalerMap{
......
......@@ -4,7 +4,6 @@ import (
"errors"
cmds "github.com/jbenet/go-ipfs/commands"
u "github.com/jbenet/go-ipfs/util"
)
var resolveCmd = &cmds.Command{
......@@ -59,11 +58,7 @@ Resolve te value of another name:
name = n.Identity.ID().String()
} else {
var ok bool
name, ok = req.Arguments()[0].(string)
if !ok {
return nil, u.ErrCast()
}
name = req.Arguments()[0]
}
output, err := n.Namesys.Resolve(name)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment