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