switch urlstore to the new commands lib
License: MIT Signed-off-by: Steven Allen <steven@stebalien.com>
Steven Allen committed
Jul 16, 2018 at 12:29 UTC
89e1d9fd493522678a5347b45ed48040939454c8
2 files changed
+11
-15
core/commands/root.go
+1
-1
@@ -136,7 +136,7 @@ var rootSubcommands = map[string]*cmds.Command{
136
"tar": lgc.NewCommand(TarCmd),
137
"file": lgc.NewCommand(unixfs.UnixFSCmd),
138
"update": lgc.NewCommand(ExternalBinary()),
139
- "urlstore": lgc.NewCommand(urlStoreCmd),
139
+ "urlstore": urlStoreCmd,
140
"version": lgc.NewCommand(VersionCmd),
141
"shutdown": lgc.NewCommand(daemonShutdownCmd),
142
}
core/commands/urlstore.go
+10
-14
@@ -4,13 +4,12 @@ import (
4
"fmt"
5
"io"
6
"net/http"
7
- "strings"
7
9
- cmds "github.com/ipfs/go-ipfs/commands"
8
filestore "github.com/ipfs/go-ipfs/filestore"
9
balanced "github.com/ipfs/go-ipfs/importer/balanced"
10
ihelper "github.com/ipfs/go-ipfs/importer/helpers"
11
12
+ cmds "gx/ipfs/QmNueRyPRQiV7PUEpnP4GgGLuK1rKQLaRW7sfPvUetYig1/go-ipfs-cmds"
13
mh "gx/ipfs/QmPnFwZ2JXKnXgMw8CdBPxn7FWh6LLdjUjxV1fKHuJnkr8/go-multihash"
14
chunk "gx/ipfs/QmXnzH7wowyLZy8XJxxaQCVTgLMcDXdMBznmsrmQWCyiQV/go-ipfs-chunker"
15
cid "gx/ipfs/QmapdYm1b22Frv3k17fqrBYTFRxwiaVJkB299Mfn33edeB/go-cid"
@@ -18,7 +17,6 @@ import (
17
)
18
19
var urlStoreCmd = &cmds.Command{
21
-
20
Subcommands: map[string]*cmds.Command{
21
"add": urlAdd,
22
},
@@ -49,9 +47,9 @@ time.
47
},
48
Type: BlockStat{},
49
52
- Run: func(req cmds.Request, res cmds.Response) {
53
- url := req.Arguments()[0]
54
- n, err := req.InvocContext().GetNode()
50
+ Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) {
51
+ url := req.Arguments[0]
52
+ n, err := GetNode(env)
53
if err != nil {
54
res.SetError(err, cmdkit.ErrNormal)
55
return
@@ -106,17 +104,15 @@ time.
104
return
105
}
106
109
- res.SetOutput(BlockStat{
107
+ cmds.EmitOnce(res, BlockStat{
108
Key: blc.Cid().String(),
109
Size: int(hres.ContentLength),
110
})
111
},
114
- Marshalers: cmds.MarshalerMap{
115
- cmds.Text: func(res cmds.Response) (io.Reader, error) {
116
- ch := res.Output().(<-chan interface{})
117
- bs0 := <-ch
118
- bs := bs0.(*BlockStat)
119
- return strings.NewReader(bs.Key + "\n"), nil
120
- },
112
+ Encoders: cmds.EncoderMap{
113
+ cmds.Text: cmds.MakeTypedEncoder(func(req *cmds.Request, w io.Writer, bs *BlockStat) error {
114
+ _, err := fmt.Fprintln(w, bs.Key)
115
+ return err
116
+ }),
117
},
118
}