mirror of
https://github.com/ipfs/kubo.git
synced 2026-03-05 16:28:06 +08:00
Merge pull request #4826 from ipfs/fix/rm-string-arguments
upgrade commands that used StringArguments
This commit is contained in:
commit
7f1868aef2
@ -57,7 +57,7 @@ operations.
|
||||
},
|
||||
Subcommands: map[string]*cmds.Command{
|
||||
"read": lgc.NewCommand(filesReadCmd),
|
||||
"write": lgc.NewCommand(filesWriteCmd),
|
||||
"write": filesWriteCmd,
|
||||
"mv": lgc.NewCommand(filesMvCmd),
|
||||
"cp": lgc.NewCommand(filesCpCmd),
|
||||
"ls": lgc.NewCommand(filesLsCmd),
|
||||
@ -654,7 +654,7 @@ Example:
|
||||
},
|
||||
}
|
||||
|
||||
var filesWriteCmd = &oldcmds.Command{
|
||||
var filesWriteCmd = &cmds.Command{
|
||||
Helptext: cmdkit.HelpText{
|
||||
Tagline: "Write to a mutable file in a given filesystem.",
|
||||
ShortDescription: `
|
||||
@ -701,43 +701,39 @@ stat' on the file or any of its ancestors.
|
||||
cidVersionOption,
|
||||
hashOption,
|
||||
},
|
||||
Run: func(req oldcmds.Request, res oldcmds.Response) {
|
||||
path, err := checkPath(req.StringArguments()[0])
|
||||
Run: func(req *cmds.Request, re cmds.ResponseEmitter, env cmds.Environment) {
|
||||
path, err := checkPath(req.Arguments[0])
|
||||
if err != nil {
|
||||
res.SetError(err, cmdkit.ErrNormal)
|
||||
re.SetError(err, cmdkit.ErrNormal)
|
||||
return
|
||||
}
|
||||
|
||||
create, _, _ := req.Option("create").Bool()
|
||||
trunc, _, _ := req.Option("truncate").Bool()
|
||||
flush, _, _ := req.Option("flush").Bool()
|
||||
rawLeaves, rawLeavesDef, _ := req.Option("raw-leaves").Bool()
|
||||
create, _ := req.Options["create"].(bool)
|
||||
trunc, _ := req.Options["truncate"].(bool)
|
||||
flush, _ := req.Options["flush"].(bool)
|
||||
rawLeaves, rawLeavesDef := req.Options["raw-leaves"].(bool)
|
||||
|
||||
prefix, err := getPrefix(req)
|
||||
prefix, err := getPrefixNew(req)
|
||||
if err != nil {
|
||||
res.SetError(err, cmdkit.ErrNormal)
|
||||
re.SetError(err, cmdkit.ErrNormal)
|
||||
return
|
||||
}
|
||||
|
||||
nd, err := req.InvocContext().GetNode()
|
||||
nd, err := GetNode(env)
|
||||
if err != nil {
|
||||
res.SetError(err, cmdkit.ErrNormal)
|
||||
re.SetError(err, cmdkit.ErrNormal)
|
||||
return
|
||||
}
|
||||
|
||||
offset, _, err := req.Option("offset").Int()
|
||||
if err != nil {
|
||||
res.SetError(err, cmdkit.ErrNormal)
|
||||
return
|
||||
}
|
||||
offset, _ := req.Options["offset"].(int)
|
||||
if offset < 0 {
|
||||
res.SetError(fmt.Errorf("cannot have negative write offset"), cmdkit.ErrNormal)
|
||||
re.SetError(fmt.Errorf("cannot have negative write offset"), cmdkit.ErrNormal)
|
||||
return
|
||||
}
|
||||
|
||||
fi, err := getFileHandle(nd.FilesRoot, path, create, prefix)
|
||||
if err != nil {
|
||||
res.SetError(err, cmdkit.ErrNormal)
|
||||
re.SetError(err, cmdkit.ErrNormal)
|
||||
return
|
||||
}
|
||||
if rawLeavesDef {
|
||||
@ -746,44 +742,40 @@ stat' on the file or any of its ancestors.
|
||||
|
||||
wfd, err := fi.Open(mfs.OpenWriteOnly, flush)
|
||||
if err != nil {
|
||||
res.SetError(err, cmdkit.ErrNormal)
|
||||
re.SetError(err, cmdkit.ErrNormal)
|
||||
return
|
||||
}
|
||||
|
||||
defer func() {
|
||||
err := wfd.Close()
|
||||
if err != nil {
|
||||
res.SetError(err, cmdkit.ErrNormal)
|
||||
re.SetError(err, cmdkit.ErrNormal)
|
||||
}
|
||||
}()
|
||||
|
||||
if trunc {
|
||||
if err := wfd.Truncate(0); err != nil {
|
||||
res.SetError(err, cmdkit.ErrNormal)
|
||||
re.SetError(err, cmdkit.ErrNormal)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
count, countfound, err := req.Option("count").Int()
|
||||
if err != nil {
|
||||
res.SetError(err, cmdkit.ErrNormal)
|
||||
return
|
||||
}
|
||||
count, countfound := req.Options["count"].(int)
|
||||
if countfound && count < 0 {
|
||||
res.SetError(fmt.Errorf("cannot have negative byte count"), cmdkit.ErrNormal)
|
||||
re.SetError(fmt.Errorf("cannot have negative byte count"), cmdkit.ErrNormal)
|
||||
return
|
||||
}
|
||||
|
||||
_, err = wfd.Seek(int64(offset), io.SeekStart)
|
||||
if err != nil {
|
||||
flog.Error("seekfail: ", err)
|
||||
res.SetError(err, cmdkit.ErrNormal)
|
||||
re.SetError(err, cmdkit.ErrNormal)
|
||||
return
|
||||
}
|
||||
|
||||
input, err := req.Files().NextFile()
|
||||
input, err := req.Files.NextFile()
|
||||
if err != nil {
|
||||
res.SetError(err, cmdkit.ErrNormal)
|
||||
re.SetError(err, cmdkit.ErrNormal)
|
||||
return
|
||||
}
|
||||
|
||||
@ -794,11 +786,9 @@ stat' on the file or any of its ancestors.
|
||||
|
||||
_, err = io.Copy(wfd, r)
|
||||
if err != nil {
|
||||
res.SetError(err, cmdkit.ErrNormal)
|
||||
re.SetError(err, cmdkit.ErrNormal)
|
||||
return
|
||||
}
|
||||
|
||||
res.SetOutput(nil)
|
||||
},
|
||||
}
|
||||
|
||||
@ -1072,6 +1062,35 @@ Remove files or directories.
|
||||
},
|
||||
}
|
||||
|
||||
func getPrefixNew(req *cmds.Request) (*cid.Prefix, error) {
|
||||
cidVer, cidVerSet := req.Options["cid-version"].(int)
|
||||
hashFunStr, hashFunSet := req.Options["hash"].(string)
|
||||
|
||||
if !cidVerSet && !hashFunSet {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
if hashFunSet && cidVer == 0 {
|
||||
cidVer = 1
|
||||
}
|
||||
|
||||
prefix, err := dag.PrefixForCidVersion(cidVer)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if hashFunSet {
|
||||
hashFunCode, ok := mh.Names[strings.ToLower(hashFunStr)]
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unrecognized hash function: %s", strings.ToLower(hashFunStr))
|
||||
}
|
||||
prefix.MhType = hashFunCode
|
||||
prefix.MhLength = -1
|
||||
}
|
||||
|
||||
return &prefix, nil
|
||||
}
|
||||
|
||||
func getPrefix(req oldcmds.Request) (*cid.Prefix, error) {
|
||||
cidVer, cidVerSet, _ := req.Option("cid-version").Int()
|
||||
hashFunStr, hashFunSet, _ := req.Option("hash").String()
|
||||
|
||||
@ -13,7 +13,8 @@ import (
|
||||
"strings"
|
||||
"text/tabwriter"
|
||||
|
||||
cmds "github.com/ipfs/go-ipfs/commands"
|
||||
oldcmds "github.com/ipfs/go-ipfs/commands"
|
||||
lgc "github.com/ipfs/go-ipfs/commands/legacy"
|
||||
core "github.com/ipfs/go-ipfs/core"
|
||||
e "github.com/ipfs/go-ipfs/core/commands/e"
|
||||
dag "github.com/ipfs/go-ipfs/merkledag"
|
||||
@ -21,6 +22,7 @@ import (
|
||||
pin "github.com/ipfs/go-ipfs/pin"
|
||||
ft "github.com/ipfs/go-ipfs/unixfs"
|
||||
|
||||
cmds "gx/ipfs/QmabLouZTZwhfALuBcssPvkzhbYGMb4394huT7HY4LQ6d3/go-ipfs-cmds"
|
||||
cid "gx/ipfs/QmcZfnkapfECQGcLZaf9B79NRg7cRa9EnZh4LSbkCzwNvY/go-cid"
|
||||
cmdkit "gx/ipfs/QmceUdzxkimdYsgtX733uNgzf1DLHyBKN6ehGSp85ayppM/go-ipfs-cmdkit"
|
||||
ipld "gx/ipfs/Qme5bWv7wtjUNGsK2BNGVUFPKiuxWrsqrtvYwCLRw8YFES/go-ipld-format"
|
||||
@ -55,18 +57,18 @@ directly.`,
|
||||
},
|
||||
|
||||
Subcommands: map[string]*cmds.Command{
|
||||
"data": ObjectDataCmd,
|
||||
"diff": ObjectDiffCmd,
|
||||
"get": ObjectGetCmd,
|
||||
"links": ObjectLinksCmd,
|
||||
"new": ObjectNewCmd,
|
||||
"data": lgc.NewCommand(ObjectDataCmd),
|
||||
"diff": lgc.NewCommand(ObjectDiffCmd),
|
||||
"get": lgc.NewCommand(ObjectGetCmd),
|
||||
"links": lgc.NewCommand(ObjectLinksCmd),
|
||||
"new": lgc.NewCommand(ObjectNewCmd),
|
||||
"patch": ObjectPatchCmd,
|
||||
"put": ObjectPutCmd,
|
||||
"stat": ObjectStatCmd,
|
||||
"put": lgc.NewCommand(ObjectPutCmd),
|
||||
"stat": lgc.NewCommand(ObjectStatCmd),
|
||||
},
|
||||
}
|
||||
|
||||
var ObjectDataCmd = &cmds.Command{
|
||||
var ObjectDataCmd = &oldcmds.Command{
|
||||
Helptext: cmdkit.HelpText{
|
||||
Tagline: "Output the raw bytes of an IPFS object.",
|
||||
ShortDescription: `
|
||||
@ -85,7 +87,7 @@ is the raw data of the object.
|
||||
Arguments: []cmdkit.Argument{
|
||||
cmdkit.StringArg("key", true, false, "Key of the object to retrieve, in base58-encoded multihash format.").EnableStdin(),
|
||||
},
|
||||
Run: func(req cmds.Request, res cmds.Response) {
|
||||
Run: func(req oldcmds.Request, res oldcmds.Response) {
|
||||
n, err := req.InvocContext().GetNode()
|
||||
if err != nil {
|
||||
res.SetError(err, cmdkit.ErrNormal)
|
||||
@ -114,7 +116,7 @@ is the raw data of the object.
|
||||
},
|
||||
}
|
||||
|
||||
var ObjectLinksCmd = &cmds.Command{
|
||||
var ObjectLinksCmd = &oldcmds.Command{
|
||||
Helptext: cmdkit.HelpText{
|
||||
Tagline: "Output the links pointed to by the specified object.",
|
||||
ShortDescription: `
|
||||
@ -130,7 +132,7 @@ multihash.
|
||||
Options: []cmdkit.Option{
|
||||
cmdkit.BoolOption("headers", "v", "Print table headers (Hash, Size, Name)."),
|
||||
},
|
||||
Run: func(req cmds.Request, res cmds.Response) {
|
||||
Run: func(req oldcmds.Request, res oldcmds.Response) {
|
||||
n, err := req.InvocContext().GetNode()
|
||||
if err != nil {
|
||||
res.SetError(err, cmdkit.ErrNormal)
|
||||
@ -157,8 +159,8 @@ multihash.
|
||||
}
|
||||
res.SetOutput(output)
|
||||
},
|
||||
Marshalers: cmds.MarshalerMap{
|
||||
cmds.Text: func(res cmds.Response) (io.Reader, error) {
|
||||
Marshalers: oldcmds.MarshalerMap{
|
||||
oldcmds.Text: func(res oldcmds.Response) (io.Reader, error) {
|
||||
v, err := unwrapOutput(res.Output())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -185,7 +187,7 @@ multihash.
|
||||
Type: Object{},
|
||||
}
|
||||
|
||||
var ObjectGetCmd = &cmds.Command{
|
||||
var ObjectGetCmd = &oldcmds.Command{
|
||||
Helptext: cmdkit.HelpText{
|
||||
Tagline: "Get and serialize the DAG node named by <key>.",
|
||||
ShortDescription: `
|
||||
@ -208,7 +210,7 @@ This command outputs data in the following encodings:
|
||||
Arguments: []cmdkit.Argument{
|
||||
cmdkit.StringArg("key", true, false, "Key of the object to retrieve, in base58-encoded multihash format.").EnableStdin(),
|
||||
},
|
||||
Run: func(req cmds.Request, res cmds.Response) {
|
||||
Run: func(req oldcmds.Request, res oldcmds.Response) {
|
||||
n, err := req.InvocContext().GetNode()
|
||||
if err != nil {
|
||||
res.SetError(err, cmdkit.ErrNormal)
|
||||
@ -245,8 +247,8 @@ This command outputs data in the following encodings:
|
||||
res.SetOutput(node)
|
||||
},
|
||||
Type: Node{},
|
||||
Marshalers: cmds.MarshalerMap{
|
||||
cmds.Protobuf: func(res cmds.Response) (io.Reader, error) {
|
||||
Marshalers: oldcmds.MarshalerMap{
|
||||
oldcmds.Protobuf: func(res oldcmds.Response) (io.Reader, error) {
|
||||
v, err := unwrapOutput(res.Output())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -272,7 +274,7 @@ This command outputs data in the following encodings:
|
||||
},
|
||||
}
|
||||
|
||||
var ObjectStatCmd = &cmds.Command{
|
||||
var ObjectStatCmd = &oldcmds.Command{
|
||||
Helptext: cmdkit.HelpText{
|
||||
Tagline: "Get stats for the DAG node named by <key>.",
|
||||
ShortDescription: `
|
||||
@ -290,7 +292,7 @@ var ObjectStatCmd = &cmds.Command{
|
||||
Arguments: []cmdkit.Argument{
|
||||
cmdkit.StringArg("key", true, false, "Key of the object to retrieve, in base58-encoded multihash format.").EnableStdin(),
|
||||
},
|
||||
Run: func(req cmds.Request, res cmds.Response) {
|
||||
Run: func(req oldcmds.Request, res oldcmds.Response) {
|
||||
n, err := req.InvocContext().GetNode()
|
||||
if err != nil {
|
||||
res.SetError(err, cmdkit.ErrNormal)
|
||||
@ -314,8 +316,8 @@ var ObjectStatCmd = &cmds.Command{
|
||||
res.SetOutput(ns)
|
||||
},
|
||||
Type: ipld.NodeStat{},
|
||||
Marshalers: cmds.MarshalerMap{
|
||||
cmds.Text: func(res cmds.Response) (io.Reader, error) {
|
||||
Marshalers: oldcmds.MarshalerMap{
|
||||
oldcmds.Text: func(res oldcmds.Response) (io.Reader, error) {
|
||||
v, err := unwrapOutput(res.Output())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -341,7 +343,7 @@ var ObjectStatCmd = &cmds.Command{
|
||||
},
|
||||
}
|
||||
|
||||
var ObjectPutCmd = &cmds.Command{
|
||||
var ObjectPutCmd = &oldcmds.Command{
|
||||
Helptext: cmdkit.HelpText{
|
||||
Tagline: "Store input as a DAG object, print its key.",
|
||||
ShortDescription: `
|
||||
@ -388,7 +390,7 @@ And then run:
|
||||
cmdkit.BoolOption("pin", "Pin this object when adding."),
|
||||
cmdkit.BoolOption("quiet", "q", "Write minimal output."),
|
||||
},
|
||||
Run: func(req cmds.Request, res cmds.Response) {
|
||||
Run: func(req oldcmds.Request, res oldcmds.Response) {
|
||||
n, err := req.InvocContext().GetNode()
|
||||
if err != nil {
|
||||
res.SetError(err, cmdkit.ErrNormal)
|
||||
@ -444,8 +446,8 @@ And then run:
|
||||
|
||||
res.SetOutput(&Object{Hash: objectCid.String()})
|
||||
},
|
||||
Marshalers: cmds.MarshalerMap{
|
||||
cmds.Text: func(res cmds.Response) (io.Reader, error) {
|
||||
Marshalers: oldcmds.MarshalerMap{
|
||||
oldcmds.Text: func(res oldcmds.Response) (io.Reader, error) {
|
||||
quiet, _, _ := res.Request().Option("quiet").Bool()
|
||||
|
||||
v, err := unwrapOutput(res.Output())
|
||||
@ -468,7 +470,7 @@ And then run:
|
||||
Type: Object{},
|
||||
}
|
||||
|
||||
var ObjectNewCmd = &cmds.Command{
|
||||
var ObjectNewCmd = &oldcmds.Command{
|
||||
Helptext: cmdkit.HelpText{
|
||||
Tagline: "Create a new object from an ipfs template.",
|
||||
ShortDescription: `
|
||||
@ -487,7 +489,7 @@ Available templates:
|
||||
Arguments: []cmdkit.Argument{
|
||||
cmdkit.StringArg("template", false, false, "Template to use. Optional."),
|
||||
},
|
||||
Run: func(req cmds.Request, res cmds.Response) {
|
||||
Run: func(req oldcmds.Request, res oldcmds.Response) {
|
||||
n, err := req.InvocContext().GetNode()
|
||||
if err != nil {
|
||||
res.SetError(err, cmdkit.ErrNormal)
|
||||
@ -512,8 +514,8 @@ Available templates:
|
||||
}
|
||||
res.SetOutput(&Object{Hash: node.Cid().String()})
|
||||
},
|
||||
Marshalers: cmds.MarshalerMap{
|
||||
cmds.Text: func(res cmds.Response) (io.Reader, error) {
|
||||
Marshalers: oldcmds.MarshalerMap{
|
||||
oldcmds.Text: func(res oldcmds.Response) (io.Reader, error) {
|
||||
v, err := unwrapOutput(res.Output())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@ -1,11 +1,13 @@
|
||||
package objectcmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"strings"
|
||||
|
||||
cmds "github.com/ipfs/go-ipfs/commands"
|
||||
oldcmds "github.com/ipfs/go-ipfs/commands"
|
||||
lgc "github.com/ipfs/go-ipfs/commands/legacy"
|
||||
core "github.com/ipfs/go-ipfs/core"
|
||||
e "github.com/ipfs/go-ipfs/core/commands/e"
|
||||
dag "github.com/ipfs/go-ipfs/merkledag"
|
||||
@ -14,6 +16,7 @@ import (
|
||||
ft "github.com/ipfs/go-ipfs/unixfs"
|
||||
|
||||
logging "gx/ipfs/QmRb5jh8z2E8hMGN2tkvs1yHynUanqnZ3UeKwgN1i9P1F8/go-log"
|
||||
cmds "gx/ipfs/QmabLouZTZwhfALuBcssPvkzhbYGMb4394huT7HY4LQ6d3/go-ipfs-cmds"
|
||||
cmdkit "gx/ipfs/QmceUdzxkimdYsgtX733uNgzf1DLHyBKN6ehGSp85ayppM/go-ipfs-cmdkit"
|
||||
)
|
||||
|
||||
@ -31,13 +34,13 @@ result. This is the Merkle-DAG version of modifying an object.
|
||||
Arguments: []cmdkit.Argument{},
|
||||
Subcommands: map[string]*cmds.Command{
|
||||
"append-data": patchAppendDataCmd,
|
||||
"add-link": patchAddLinkCmd,
|
||||
"rm-link": patchRmLinkCmd,
|
||||
"set-data": patchSetDataCmd,
|
||||
"add-link": lgc.NewCommand(patchAddLinkCmd),
|
||||
"rm-link": lgc.NewCommand(patchRmLinkCmd),
|
||||
"set-data": lgc.NewCommand(patchSetDataCmd),
|
||||
},
|
||||
}
|
||||
|
||||
func objectMarshaler(res cmds.Response) (io.Reader, error) {
|
||||
func objectMarshaler(res oldcmds.Response) (io.Reader, error) {
|
||||
v, err := unwrapOutput(res.Output())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -70,60 +73,63 @@ the limit will not be respected by the network.
|
||||
cmdkit.StringArg("root", true, false, "The hash of the node to modify."),
|
||||
cmdkit.FileArg("data", true, false, "Data to append.").EnableStdin(),
|
||||
},
|
||||
Run: func(req cmds.Request, res cmds.Response) {
|
||||
nd, err := req.InvocContext().GetNode()
|
||||
Run: func(req *cmds.Request, re cmds.ResponseEmitter, env cmds.Environment) {
|
||||
nd, err := GetNode(env)
|
||||
if err != nil {
|
||||
res.SetError(err, cmdkit.ErrNormal)
|
||||
re.SetError(err, cmdkit.ErrNormal)
|
||||
return
|
||||
}
|
||||
|
||||
root, err := path.ParsePath(req.StringArguments()[0])
|
||||
root, err := path.ParsePath(req.Arguments[0])
|
||||
if err != nil {
|
||||
res.SetError(err, cmdkit.ErrNormal)
|
||||
re.SetError(err, cmdkit.ErrNormal)
|
||||
return
|
||||
}
|
||||
|
||||
rootnd, err := core.Resolve(req.Context(), nd.Namesys, nd.Resolver, root)
|
||||
rootnd, err := core.Resolve(req.Context, nd.Namesys, nd.Resolver, root)
|
||||
if err != nil {
|
||||
res.SetError(err, cmdkit.ErrNormal)
|
||||
re.SetError(err, cmdkit.ErrNormal)
|
||||
return
|
||||
}
|
||||
|
||||
rtpb, ok := rootnd.(*dag.ProtoNode)
|
||||
if !ok {
|
||||
res.SetError(dag.ErrNotProtobuf, cmdkit.ErrNormal)
|
||||
re.SetError(dag.ErrNotProtobuf, cmdkit.ErrNormal)
|
||||
return
|
||||
}
|
||||
|
||||
fi, err := req.Files().NextFile()
|
||||
fi, err := req.Files.NextFile()
|
||||
if err != nil {
|
||||
res.SetError(err, cmdkit.ErrNormal)
|
||||
re.SetError(err, cmdkit.ErrNormal)
|
||||
return
|
||||
}
|
||||
|
||||
data, err := ioutil.ReadAll(fi)
|
||||
if err != nil {
|
||||
res.SetError(err, cmdkit.ErrNormal)
|
||||
re.SetError(err, cmdkit.ErrNormal)
|
||||
return
|
||||
}
|
||||
|
||||
rtpb.SetData(append(rtpb.Data(), data...))
|
||||
|
||||
err = nd.DAG.Add(req.Context(), rtpb)
|
||||
err = nd.DAG.Add(req.Context, rtpb)
|
||||
if err != nil {
|
||||
res.SetError(err, cmdkit.ErrNormal)
|
||||
re.SetError(err, cmdkit.ErrNormal)
|
||||
return
|
||||
}
|
||||
|
||||
res.SetOutput(&Object{Hash: rtpb.Cid().String()})
|
||||
cmds.EmitOnce(re, &Object{Hash: rtpb.Cid().String()})
|
||||
},
|
||||
Type: Object{},
|
||||
Marshalers: cmds.MarshalerMap{
|
||||
cmds.Text: objectMarshaler,
|
||||
Encoders: cmds.EncoderMap{
|
||||
cmds.Text: cmds.MakeTypedEncoder(func(req *cmds.Request, w io.Writer, obj *Object) error {
|
||||
_, err := fmt.Fprintln(w, obj.Hash)
|
||||
return err
|
||||
}),
|
||||
},
|
||||
}
|
||||
|
||||
var patchSetDataCmd = &cmds.Command{
|
||||
var patchSetDataCmd = &oldcmds.Command{
|
||||
Helptext: cmdkit.HelpText{
|
||||
Tagline: "Set the data field of an IPFS object.",
|
||||
ShortDescription: `
|
||||
@ -138,7 +144,7 @@ Example:
|
||||
cmdkit.StringArg("root", true, false, "The hash of the node to modify."),
|
||||
cmdkit.FileArg("data", true, false, "The data to set the object to.").EnableStdin(),
|
||||
},
|
||||
Run: func(req cmds.Request, res cmds.Response) {
|
||||
Run: func(req oldcmds.Request, res oldcmds.Response) {
|
||||
nd, err := req.InvocContext().GetNode()
|
||||
if err != nil {
|
||||
res.SetError(err, cmdkit.ErrNormal)
|
||||
@ -186,12 +192,12 @@ Example:
|
||||
res.SetOutput(&Object{Hash: rtpb.Cid().String()})
|
||||
},
|
||||
Type: Object{},
|
||||
Marshalers: cmds.MarshalerMap{
|
||||
cmds.Text: objectMarshaler,
|
||||
Marshalers: oldcmds.MarshalerMap{
|
||||
oldcmds.Text: objectMarshaler,
|
||||
},
|
||||
}
|
||||
|
||||
var patchRmLinkCmd = &cmds.Command{
|
||||
var patchRmLinkCmd = &oldcmds.Command{
|
||||
Helptext: cmdkit.HelpText{
|
||||
Tagline: "Remove a link from an object.",
|
||||
ShortDescription: `
|
||||
@ -202,7 +208,7 @@ Removes a link by the given name from root.
|
||||
cmdkit.StringArg("root", true, false, "The hash of the node to modify."),
|
||||
cmdkit.StringArg("link", true, false, "Name of the link to remove."),
|
||||
},
|
||||
Run: func(req cmds.Request, res cmds.Response) {
|
||||
Run: func(req oldcmds.Request, res oldcmds.Response) {
|
||||
nd, err := req.InvocContext().GetNode()
|
||||
if err != nil {
|
||||
res.SetError(err, cmdkit.ErrNormal)
|
||||
@ -248,12 +254,12 @@ Removes a link by the given name from root.
|
||||
res.SetOutput(&Object{Hash: nc.String()})
|
||||
},
|
||||
Type: Object{},
|
||||
Marshalers: cmds.MarshalerMap{
|
||||
cmds.Text: objectMarshaler,
|
||||
Marshalers: oldcmds.MarshalerMap{
|
||||
oldcmds.Text: objectMarshaler,
|
||||
},
|
||||
}
|
||||
|
||||
var patchAddLinkCmd = &cmds.Command{
|
||||
var patchAddLinkCmd = &oldcmds.Command{
|
||||
Helptext: cmdkit.HelpText{
|
||||
Tagline: "Add a link to a given object.",
|
||||
ShortDescription: `
|
||||
@ -277,7 +283,7 @@ to a file containing 'bar', and returns the hash of the new object.
|
||||
Options: []cmdkit.Option{
|
||||
cmdkit.BoolOption("create", "p", "Create intermediary nodes."),
|
||||
},
|
||||
Run: func(req cmds.Request, res cmds.Response) {
|
||||
Run: func(req oldcmds.Request, res oldcmds.Response) {
|
||||
nd, err := req.InvocContext().GetNode()
|
||||
if err != nil {
|
||||
res.SetError(err, cmdkit.ErrNormal)
|
||||
@ -345,7 +351,18 @@ to a file containing 'bar', and returns the hash of the new object.
|
||||
res.SetOutput(&Object{Hash: nc.String()})
|
||||
},
|
||||
Type: Object{},
|
||||
Marshalers: cmds.MarshalerMap{
|
||||
cmds.Text: objectMarshaler,
|
||||
Marshalers: oldcmds.MarshalerMap{
|
||||
oldcmds.Text: objectMarshaler,
|
||||
},
|
||||
}
|
||||
|
||||
// COPIED FROM ONE LEVEL UP
|
||||
// GetNode extracts the node from the environment.
|
||||
func GetNode(env interface{}) (*core.IpfsNode, error) {
|
||||
ctx, ok := env.(*oldcmds.Context)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("expected env to be of type %T, got %T", ctx, env)
|
||||
}
|
||||
|
||||
return ctx.GetNode()
|
||||
}
|
||||
|
||||
@ -126,7 +126,7 @@ var rootSubcommands = map[string]*cmds.Command{
|
||||
"ls": lgc.NewCommand(LsCmd),
|
||||
"mount": lgc.NewCommand(MountCmd),
|
||||
"name": lgc.NewCommand(NameCmd),
|
||||
"object": lgc.NewCommand(ocmd.ObjectCmd),
|
||||
"object": ocmd.ObjectCmd,
|
||||
"pin": lgc.NewCommand(PinCmd),
|
||||
"ping": lgc.NewCommand(PingCmd),
|
||||
"p2p": lgc.NewCommand(P2PCmd),
|
||||
|
||||
Loading…
Reference in New Issue
Block a user