@cryptotaxi247 / kubo / commits / 116269a12

upgrade commands that used StringArguments

License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com>

Jeromy committed Mar 16, 2018 at 20:06 UTC 116269a12b903ba780fb43dab5b0d5e5486aa196
4 files changed +137 -99
core/commands/files.go
+54 -35
@@ -57,7 +57,7 @@ operations.
57 },
58 Subcommands: map[string]*cmds.Command{
59 "read": lgc.NewCommand(filesReadCmd),
60 - "write": lgc.NewCommand(filesWriteCmd),
60 + "write": filesWriteCmd,
61 "mv": lgc.NewCommand(filesMvCmd),
62 "cp": lgc.NewCommand(filesCpCmd),
63 "ls": lgc.NewCommand(filesLsCmd),
@@ -654,7 +654,7 @@ Example:
654 },
655 }
656
657 -var filesWriteCmd = &oldcmds.Command{
657 +var filesWriteCmd = &cmds.Command{
658 Helptext: cmdkit.HelpText{
659 Tagline: "Write to a mutable file in a given filesystem.",
660 ShortDescription: `
@@ -701,43 +701,39 @@ stat' on the file or any of its ancestors.
701 cidVersionOption,
702 hashOption,
703 },
704 - Run: func(req oldcmds.Request, res oldcmds.Response) {
705 - path, err := checkPath(req.StringArguments()[0])
704 + Run: func(req *cmds.Request, re cmds.ResponseEmitter, env cmds.Environment) {
705 + path, err := checkPath(req.Arguments[0])
706 if err != nil {
707 - res.SetError(err, cmdkit.ErrNormal)
707 + re.SetError(err, cmdkit.ErrNormal)
708 return
709 }
710
711 - create, _, _ := req.Option("create").Bool()
712 - trunc, _, _ := req.Option("truncate").Bool()
713 - flush, _, _ := req.Option("flush").Bool()
714 - rawLeaves, rawLeavesDef, _ := req.Option("raw-leaves").Bool()
711 + create, _ := req.Options["create"].(bool)
712 + trunc, _ := req.Options["truncate"].(bool)
713 + flush, _ := req.Options["flush"].(bool)
714 + rawLeaves, rawLeavesDef := req.Options["raw-leaves"].(bool)
715
716 - prefix, err := getPrefix(req)
716 + prefix, err := getPrefixNew(req)
717 if err != nil {
718 - res.SetError(err, cmdkit.ErrNormal)
718 + re.SetError(err, cmdkit.ErrNormal)
719 return
720 }
721
722 - nd, err := req.InvocContext().GetNode()
722 + nd, err := GetNode(env)
723 if err != nil {
724 - res.SetError(err, cmdkit.ErrNormal)
724 + re.SetError(err, cmdkit.ErrNormal)
725 return
726 }
727
728 - offset, _, err := req.Option("offset").Int()
729 - if err != nil {
730 - res.SetError(err, cmdkit.ErrNormal)
731 - return
732 - }
728 + offset, _ := req.Options["offset"].(int)
729 if offset < 0 {
734 - res.SetError(fmt.Errorf("cannot have negative write offset"), cmdkit.ErrNormal)
730 + re.SetError(fmt.Errorf("cannot have negative write offset"), cmdkit.ErrNormal)
731 return
732 }
733
734 fi, err := getFileHandle(nd.FilesRoot, path, create, prefix)
735 if err != nil {
740 - res.SetError(err, cmdkit.ErrNormal)
736 + re.SetError(err, cmdkit.ErrNormal)
737 return
738 }
739 if rawLeavesDef {
@@ -746,44 +742,40 @@ stat' on the file or any of its ancestors.
742
743 wfd, err := fi.Open(mfs.OpenWriteOnly, flush)
744 if err != nil {
749 - res.SetError(err, cmdkit.ErrNormal)
745 + re.SetError(err, cmdkit.ErrNormal)
746 return
747 }
748
749 defer func() {
750 err := wfd.Close()
751 if err != nil {
756 - res.SetError(err, cmdkit.ErrNormal)
752 + re.SetError(err, cmdkit.ErrNormal)
753 }
754 }()
755
756 if trunc {
757 if err := wfd.Truncate(0); err != nil {
762 - res.SetError(err, cmdkit.ErrNormal)
758 + re.SetError(err, cmdkit.ErrNormal)
759 return
760 }
761 }
762
767 - count, countfound, err := req.Option("count").Int()
768 - if err != nil {
769 - res.SetError(err, cmdkit.ErrNormal)
770 - return
771 - }
763 + count, countfound := req.Options["count"].(int)
764 if countfound && count < 0 {
773 - res.SetError(fmt.Errorf("cannot have negative byte count"), cmdkit.ErrNormal)
765 + re.SetError(fmt.Errorf("cannot have negative byte count"), cmdkit.ErrNormal)
766 return
767 }
768
769 _, err = wfd.Seek(int64(offset), io.SeekStart)
770 if err != nil {
771 flog.Error("seekfail: ", err)
780 - res.SetError(err, cmdkit.ErrNormal)
772 + re.SetError(err, cmdkit.ErrNormal)
773 return
774 }
775
784 - input, err := req.Files().NextFile()
776 + input, err := req.Files.NextFile()
777 if err != nil {
786 - res.SetError(err, cmdkit.ErrNormal)
778 + re.SetError(err, cmdkit.ErrNormal)
779 return
780 }
781
@@ -794,11 +786,9 @@ stat' on the file or any of its ancestors.
786
787 _, err = io.Copy(wfd, r)
788 if err != nil {
797 - res.SetError(err, cmdkit.ErrNormal)
789 + re.SetError(err, cmdkit.ErrNormal)
790 return
791 }
800 -
801 - res.SetOutput(nil)
792 },
793 }
794
@@ -1072,6 +1062,35 @@ Remove files or directories.
1062 },
1063 }
1064
1065 +func getPrefixNew(req *cmds.Request) (*cid.Prefix, error) {
1066 + cidVer, cidVerSet := req.Options["cid-version"].(int)
1067 + hashFunStr, hashFunSet := req.Options["hash"].(string)
1068 +
1069 + if !cidVerSet && !hashFunSet {
1070 + return nil, nil
1071 + }
1072 +
1073 + if hashFunSet && cidVer == 0 {
1074 + cidVer = 1
1075 + }
1076 +
1077 + prefix, err := dag.PrefixForCidVersion(cidVer)
1078 + if err != nil {
1079 + return nil, err
1080 + }
1081 +
1082 + if hashFunSet {
1083 + hashFunCode, ok := mh.Names[strings.ToLower(hashFunStr)]
1084 + if !ok {
1085 + return nil, fmt.Errorf("unrecognized hash function: %s", strings.ToLower(hashFunStr))
1086 + }
1087 + prefix.MhType = hashFunCode
1088 + prefix.MhLength = -1
1089 + }
1090 +
1091 + return &prefix, nil
1092 +}
1093 +
1094 func getPrefix(req oldcmds.Request) (*cid.Prefix, error) {
1095 cidVer, cidVerSet, _ := req.Option("cid-version").Int()
1096 hashFunStr, hashFunSet, _ := req.Option("hash").String()
core/commands/object/object.go
+32 -30
@@ -13,7 +13,8 @@ import (
13 "strings"
14 "text/tabwriter"
15
16 - cmds "github.com/ipfs/go-ipfs/commands"
16 + oldcmds "github.com/ipfs/go-ipfs/commands"
17 + lgc "github.com/ipfs/go-ipfs/commands/legacy"
18 core "github.com/ipfs/go-ipfs/core"
19 e "github.com/ipfs/go-ipfs/core/commands/e"
20 dag "github.com/ipfs/go-ipfs/merkledag"
@@ -21,6 +22,7 @@ import (
22 pin "github.com/ipfs/go-ipfs/pin"
23 ft "github.com/ipfs/go-ipfs/unixfs"
24
25 + cmds "gx/ipfs/QmabLouZTZwhfALuBcssPvkzhbYGMb4394huT7HY4LQ6d3/go-ipfs-cmds"
26 cid "gx/ipfs/QmcZfnkapfECQGcLZaf9B79NRg7cRa9EnZh4LSbkCzwNvY/go-cid"
27 cmdkit "gx/ipfs/QmceUdzxkimdYsgtX733uNgzf1DLHyBKN6ehGSp85ayppM/go-ipfs-cmdkit"
28 ipld "gx/ipfs/Qme5bWv7wtjUNGsK2BNGVUFPKiuxWrsqrtvYwCLRw8YFES/go-ipld-format"
@@ -55,18 +57,18 @@ directly.`,
57 },
58
59 Subcommands: map[string]*cmds.Command{
58 - "data": ObjectDataCmd,
59 - "diff": ObjectDiffCmd,
60 - "get": ObjectGetCmd,
61 - "links": ObjectLinksCmd,
62 - "new": ObjectNewCmd,
60 + "data": lgc.NewCommand(ObjectDataCmd),
61 + "diff": lgc.NewCommand(ObjectDiffCmd),
62 + "get": lgc.NewCommand(ObjectGetCmd),
63 + "links": lgc.NewCommand(ObjectLinksCmd),
64 + "new": lgc.NewCommand(ObjectNewCmd),
65 "patch": ObjectPatchCmd,
64 - "put": ObjectPutCmd,
65 - "stat": ObjectStatCmd,
66 + "put": lgc.NewCommand(ObjectPutCmd),
67 + "stat": lgc.NewCommand(ObjectStatCmd),
68 },
69 }
70
69 -var ObjectDataCmd = &cmds.Command{
71 +var ObjectDataCmd = &oldcmds.Command{
72 Helptext: cmdkit.HelpText{
73 Tagline: "Output the raw bytes of an IPFS object.",
74 ShortDescription: `
@@ -85,7 +87,7 @@ is the raw data of the object.
87 Arguments: []cmdkit.Argument{
88 cmdkit.StringArg("key", true, false, "Key of the object to retrieve, in base58-encoded multihash format.").EnableStdin(),
89 },
88 - Run: func(req cmds.Request, res cmds.Response) {
90 + Run: func(req oldcmds.Request, res oldcmds.Response) {
91 n, err := req.InvocContext().GetNode()
92 if err != nil {
93 res.SetError(err, cmdkit.ErrNormal)
@@ -114,7 +116,7 @@ is the raw data of the object.
116 },
117 }
118
117 -var ObjectLinksCmd = &cmds.Command{
119 +var ObjectLinksCmd = &oldcmds.Command{
120 Helptext: cmdkit.HelpText{
121 Tagline: "Output the links pointed to by the specified object.",
122 ShortDescription: `
@@ -130,7 +132,7 @@ multihash.
132 Options: []cmdkit.Option{
133 cmdkit.BoolOption("headers", "v", "Print table headers (Hash, Size, Name)."),
134 },
133 - Run: func(req cmds.Request, res cmds.Response) {
135 + Run: func(req oldcmds.Request, res oldcmds.Response) {
136 n, err := req.InvocContext().GetNode()
137 if err != nil {
138 res.SetError(err, cmdkit.ErrNormal)
@@ -157,8 +159,8 @@ multihash.
159 }
160 res.SetOutput(output)
161 },
160 - Marshalers: cmds.MarshalerMap{
161 - cmds.Text: func(res cmds.Response) (io.Reader, error) {
162 + Marshalers: oldcmds.MarshalerMap{
163 + oldcmds.Text: func(res oldcmds.Response) (io.Reader, error) {
164 v, err := unwrapOutput(res.Output())
165 if err != nil {
166 return nil, err
@@ -185,7 +187,7 @@ multihash.
187 Type: Object{},
188 }
189
188 -var ObjectGetCmd = &cmds.Command{
190 +var ObjectGetCmd = &oldcmds.Command{
191 Helptext: cmdkit.HelpText{
192 Tagline: "Get and serialize the DAG node named by <key>.",
193 ShortDescription: `
@@ -208,7 +210,7 @@ This command outputs data in the following encodings:
210 Arguments: []cmdkit.Argument{
211 cmdkit.StringArg("key", true, false, "Key of the object to retrieve, in base58-encoded multihash format.").EnableStdin(),
212 },
211 - Run: func(req cmds.Request, res cmds.Response) {
213 + Run: func(req oldcmds.Request, res oldcmds.Response) {
214 n, err := req.InvocContext().GetNode()
215 if err != nil {
216 res.SetError(err, cmdkit.ErrNormal)
@@ -245,8 +247,8 @@ This command outputs data in the following encodings:
247 res.SetOutput(node)
248 },
249 Type: Node{},
248 - Marshalers: cmds.MarshalerMap{
249 - cmds.Protobuf: func(res cmds.Response) (io.Reader, error) {
250 + Marshalers: oldcmds.MarshalerMap{
251 + oldcmds.Protobuf: func(res oldcmds.Response) (io.Reader, error) {
252 v, err := unwrapOutput(res.Output())
253 if err != nil {
254 return nil, err
@@ -272,7 +274,7 @@ This command outputs data in the following encodings:
274 },
275 }
276
275 -var ObjectStatCmd = &cmds.Command{
277 +var ObjectStatCmd = &oldcmds.Command{
278 Helptext: cmdkit.HelpText{
279 Tagline: "Get stats for the DAG node named by <key>.",
280 ShortDescription: `
@@ -290,7 +292,7 @@ var ObjectStatCmd = &cmds.Command{
292 Arguments: []cmdkit.Argument{
293 cmdkit.StringArg("key", true, false, "Key of the object to retrieve, in base58-encoded multihash format.").EnableStdin(),
294 },
293 - Run: func(req cmds.Request, res cmds.Response) {
295 + Run: func(req oldcmds.Request, res oldcmds.Response) {
296 n, err := req.InvocContext().GetNode()
297 if err != nil {
298 res.SetError(err, cmdkit.ErrNormal)
@@ -314,8 +316,8 @@ var ObjectStatCmd = &cmds.Command{
316 res.SetOutput(ns)
317 },
318 Type: ipld.NodeStat{},
317 - Marshalers: cmds.MarshalerMap{
318 - cmds.Text: func(res cmds.Response) (io.Reader, error) {
319 + Marshalers: oldcmds.MarshalerMap{
320 + oldcmds.Text: func(res oldcmds.Response) (io.Reader, error) {
321 v, err := unwrapOutput(res.Output())
322 if err != nil {
323 return nil, err
@@ -341,7 +343,7 @@ var ObjectStatCmd = &cmds.Command{
343 },
344 }
345
344 -var ObjectPutCmd = &cmds.Command{
346 +var ObjectPutCmd = &oldcmds.Command{
347 Helptext: cmdkit.HelpText{
348 Tagline: "Store input as a DAG object, print its key.",
349 ShortDescription: `
@@ -388,7 +390,7 @@ And then run:
390 cmdkit.BoolOption("pin", "Pin this object when adding."),
391 cmdkit.BoolOption("quiet", "q", "Write minimal output."),
392 },
391 - Run: func(req cmds.Request, res cmds.Response) {
393 + Run: func(req oldcmds.Request, res oldcmds.Response) {
394 n, err := req.InvocContext().GetNode()
395 if err != nil {
396 res.SetError(err, cmdkit.ErrNormal)
@@ -444,8 +446,8 @@ And then run:
446
447 res.SetOutput(&Object{Hash: objectCid.String()})
448 },
447 - Marshalers: cmds.MarshalerMap{
448 - cmds.Text: func(res cmds.Response) (io.Reader, error) {
449 + Marshalers: oldcmds.MarshalerMap{
450 + oldcmds.Text: func(res oldcmds.Response) (io.Reader, error) {
451 quiet, _, _ := res.Request().Option("quiet").Bool()
452
453 v, err := unwrapOutput(res.Output())
@@ -468,7 +470,7 @@ And then run:
470 Type: Object{},
471 }
472
471 -var ObjectNewCmd = &cmds.Command{
473 +var ObjectNewCmd = &oldcmds.Command{
474 Helptext: cmdkit.HelpText{
475 Tagline: "Create a new object from an ipfs template.",
476 ShortDescription: `
@@ -487,7 +489,7 @@ Available templates:
489 Arguments: []cmdkit.Argument{
490 cmdkit.StringArg("template", false, false, "Template to use. Optional."),
491 },
490 - Run: func(req cmds.Request, res cmds.Response) {
492 + Run: func(req oldcmds.Request, res oldcmds.Response) {
493 n, err := req.InvocContext().GetNode()
494 if err != nil {
495 res.SetError(err, cmdkit.ErrNormal)
@@ -512,8 +514,8 @@ Available templates:
514 }
515 res.SetOutput(&Object{Hash: node.Cid().String()})
516 },
515 - Marshalers: cmds.MarshalerMap{
516 - cmds.Text: func(res cmds.Response) (io.Reader, error) {
517 + Marshalers: oldcmds.MarshalerMap{
518 + oldcmds.Text: func(res oldcmds.Response) (io.Reader, error) {
519 v, err := unwrapOutput(res.Output())
520 if err != nil {
521 return nil, err
core/commands/object/patch.go
+50 -33
@@ -1,11 +1,13 @@
1 package objectcmd
2
3 import (
4 + "fmt"
5 "io"
6 "io/ioutil"
7 "strings"
8
8 - cmds "github.com/ipfs/go-ipfs/commands"
9 + oldcmds "github.com/ipfs/go-ipfs/commands"
10 + lgc "github.com/ipfs/go-ipfs/commands/legacy"
11 core "github.com/ipfs/go-ipfs/core"
12 e "github.com/ipfs/go-ipfs/core/commands/e"
13 dag "github.com/ipfs/go-ipfs/merkledag"
@@ -14,6 +16,7 @@ import (
16 ft "github.com/ipfs/go-ipfs/unixfs"
17
18 logging "gx/ipfs/QmRb5jh8z2E8hMGN2tkvs1yHynUanqnZ3UeKwgN1i9P1F8/go-log"
19 + cmds "gx/ipfs/QmabLouZTZwhfALuBcssPvkzhbYGMb4394huT7HY4LQ6d3/go-ipfs-cmds"
20 cmdkit "gx/ipfs/QmceUdzxkimdYsgtX733uNgzf1DLHyBKN6ehGSp85ayppM/go-ipfs-cmdkit"
21 )
22
@@ -31,13 +34,13 @@ result. This is the Merkle-DAG version of modifying an object.
34 Arguments: []cmdkit.Argument{},
35 Subcommands: map[string]*cmds.Command{
36 "append-data": patchAppendDataCmd,
34 - "add-link": patchAddLinkCmd,
35 - "rm-link": patchRmLinkCmd,
36 - "set-data": patchSetDataCmd,
37 + "add-link": lgc.NewCommand(patchAddLinkCmd),
38 + "rm-link": lgc.NewCommand(patchRmLinkCmd),
39 + "set-data": lgc.NewCommand(patchSetDataCmd),
40 },
41 }
42
40 -func objectMarshaler(res cmds.Response) (io.Reader, error) {
43 +func objectMarshaler(res oldcmds.Response) (io.Reader, error) {
44 v, err := unwrapOutput(res.Output())
45 if err != nil {
46 return nil, err
@@ -70,60 +73,63 @@ the limit will not be respected by the network.
73 cmdkit.StringArg("root", true, false, "The hash of the node to modify."),
74 cmdkit.FileArg("data", true, false, "Data to append.").EnableStdin(),
75 },
73 - Run: func(req cmds.Request, res cmds.Response) {
74 - nd, err := req.InvocContext().GetNode()
76 + Run: func(req *cmds.Request, re cmds.ResponseEmitter, env cmds.Environment) {
77 + nd, err := GetNode(env)
78 if err != nil {
76 - res.SetError(err, cmdkit.ErrNormal)
79 + re.SetError(err, cmdkit.ErrNormal)
80 return
81 }
82
80 - root, err := path.ParsePath(req.StringArguments()[0])
83 + root, err := path.ParsePath(req.Arguments[0])
84 if err != nil {
82 - res.SetError(err, cmdkit.ErrNormal)
85 + re.SetError(err, cmdkit.ErrNormal)
86 return
87 }
88
86 - rootnd, err := core.Resolve(req.Context(), nd.Namesys, nd.Resolver, root)
89 + rootnd, err := core.Resolve(req.Context, nd.Namesys, nd.Resolver, root)
90 if err != nil {
88 - res.SetError(err, cmdkit.ErrNormal)
91 + re.SetError(err, cmdkit.ErrNormal)
92 return
93 }
94
95 rtpb, ok := rootnd.(*dag.ProtoNode)
96 if !ok {
94 - res.SetError(dag.ErrNotProtobuf, cmdkit.ErrNormal)
97 + re.SetError(dag.ErrNotProtobuf, cmdkit.ErrNormal)
98 return
99 }
100
98 - fi, err := req.Files().NextFile()
101 + fi, err := req.Files.NextFile()
102 if err != nil {
100 - res.SetError(err, cmdkit.ErrNormal)
103 + re.SetError(err, cmdkit.ErrNormal)
104 return
105 }
106
107 data, err := ioutil.ReadAll(fi)
108 if err != nil {
106 - res.SetError(err, cmdkit.ErrNormal)
109 + re.SetError(err, cmdkit.ErrNormal)
110 return
111 }
112
113 rtpb.SetData(append(rtpb.Data(), data...))
114
112 - err = nd.DAG.Add(req.Context(), rtpb)
115 + err = nd.DAG.Add(req.Context, rtpb)
116 if err != nil {
114 - res.SetError(err, cmdkit.ErrNormal)
117 + re.SetError(err, cmdkit.ErrNormal)
118 return
119 }
120
118 - res.SetOutput(&Object{Hash: rtpb.Cid().String()})
121 + cmds.EmitOnce(re, &Object{Hash: rtpb.Cid().String()})
122 },
123 Type: Object{},
121 - Marshalers: cmds.MarshalerMap{
122 - cmds.Text: objectMarshaler,
124 + Encoders: cmds.EncoderMap{
125 + cmds.Text: cmds.MakeTypedEncoder(func(req *cmds.Request, w io.Writer, obj *Object) error {
126 + _, err := fmt.Fprintln(w, obj.Hash)
127 + return err
128 + }),
129 },
130 }
131
126 -var patchSetDataCmd = &cmds.Command{
132 +var patchSetDataCmd = &oldcmds.Command{
133 Helptext: cmdkit.HelpText{
134 Tagline: "Set the data field of an IPFS object.",
135 ShortDescription: `
@@ -138,7 +144,7 @@ Example:
144 cmdkit.StringArg("root", true, false, "The hash of the node to modify."),
145 cmdkit.FileArg("data", true, false, "The data to set the object to.").EnableStdin(),
146 },
141 - Run: func(req cmds.Request, res cmds.Response) {
147 + Run: func(req oldcmds.Request, res oldcmds.Response) {
148 nd, err := req.InvocContext().GetNode()
149 if err != nil {
150 res.SetError(err, cmdkit.ErrNormal)
@@ -186,12 +192,12 @@ Example:
192 res.SetOutput(&Object{Hash: rtpb.Cid().String()})
193 },
194 Type: Object{},
189 - Marshalers: cmds.MarshalerMap{
190 - cmds.Text: objectMarshaler,
195 + Marshalers: oldcmds.MarshalerMap{
196 + oldcmds.Text: objectMarshaler,
197 },
198 }
199
194 -var patchRmLinkCmd = &cmds.Command{
200 +var patchRmLinkCmd = &oldcmds.Command{
201 Helptext: cmdkit.HelpText{
202 Tagline: "Remove a link from an object.",
203 ShortDescription: `
@@ -202,7 +208,7 @@ Removes a link by the given name from root.
208 cmdkit.StringArg("root", true, false, "The hash of the node to modify."),
209 cmdkit.StringArg("link", true, false, "Name of the link to remove."),
210 },
205 - Run: func(req cmds.Request, res cmds.Response) {
211 + Run: func(req oldcmds.Request, res oldcmds.Response) {
212 nd, err := req.InvocContext().GetNode()
213 if err != nil {
214 res.SetError(err, cmdkit.ErrNormal)
@@ -248,12 +254,12 @@ Removes a link by the given name from root.
254 res.SetOutput(&Object{Hash: nc.String()})
255 },
256 Type: Object{},
251 - Marshalers: cmds.MarshalerMap{
252 - cmds.Text: objectMarshaler,
257 + Marshalers: oldcmds.MarshalerMap{
258 + oldcmds.Text: objectMarshaler,
259 },
260 }
261
256 -var patchAddLinkCmd = &cmds.Command{
262 +var patchAddLinkCmd = &oldcmds.Command{
263 Helptext: cmdkit.HelpText{
264 Tagline: "Add a link to a given object.",
265 ShortDescription: `
@@ -277,7 +283,7 @@ to a file containing 'bar', and returns the hash of the new object.
283 Options: []cmdkit.Option{
284 cmdkit.BoolOption("create", "p", "Create intermediary nodes."),
285 },
280 - Run: func(req cmds.Request, res cmds.Response) {
286 + Run: func(req oldcmds.Request, res oldcmds.Response) {
287 nd, err := req.InvocContext().GetNode()
288 if err != nil {
289 res.SetError(err, cmdkit.ErrNormal)
@@ -345,7 +351,18 @@ to a file containing 'bar', and returns the hash of the new object.
351 res.SetOutput(&Object{Hash: nc.String()})
352 },
353 Type: Object{},
348 - Marshalers: cmds.MarshalerMap{
349 - cmds.Text: objectMarshaler,
354 + Marshalers: oldcmds.MarshalerMap{
355 + oldcmds.Text: objectMarshaler,
356 },
357 }
358 +
359 +// COPIED FROM ONE LEVEL UP
360 +// GetNode extracts the node from the environment.
361 +func GetNode(env interface{}) (*core.IpfsNode, error) {
362 + ctx, ok := env.(*oldcmds.Context)
363 + if !ok {
364 + return nil, fmt.Errorf("expected env to be of type %T, got %T", ctx, env)
365 + }
366 +
367 + return ctx.GetNode()
368 +}
core/commands/root.go
+1 -1
@@ -126,7 +126,7 @@ var rootSubcommands = map[string]*cmds.Command{
126 "ls": lgc.NewCommand(LsCmd),
127 "mount": lgc.NewCommand(MountCmd),
128 "name": lgc.NewCommand(NameCmd),
129 - "object": lgc.NewCommand(ocmd.ObjectCmd),
129 + "object": ocmd.ObjectCmd,
130 "pin": lgc.NewCommand(PinCmd),
131 "ping": lgc.NewCommand(PingCmd),
132 "p2p": lgc.NewCommand(P2PCmd),