name cmd: move subcommands to subdirectory
License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
Łukasz Magiera committed
Aug 21, 2018 at 19:03 UTC
b0c480acf5fd89a7d30d3cdac3d8427a16563d43
27 files changed
+195
-174
core/commands/add.go
+2
-1
@@ -8,6 +8,7 @@ import (
8
"strings"
9
10
core "github.com/ipfs/go-ipfs/core"
11
+ cmdenv "github.com/ipfs/go-ipfs/core/commands/cmdenv"
12
"github.com/ipfs/go-ipfs/core/coreunix"
13
filestore "github.com/ipfs/go-ipfs/filestore"
14
ft "gx/ipfs/QmQjEpRiwVvtowhq69dAtB4jhioPVFXiCcWZm9Sfgn7eqc/go-unixfs"
@@ -141,7 +142,7 @@ You can now check what blocks have been created by:
142
return nil
143
},
144
Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) {
144
- n, err := GetNode(env)
145
+ n, err := cmdenv.GetNode(env)
146
if err != nil {
147
res.SetError(err, cmdkit.ErrNormal)
148
return
core/commands/bitswap.go
+7
-6
@@ -7,6 +7,7 @@ import (
7
8
oldcmds "github.com/ipfs/go-ipfs/commands"
9
lgc "github.com/ipfs/go-ipfs/commands/legacy"
10
+ cmdenv "github.com/ipfs/go-ipfs/core/commands/cmdenv"
11
e "github.com/ipfs/go-ipfs/core/commands/e"
12
bitswap "gx/ipfs/QmTtmrK4iiM3MxWNA3pvbM9ekQiGZAiFyo57GP8B9FFgtz/go-bitswap"
13
decision "gx/ipfs/QmTtmrK4iiM3MxWNA3pvbM9ekQiGZAiFyo57GP8B9FFgtz/go-bitswap/decision"
@@ -48,7 +49,7 @@ var unwantCmd = &oldcmds.Command{
49
}
50
51
if !nd.OnlineMode() {
51
- res.SetError(errNotOnline, cmdkit.ErrClient)
52
+ res.SetError(ErrNotOnline, cmdkit.ErrClient)
53
return
54
}
55
@@ -97,7 +98,7 @@ Print out all blocks currently on the bitswap wantlist for the local peer.`,
98
}
99
100
if !nd.OnlineMode() {
100
- res.SetError(errNotOnline, cmdkit.ErrClient)
101
+ res.SetError(ErrNotOnline, cmdkit.ErrClient)
102
return
103
}
104
@@ -140,14 +141,14 @@ var bitswapStatCmd = &cmds.Command{
141
},
142
Type: bitswap.Stat{},
143
Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) {
143
- nd, err := GetNode(env)
144
+ nd, err := cmdenv.GetNode(env)
145
if err != nil {
146
res.SetError(err, cmdkit.ErrNormal)
147
return
148
}
149
150
if !nd.OnlineMode() {
150
- res.SetError(errNotOnline, cmdkit.ErrClient)
151
+ res.SetError(ErrNotOnline, cmdkit.ErrClient)
152
return
153
}
154
@@ -215,7 +216,7 @@ prints the ledger associated with a given peer.
216
}
217
218
if !nd.OnlineMode() {
218
- res.SetError(errNotOnline, cmdkit.ErrClient)
219
+ res.SetError(ErrNotOnline, cmdkit.ErrClient)
220
return
221
}
222
@@ -272,7 +273,7 @@ Trigger reprovider to announce our data to network.
273
}
274
275
if !nd.OnlineMode() {
275
- res.SetError(errNotOnline, cmdkit.ErrClient)
276
+ res.SetError(ErrNotOnline, cmdkit.ErrClient)
277
return
278
}
279
core/commands/block.go
+4
-3
@@ -10,6 +10,7 @@ import (
10
"os"
11
12
util "github.com/ipfs/go-ipfs/blocks/blockstoreutil"
13
+ cmdenv "github.com/ipfs/go-ipfs/core/commands/cmdenv"
14
e "github.com/ipfs/go-ipfs/core/commands/e"
15
16
"gx/ipfs/QmPTfgFTo9PFr1PvPKyKoeMgBvYPh6cX3aDP7DHKVbnCbi/go-ipfs-cmds"
@@ -137,7 +138,7 @@ than 'sha2-256' or format to anything other than 'v0' will result in CIDv1.
138
cmdkit.IntOption("mhlen", "multihash hash length").WithDefault(-1),
139
},
140
Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) {
140
- n, err := GetNode(env)
141
+ n, err := cmdenv.GetNode(env)
142
if err != nil {
143
res.SetError(err, cmdkit.ErrNormal)
144
return
@@ -248,7 +249,7 @@ func getBlockForKey(ctx context.Context, env cmds.Environment, skey string) (blo
249
return nil, fmt.Errorf("zero length cid invalid")
250
}
251
251
- n, err := GetNode(env)
252
+ n, err := cmdenv.GetNode(env)
253
if err != nil {
254
return nil, err
255
}
@@ -282,7 +283,7 @@ It takes a list of base58 encoded multihashes to remove.
283
cmdkit.BoolOption("quiet", "q", "Write minimal output."),
284
},
285
Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) {
285
- n, err := GetNode(env)
286
+ n, err := cmdenv.GetNode(env)
287
if err != nil {
288
res.SetError(err, cmdkit.ErrNormal)
289
return
core/commands/cat.go
+2
-1
@@ -7,6 +7,7 @@ import (
7
"os"
8
9
core "github.com/ipfs/go-ipfs/core"
10
+ cmdenv "github.com/ipfs/go-ipfs/core/commands/cmdenv"
11
coreunix "github.com/ipfs/go-ipfs/core/coreunix"
12
13
cmds "gx/ipfs/QmPTfgFTo9PFr1PvPKyKoeMgBvYPh6cX3aDP7DHKVbnCbi/go-ipfs-cmds"
@@ -29,7 +30,7 @@ var CatCmd = &cmds.Command{
30
cmdkit.IntOption("length", "l", "Maximum number of bytes to read."),
31
},
32
Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) {
32
- node, err := GetNode(env)
33
+ node, err := cmdenv.GetNode(env)
34
if err != nil {
35
res.SetError(err, cmdkit.ErrNormal)
36
return
core/commands/cmdenv/env.go
renamed
+1
-1
@@ -1,4 +1,4 @@
1
-package commands
1
+package cmdenv
2
3
import (
4
"fmt"
core/commands/dht.go
+5
-5
@@ -160,7 +160,7 @@ var findProvidersDhtCmd = &cmds.Command{
160
}
161
162
if n.Routing == nil {
163
- res.SetError(errNotOnline, cmdkit.ErrNormal)
163
+ res.SetError(ErrNotOnline, cmdkit.ErrNormal)
164
return
165
}
166
@@ -272,7 +272,7 @@ var provideRefDhtCmd = &cmds.Command{
272
}
273
274
if n.Routing == nil {
275
- res.SetError(errNotOnline, cmdkit.ErrNormal)
275
+ res.SetError(ErrNotOnline, cmdkit.ErrNormal)
276
return
277
}
278
@@ -424,7 +424,7 @@ var findPeerDhtCmd = &cmds.Command{
424
}
425
426
if n.Routing == nil {
427
- res.SetError(errNotOnline, cmdkit.ErrNormal)
427
+ res.SetError(ErrNotOnline, cmdkit.ErrNormal)
428
return
429
}
430
@@ -529,7 +529,7 @@ Different key types can specify other 'best' rules.
529
}
530
531
if n.Routing == nil {
532
- res.SetError(errNotOnline, cmdkit.ErrNormal)
532
+ res.SetError(ErrNotOnline, cmdkit.ErrNormal)
533
return
534
}
535
@@ -643,7 +643,7 @@ NOTE: A value may not exceed 2048 bytes.
643
}
644
645
if n.Routing == nil {
646
- res.SetError(errNotOnline, cmdkit.ErrNormal)
646
+ res.SetError(ErrNotOnline, cmdkit.ErrNormal)
647
return
648
}
649
core/commands/dns.go
+4
-3
@@ -6,6 +6,7 @@ import (
6
7
cmds "github.com/ipfs/go-ipfs/commands"
8
e "github.com/ipfs/go-ipfs/core/commands/e"
9
+ ncmd "github.com/ipfs/go-ipfs/core/commands/name"
10
namesys "github.com/ipfs/go-ipfs/namesys"
11
nsopts "github.com/ipfs/go-ipfs/namesys/opts"
12
@@ -72,7 +73,7 @@ The resolver can recursively resolve:
73
res.SetError(err, cmdkit.ErrNormal)
74
return
75
}
75
- res.SetOutput(&ResolvedPath{output})
76
+ res.SetOutput(&ncmd.ResolvedPath{Path: output})
77
},
78
Marshalers: cmds.MarshalerMap{
79
cmds.Text: func(res cmds.Response) (io.Reader, error) {
@@ -81,12 +82,12 @@ The resolver can recursively resolve:
82
return nil, err
83
}
84
84
- output, ok := v.(*ResolvedPath)
85
+ output, ok := v.(*ncmd.ResolvedPath)
86
if !ok {
87
return nil, e.TypeErr(output, v)
88
}
89
return strings.NewReader(output.Path.String() + "\n"), nil
90
},
91
},
91
- Type: ResolvedPath{},
92
+ Type: ncmd.ResolvedPath{},
93
}
core/commands/files.go
+3
-2
@@ -14,6 +14,7 @@ import (
14
oldcmds "github.com/ipfs/go-ipfs/commands"
15
lgc "github.com/ipfs/go-ipfs/commands/legacy"
16
core "github.com/ipfs/go-ipfs/core"
17
+ cmdenv "github.com/ipfs/go-ipfs/core/commands/cmdenv"
18
e "github.com/ipfs/go-ipfs/core/commands/e"
19
ft "gx/ipfs/QmQjEpRiwVvtowhq69dAtB4jhioPVFXiCcWZm9Sfgn7eqc/go-unixfs"
20
uio "gx/ipfs/QmQjEpRiwVvtowhq69dAtB4jhioPVFXiCcWZm9Sfgn7eqc/go-unixfs/io"
@@ -114,7 +115,7 @@ var filesStatCmd = &cmds.Command{
115
res.SetError(err, cmdkit.ErrClient)
116
}
117
117
- node, err := GetNode(env)
118
+ node, err := cmdenv.GetNode(env)
119
if err != nil {
120
res.SetError(err, cmdkit.ErrNormal)
121
return
@@ -745,7 +746,7 @@ stat' on the file or any of its ancestors.
746
return
747
}
748
748
- nd, err := GetNode(env)
749
+ nd, err := cmdenv.GetNode(env)
750
if err != nil {
751
re.SetError(err, cmdkit.ErrNormal)
752
return
core/commands/filestore.go
+2
-1
@@ -9,6 +9,7 @@ import (
9
oldCmds "github.com/ipfs/go-ipfs/commands"
10
lgc "github.com/ipfs/go-ipfs/commands/legacy"
11
"github.com/ipfs/go-ipfs/core"
12
+ cmdenv "github.com/ipfs/go-ipfs/core/commands/cmdenv"
13
e "github.com/ipfs/go-ipfs/core/commands/e"
14
"github.com/ipfs/go-ipfs/filestore"
15
@@ -231,7 +232,7 @@ var dupsFileStore = &oldCmds.Command{
232
}
233
234
func getFilestore(env interface{}) (*core.IpfsNode, *filestore.Filestore, error) {
234
- n, err := GetNode(env)
235
+ n, err := cmdenv.GetNode(env)
236
if err != nil {
237
return nil, nil, err
238
}
core/commands/get.go
+5
-4
@@ -10,15 +10,16 @@ import (
10
"strings"
11
12
core "github.com/ipfs/go-ipfs/core"
13
+ cmdenv "github.com/ipfs/go-ipfs/core/commands/cmdenv"
14
e "github.com/ipfs/go-ipfs/core/commands/e"
14
- uarchive "gx/ipfs/QmQjEpRiwVvtowhq69dAtB4jhioPVFXiCcWZm9Sfgn7eqc/go-unixfs/archive"
15
- dag "gx/ipfs/QmRiQCJZ91B7VNmLvA6sxzDuBJGSojS3uXHHVuNr3iueNZ/go-merkledag"
16
- path "gx/ipfs/QmdMPBephdLYNESkruDX2hcDTgFYhoCt4LimWhgnomSdV2/go-path"
15
16
"gx/ipfs/QmPTfgFTo9PFr1PvPKyKoeMgBvYPh6cX3aDP7DHKVbnCbi/go-ipfs-cmds"
17
"gx/ipfs/QmPtj12fdwuAqj9sBSTNUxBNu8kCGNp8b3o8yUzMm5GHpq/pb"
18
tar "gx/ipfs/QmQine7gvHncNevKtG9QXxf3nXcwSj6aDDmMm52mHofEEp/tar-utils"
19
+ uarchive "gx/ipfs/QmQjEpRiwVvtowhq69dAtB4jhioPVFXiCcWZm9Sfgn7eqc/go-unixfs/archive"
20
+ dag "gx/ipfs/QmRiQCJZ91B7VNmLvA6sxzDuBJGSojS3uXHHVuNr3iueNZ/go-merkledag"
21
"gx/ipfs/QmSP88ryZkHSRn1fnngAaV2Vcn63WUJzAavnRM9CVdU1Ky/go-ipfs-cmdkit"
22
+ path "gx/ipfs/QmdMPBephdLYNESkruDX2hcDTgFYhoCt4LimWhgnomSdV2/go-path"
23
)
24
25
var ErrInvalidCompressionLevel = errors.New("compression level must be between 1 and 9")
@@ -59,7 +60,7 @@ may also specify the level of compression by specifying '-l=<1-9>'.
60
return
61
}
62
62
- node, err := GetNode(env)
63
+ node, err := cmdenv.GetNode(env)
64
if err != nil {
65
res.SetError(err, cmdkit.ErrNormal)
66
return
core/commands/keystore.go
+5
-4
@@ -5,6 +5,7 @@ import (
5
"io"
6
"text/tabwriter"
7
8
+ cmdenv "github.com/ipfs/go-ipfs/core/commands/cmdenv"
9
"github.com/ipfs/go-ipfs/core/commands/e"
10
"github.com/ipfs/go-ipfs/core/coreapi/interface/options"
11
@@ -66,7 +67,7 @@ var keyGenCmd = &cmds.Command{
67
cmdkit.StringArg("name", true, false, "name of key to create"),
68
},
69
Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) {
69
- api, err := GetApi(env)
70
+ api, err := cmdenv.GetApi(env)
71
if err != nil {
72
res.SetError(err, cmdkit.ErrNormal)
73
return
@@ -125,7 +126,7 @@ var keyListCmd = &cmds.Command{
126
cmdkit.BoolOption("l", "Show extra information about keys."),
127
},
128
Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) {
128
- api, err := GetApi(env)
129
+ api, err := cmdenv.GetApi(env)
130
if err != nil {
131
res.SetError(err, cmdkit.ErrNormal)
132
return
@@ -163,7 +164,7 @@ var keyRenameCmd = &cmds.Command{
164
cmdkit.BoolOption("force", "f", "Allow to overwrite an existing key."),
165
},
166
Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) {
166
- api, err := GetApi(env)
167
+ api, err := cmdenv.GetApi(env)
168
if err != nil {
169
res.SetError(err, cmdkit.ErrNormal)
170
return
@@ -215,7 +216,7 @@ var keyRmCmd = &cmds.Command{
216
cmdkit.BoolOption("l", "Show extra information about keys."),
217
},
218
Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) {
218
- api, err := GetApi(env)
219
+ api, err := cmdenv.GetApi(env)
220
if err != nil {
221
res.SetError(err, cmdkit.ErrNormal)
222
return
core/commands/mount_unix.go
+1
-1
@@ -91,7 +91,7 @@ baz
91
92
// error if we aren't running node in online mode
93
if node.LocalMode() {
94
- res.SetError(errNotOnline, cmdkit.ErrClient)
94
+ res.SetError(ErrNotOnline, cmdkit.ErrClient)
95
return
96
}
97
core/commands/name/ipns.go
renamed
+29
-23
@@ -1,4 +1,4 @@
1
-package commands
1
+package name
2
3
import (
4
"errors"
@@ -6,15 +6,25 @@ import (
6
"strings"
7
"time"
8
9
- cmds "github.com/ipfs/go-ipfs/commands"
9
+ cmdenv "github.com/ipfs/go-ipfs/core/commands/cmdenv"
10
e "github.com/ipfs/go-ipfs/core/commands/e"
11
namesys "github.com/ipfs/go-ipfs/namesys"
12
nsopts "github.com/ipfs/go-ipfs/namesys/opts"
13
14
+ cmds "gx/ipfs/QmPTfgFTo9PFr1PvPKyKoeMgBvYPh6cX3aDP7DHKVbnCbi/go-ipfs-cmds"
15
+ logging "gx/ipfs/QmRREK2CAZ5Re2Bd9zZFG6FeYDppUWt5cMgsoUEp3ktgSr/go-log"
16
"gx/ipfs/QmSP88ryZkHSRn1fnngAaV2Vcn63WUJzAavnRM9CVdU1Ky/go-ipfs-cmdkit"
17
offline "gx/ipfs/Qmd45r5jHr1PKMNQqifnbZy1ZQwHdtXUDJFamUEvUJE544/go-ipfs-routing/offline"
18
+ path "gx/ipfs/QmdMPBephdLYNESkruDX2hcDTgFYhoCt4LimWhgnomSdV2/go-path"
19
+ "fmt"
20
)
21
22
+var log = logging.Logger("core/commands/ipns")
23
+
24
+type ResolvedPath struct {
25
+ Path path.Path
26
+}
27
+
28
var IpnsCmd = &cmds.Command{
29
Helptext: cmdkit.HelpText{
30
Tagline: "Resolve IPNS names.",
@@ -62,8 +72,8 @@ Resolve the value of a dnslink:
72
cmdkit.UintOption("dht-record-count", "dhtrc", "Number of records to request for DHT resolution."),
73
cmdkit.StringOption("dht-timeout", "dhtt", "Max time to collect values during DHT resolution eg \"30s\". Pass 0 for no timeout."),
74
},
65
- Run: func(req cmds.Request, res cmds.Response) {
66
- n, err := req.InvocContext().GetNode()
75
+ Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) {
76
+ n, err := cmdenv.GetNode(env)
77
if err != nil {
78
res.SetError(err, cmdkit.ErrNormal)
79
return
@@ -77,8 +87,8 @@ Resolve the value of a dnslink:
87
}
88
}
89
80
- nocache, _, _ := req.Option("nocache").Bool()
81
- local, _, _ := req.Option("local").Bool()
90
+ nocache, _ := req.Options["nocache"].(bool)
91
+ local, _ := req.Options["local"].(bool)
92
93
// default to nodes namesys resolver
94
var resolver namesys.Resolver = n.Namesys
@@ -98,7 +108,7 @@ Resolve the value of a dnslink:
108
}
109
110
var name string
101
- if len(req.Arguments()) == 0 {
111
+ if len(req.Arguments) == 0 {
112
if n.Identity == "" {
113
res.SetError(errors.New("identity not loaded"), cmdkit.ErrNormal)
114
return
@@ -106,12 +116,12 @@ Resolve the value of a dnslink:
116
name = n.Identity.Pretty()
117
118
} else {
109
- name = req.Arguments()[0]
119
+ name = req.Arguments[0]
120
}
121
112
- recursive, _, _ := req.Option("recursive").Bool()
113
- rc, rcok, _ := req.Option("dht-record-count").Int()
114
- dhtt, dhttok, _ := req.Option("dht-timeout").String()
122
+ recursive, _ := req.Options["recursive"].(bool)
123
+ rc, rcok := req.Options["dht-record-count"].(int)
124
+ dhtt, dhttok := req.Options["dht-timeout"].(string)
125
var ropts []nsopts.ResolveOpt
126
if !recursive {
127
ropts = append(ropts, nsopts.Depth(1))
@@ -136,7 +146,7 @@ Resolve the value of a dnslink:
146
name = "/ipns/" + name
147
}
148
139
- output, err := resolver.Resolve(req.Context(), name, ropts...)
149
+ output, err := resolver.Resolve(req.Context, name, ropts...)
150
if err != nil {
151
res.SetError(err, cmdkit.ErrNormal)
152
return
@@ -144,21 +154,17 @@ Resolve the value of a dnslink:
154
155
// TODO: better errors (in the case of not finding the name, we get "failed to find any peer in table")
156
147
- res.SetOutput(&ResolvedPath{output})
157
+ cmds.EmitOnce(res, &ResolvedPath{output})
158
},
149
- Marshalers: cmds.MarshalerMap{
150
- cmds.Text: func(res cmds.Response) (io.Reader, error) {
151
- v, err := unwrapOutput(res.Output())
152
- if err != nil {
153
- return nil, err
154
- }
155
-
159
+ Encoders: cmds.EncoderMap{
160
+ cmds.Text: cmds.MakeEncoder(func(req *cmds.Request, w io.Writer, v interface{}) error {
161
output, ok := v.(*ResolvedPath)
162
if !ok {
158
- return nil, e.TypeErr(output, v)
163
+ return e.TypeErr(output, v)
164
}
160
- return strings.NewReader(output.Path.String() + "\n"), nil
161
- },
165
+ _, err := fmt.Fprintln(w, []byte(output.Path.String()))
166
+ return err
167
+ }),
168
},
169
Type: ResolvedPath{},
170
}
core/commands/name/ipnsps.go
renamed
+54
-38
@@ -1,16 +1,18 @@
1
-package commands
1
+package name
2
3
import (
4
"errors"
5
"io"
6
"strings"
7
8
- cmds "github.com/ipfs/go-ipfs/commands"
9
- e "github.com/ipfs/go-ipfs/core/commands/e"
8
+ "github.com/ipfs/go-ipfs/core/commands/cmdenv"
9
+ "github.com/ipfs/go-ipfs/core/commands/e"
10
11
- peer "gx/ipfs/QmQsErDt8Qgw1XrsXf2BpEzDgGWtB1YLsTAARBup5b6B9W/go-libp2p-peer"
12
- cmdkit "gx/ipfs/QmSP88ryZkHSRn1fnngAaV2Vcn63WUJzAavnRM9CVdU1Ky/go-ipfs-cmdkit"
13
- record "gx/ipfs/QmdHb9aBELnQKTVhvvA3hsQbRgUAwsWUzBP2vZ6Y5FBYvE/go-libp2p-record"
11
+ "gx/ipfs/QmPTfgFTo9PFr1PvPKyKoeMgBvYPh6cX3aDP7DHKVbnCbi/go-ipfs-cmds"
12
+ "gx/ipfs/QmQsErDt8Qgw1XrsXf2BpEzDgGWtB1YLsTAARBup5b6B9W/go-libp2p-peer"
13
+ "gx/ipfs/QmSP88ryZkHSRn1fnngAaV2Vcn63WUJzAavnRM9CVdU1Ky/go-ipfs-cmdkit"
14
+ "gx/ipfs/QmdHb9aBELnQKTVhvvA3hsQbRgUAwsWUzBP2vZ6Y5FBYvE/go-libp2p-record"
15
+ "fmt"
16
)
17
18
type ipnsPubsubState struct {
@@ -21,6 +23,10 @@ type ipnsPubsubCancel struct {
23
Canceled bool
24
}
25
26
+type stringList struct {
27
+ Strings []string
28
+}
29
+
30
// IpnsPubsubCmd is the subcommand that allows us to manage the IPNS pubsub system
31
var IpnsPubsubCmd = &cmds.Command{
32
Helptext: cmdkit.HelpText{
@@ -42,26 +48,21 @@ var ipnspsStateCmd = &cmds.Command{
48
Helptext: cmdkit.HelpText{
49
Tagline: "Query the state of IPNS pubsub",
50
},
45
- Run: func(req cmds.Request, res cmds.Response) {
46
- n, err := req.InvocContext().GetNode()
51
+ Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) {
52
+ n, err := cmdenv.GetNode(env)
53
if err != nil {
54
res.SetError(err, cmdkit.ErrNormal)
55
return
56
}
57
52
- res.SetOutput(&ipnsPubsubState{n.PSRouter != nil})
58
+ cmds.EmitOnce(res, &ipnsPubsubState{n.PSRouter != nil})
59
},
60
Type: ipnsPubsubState{},
55
- Marshalers: cmds.MarshalerMap{
56
- cmds.Text: func(res cmds.Response) (io.Reader, error) {
57
- v, err := unwrapOutput(res.Output())
58
- if err != nil {
59
- return nil, err
60
- }
61
-
61
+ Encoders: cmds.EncoderMap{
62
+ cmds.Text: cmds.MakeEncoder(func(req *cmds.Request, w io.Writer, v interface{}) error {
63
output, ok := v.(*ipnsPubsubState)
64
if !ok {
64
- return nil, e.TypeErr(output, v)
65
+ return e.TypeErr(output, v)
66
}
67
68
var state string
@@ -71,8 +72,9 @@ var ipnspsStateCmd = &cmds.Command{
72
state = "disabled"
73
}
74
74
- return strings.NewReader(state + "\n"), nil
75
- },
75
+ _, err := fmt.Fprintln(w, []byte(state))
76
+ return err
77
+ }),
78
},
79
}
80
@@ -80,8 +82,8 @@ var ipnspsSubsCmd = &cmds.Command{
82
Helptext: cmdkit.HelpText{
83
Tagline: "Show current name subscriptions",
84
},
83
- Run: func(req cmds.Request, res cmds.Response) {
84
- n, err := req.InvocContext().GetNode()
85
+ Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) {
86
+ n, err := cmdenv.GetNode(env)
87
if err != nil {
88
res.SetError(err, cmdkit.ErrNormal)
89
return
@@ -106,11 +108,11 @@ var ipnspsSubsCmd = &cmds.Command{
108
paths = append(paths, "/ipns/"+peer.IDB58Encode(pid))
109
}
110
109
- res.SetOutput(&stringList{paths})
111
+ cmds.EmitOnce(res, &stringList{paths})
112
},
113
Type: stringList{},
112
- Marshalers: cmds.MarshalerMap{
113
- cmds.Text: stringListMarshaler,
114
+ Encoders: cmds.EncoderMap{
115
+ cmds.Text: stringListMarshaler(),
116
},
117
}
118
@@ -118,8 +120,8 @@ var ipnspsCancelCmd = &cmds.Command{
120
Helptext: cmdkit.HelpText{
121
Tagline: "Cancel a name subscription",
122
},
121
- Run: func(req cmds.Request, res cmds.Response) {
122
- n, err := req.InvocContext().GetNode()
123
+ Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) {
124
+ n, err := cmdenv.GetNode(env)
125
if err != nil {
126
res.SetError(err, cmdkit.ErrNormal)
127
return
@@ -130,7 +132,7 @@ var ipnspsCancelCmd = &cmds.Command{
132
return
133
}
134
133
- name := req.Arguments()[0]
135
+ name := req.Arguments[0]
136
name = strings.TrimPrefix(name, "/ipns/")
137
pid, err := peer.IDB58Decode(name)
138
if err != nil {
@@ -139,22 +141,17 @@ var ipnspsCancelCmd = &cmds.Command{
141
}
142
143
ok := n.PSRouter.Cancel("/ipns/" + string(pid))
142
- res.SetOutput(&ipnsPubsubCancel{ok})
144
+ cmds.EmitOnce(res, &ipnsPubsubCancel{ok})
145
},
146
Arguments: []cmdkit.Argument{
147
cmdkit.StringArg("name", true, false, "Name to cancel the subscription for."),
148
},
149
Type: ipnsPubsubCancel{},
148
- Marshalers: cmds.MarshalerMap{
149
- cmds.Text: func(res cmds.Response) (io.Reader, error) {
150
- v, err := unwrapOutput(res.Output())
151
- if err != nil {
152
- return nil, err
153
- }
154
-
150
+ Encoders: cmds.EncoderMap{
151
+ cmds.Text: cmds.MakeEncoder(func(req *cmds.Request, w io.Writer, v interface{}) error {
152
output, ok := v.(*ipnsPubsubCancel)
153
if !ok {
157
- return nil, e.TypeErr(output, v)
154
+ return e.TypeErr(output, v)
155
}
156
157
var state string
@@ -164,7 +161,26 @@ var ipnspsCancelCmd = &cmds.Command{
161
state = "no subscription"
162
}
163
167
- return strings.NewReader(state + "\n"), nil
168
- },
164
+ _, err := fmt.Fprintln(w, []byte(state))
165
+ return err
166
+ }),
167
},
168
}
169
+
170
+func stringListMarshaler() cmds.EncoderFunc {
171
+ return cmds.MakeEncoder(func(req *cmds.Request, w io.Writer, v interface{}) error {
172
+ list, ok := v.(*stringList)
173
+ if !ok {
174
+ return e.TypeErr(list, v)
175
+ }
176
+
177
+ for _, s := range list.Strings {
178
+ _, err := fmt.Fprintln(w, []byte(s))
179
+ if err != nil {
180
+ return err
181
+ }
182
+ }
183
+
184
+ return nil
185
+ })
186
+}
core/commands/name/name.go
renamed
+2
-3
@@ -1,8 +1,7 @@
1
-package commands
1
+package name
2
3
import (
4
- cmds "github.com/ipfs/go-ipfs/commands"
5
-
4
+ "gx/ipfs/QmPTfgFTo9PFr1PvPKyKoeMgBvYPh6cX3aDP7DHKVbnCbi/go-ipfs-cmds"
5
"gx/ipfs/QmSP88ryZkHSRn1fnngAaV2Vcn63WUJzAavnRM9CVdU1Ky/go-ipfs-cmdkit"
6
)
7
core/commands/name/publish.go
renamed
+19
-25
@@ -1,26 +1,24 @@
1
-package commands
1
+package name
2
3
import (
4
"context"
5
"errors"
6
"fmt"
7
"io"
8
- "strings"
8
"time"
9
11
- cmds "github.com/ipfs/go-ipfs/commands"
10
core "github.com/ipfs/go-ipfs/core"
11
+ cmdenv "github.com/ipfs/go-ipfs/core/commands/cmdenv"
12
e "github.com/ipfs/go-ipfs/core/commands/e"
13
keystore "github.com/ipfs/go-ipfs/keystore"
15
- path "gx/ipfs/QmdMPBephdLYNESkruDX2hcDTgFYhoCt4LimWhgnomSdV2/go-path"
14
15
+ "gx/ipfs/QmPTfgFTo9PFr1PvPKyKoeMgBvYPh6cX3aDP7DHKVbnCbi/go-ipfs-cmds"
16
crypto "gx/ipfs/QmPvyPwuCgJ7pDmrKDxRtsScJgBaM5h4EpRL2qQJsmXf4n/go-libp2p-crypto"
17
peer "gx/ipfs/QmQsErDt8Qgw1XrsXf2BpEzDgGWtB1YLsTAARBup5b6B9W/go-libp2p-peer"
18
"gx/ipfs/QmSP88ryZkHSRn1fnngAaV2Vcn63WUJzAavnRM9CVdU1Ky/go-ipfs-cmdkit"
19
+ path "gx/ipfs/QmdMPBephdLYNESkruDX2hcDTgFYhoCt4LimWhgnomSdV2/go-path"
20
)
21
22
-var errNotOnline = errors.New("this command must be run in online mode. Try running 'ipfs daemon' first")
23
-
22
var PublishCmd = &cmds.Command{
23
Helptext: cmdkit.HelpText{
24
Tagline: "Publish IPNS names.",
@@ -73,8 +71,8 @@ Alternatively, publish an <ipfs-path> using a valid PeerID (as listed by
71
cmdkit.StringOption("ttl", "Time duration this record should be cached for (caution: experimental)."),
72
cmdkit.StringOption("key", "k", "Name of the key to be used or a valid PeerID, as listed by 'ipfs key list -l'. Default: <<default>>.").WithDefault("self"),
73
},
76
- Run: func(req cmds.Request, res cmds.Response) {
77
- n, err := req.InvocContext().GetNode()
74
+ Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) {
75
+ n, err := cmdenv.GetNode(env)
76
if err != nil {
77
res.SetError(err, cmdkit.ErrNormal)
78
return
@@ -93,7 +91,7 @@ Alternatively, publish an <ipfs-path> using a valid PeerID (as listed by
91
return
92
}
93
96
- pstr := req.Arguments()[0]
94
+ pstr := req.Arguments[0]
95
96
if n.Identity == "" {
97
res.SetError(errors.New("identity not loaded"), cmdkit.ErrNormal)
@@ -102,9 +100,9 @@ Alternatively, publish an <ipfs-path> using a valid PeerID (as listed by
100
101
popts := new(publishOpts)
102
105
- popts.verifyExists, _, _ = req.Option("resolve").Bool()
103
+ popts.verifyExists, _ = req.Options["resolve"].(bool)
104
107
- validtime, _, _ := req.Option("lifetime").String()
105
+ validtime, _ := req.Options["lifetime"].(string)
106
d, err := time.ParseDuration(validtime)
107
if err != nil {
108
res.SetError(fmt.Errorf("error parsing lifetime option: %s", err), cmdkit.ErrNormal)
@@ -113,8 +111,8 @@ Alternatively, publish an <ipfs-path> using a valid PeerID (as listed by
111
112
popts.pubValidTime = d
113
116
- ctx := req.Context()
117
- if ttl, found, _ := req.Option("ttl").String(); found {
114
+ ctx := req.Context
115
+ if ttl, found := req.Options["ttl"].(string); found {
116
d, err := time.ParseDuration(ttl)
117
if err != nil {
118
res.SetError(err, cmdkit.ErrNormal)
@@ -124,7 +122,7 @@ Alternatively, publish an <ipfs-path> using a valid PeerID (as listed by
122
ctx = context.WithValue(ctx, "ipns-publish-ttl", d)
123
}
124
127
- kname, _, _ := req.Option("key").String()
125
+ kname, _ := req.Options["key"].(string)
126
k, err := keylookup(n, kname)
127
if err != nil {
128
res.SetError(err, cmdkit.ErrNormal)
@@ -142,22 +140,18 @@ Alternatively, publish an <ipfs-path> using a valid PeerID (as listed by
140
res.SetError(err, cmdkit.ErrNormal)
141
return
142
}
145
- res.SetOutput(output)
143
+ cmds.EmitOnce(res, output)
144
},
147
- Marshalers: cmds.MarshalerMap{
148
- cmds.Text: func(res cmds.Response) (io.Reader, error) {
149
- v, err := unwrapOutput(res.Output())
150
- if err != nil {
151
- return nil, err
152
- }
145
+ Encoders: cmds.EncoderMap{
146
+ cmds.Text: cmds.MakeEncoder(func(req *cmds.Request, w io.Writer, v interface{}) error {
147
entry, ok := v.(*IpnsEntry)
148
if !ok {
155
- return nil, e.TypeErr(entry, v)
149
+ return e.TypeErr(entry, v)
150
}
151
158
- s := fmt.Sprintf("Published to %s: %s\n", entry.Name, entry.Value)
159
- return strings.NewReader(s), nil
160
- },
152
+ _, err := fmt.Fprintf(w, "Published to %s: %s\n", entry.Name, entry.Value)
153
+ return err
154
+ }),
155
},
156
Type: IpnsEntry{},
157
}
core/commands/object/patch.go
+2
-13
@@ -7,6 +7,7 @@ import (
7
8
oldcmds "github.com/ipfs/go-ipfs/commands"
9
lgc "github.com/ipfs/go-ipfs/commands/legacy"
10
+ cmdenv "github.com/ipfs/go-ipfs/core/commands/cmdenv"
11
e "github.com/ipfs/go-ipfs/core/commands/e"
12
coreiface "github.com/ipfs/go-ipfs/core/coreapi/interface"
13
"github.com/ipfs/go-ipfs/core/coreapi/interface/options"
@@ -67,7 +68,7 @@ the limit will not be respected by the network.
68
cmdkit.FileArg("data", true, false, "Data to append.").EnableStdin(),
69
},
70
Run: func(req *cmds.Request, re cmds.ResponseEmitter, env cmds.Environment) {
70
- api, err := GetApi(env)
71
+ api, err := cmdenv.GetApi(env)
72
if err != nil {
73
re.SetError(err, cmdkit.ErrNormal)
74
return
@@ -250,15 +251,3 @@ to a file containing 'bar', and returns the hash of the new object.
251
oldcmds.Text: objectMarshaler,
252
},
253
}
253
-
254
-// TODO: fix import loop with core/commands so we don't need that
255
-// COPIED FROM ONE LEVEL UP
256
-// GetApi extracts CoreAPI instance from the environment.
257
-func GetApi(env cmds.Environment) (coreiface.CoreAPI, error) {
258
- ctx, ok := env.(*oldcmds.Context)
259
- if !ok {
260
- return nil, fmt.Errorf("expected env to be of type %T, got %T", ctx, env)
261
- }
262
-
263
- return ctx.GetApi()
264
-}
core/commands/p2p.go
+1
-1
@@ -405,7 +405,7 @@ func getNode(req cmds.Request) (*core.IpfsNode, error) {
405
}
406
407
if !n.OnlineMode() {
408
- return nil, errNotOnline
408
+ return nil, ErrNotOnline
409
}
410
411
return n, nil
core/commands/ping.go
+1
-1
@@ -78,7 +78,7 @@ trip latency information.
78
79
// Must be online!
80
if !n.OnlineMode() {
81
- res.SetError(errNotOnline, cmdkit.ErrClient)
81
+ res.SetError(ErrNotOnline, cmdkit.ErrClient)
82
return
83
}
84
core/commands/pubsub.go
+9
-8
@@ -11,6 +11,7 @@ import (
11
"time"
12
13
core "github.com/ipfs/go-ipfs/core"
14
+ cmdenv "github.com/ipfs/go-ipfs/core/commands/cmdenv"
15
e "github.com/ipfs/go-ipfs/core/commands/e"
16
17
cmds "gx/ipfs/QmPTfgFTo9PFr1PvPKyKoeMgBvYPh6cX3aDP7DHKVbnCbi/go-ipfs-cmds"
@@ -73,7 +74,7 @@ This command outputs data in the following encodings:
74
cmdkit.BoolOption("discover", "try to discover other peers subscribed to the same topic"),
75
},
76
Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) {
76
- n, err := GetNode(env)
77
+ n, err := cmdenv.GetNode(env)
78
if err != nil {
79
res.SetError(err, cmdkit.ErrNormal)
80
return
@@ -81,7 +82,7 @@ This command outputs data in the following encodings:
82
83
// Must be online!
84
if !n.OnlineMode() {
84
- res.SetError(errNotOnline, cmdkit.ErrClient)
85
+ res.SetError(ErrNotOnline, cmdkit.ErrClient)
86
return
87
}
88
@@ -206,7 +207,7 @@ To use, the daemon must be run with '--enable-pubsub-experiment'.
207
cmdkit.StringArg("data", true, true, "Payload of message to publish.").EnableStdin(),
208
},
209
Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) {
209
- n, err := GetNode(env)
210
+ n, err := cmdenv.GetNode(env)
211
if err != nil {
212
res.SetError(err, cmdkit.ErrNormal)
213
return
@@ -214,7 +215,7 @@ To use, the daemon must be run with '--enable-pubsub-experiment'.
215
216
// Must be online!
217
if !n.OnlineMode() {
217
- res.SetError(errNotOnline, cmdkit.ErrClient)
218
+ res.SetError(ErrNotOnline, cmdkit.ErrClient)
219
return
220
}
221
@@ -253,7 +254,7 @@ To use, the daemon must be run with '--enable-pubsub-experiment'.
254
`,
255
},
256
Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) {
256
- n, err := GetNode(env)
257
+ n, err := cmdenv.GetNode(env)
258
if err != nil {
259
res.SetError(err, cmdkit.ErrNormal)
260
return
@@ -261,7 +262,7 @@ To use, the daemon must be run with '--enable-pubsub-experiment'.
262
263
// Must be online!
264
if !n.OnlineMode() {
264
- res.SetError(errNotOnline, cmdkit.ErrClient)
265
+ res.SetError(ErrNotOnline, cmdkit.ErrClient)
266
return
267
}
268
@@ -310,7 +311,7 @@ To use, the daemon must be run with '--enable-pubsub-experiment'.
311
cmdkit.StringArg("topic", false, false, "topic to list connected peers of"),
312
},
313
Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) {
313
- n, err := GetNode(env)
314
+ n, err := cmdenv.GetNode(env)
315
if err != nil {
316
res.SetError(err, cmdkit.ErrNormal)
317
return
@@ -318,7 +319,7 @@ To use, the daemon must be run with '--enable-pubsub-experiment'.
319
320
// Must be online!
321
if !n.OnlineMode() {
321
- res.SetError(errNotOnline, cmdkit.ErrClient)
322
+ res.SetError(ErrNotOnline, cmdkit.ErrClient)
323
return
324
}
325
core/commands/repo.go
+2
-1
@@ -11,6 +11,7 @@ import (
11
12
oldcmds "github.com/ipfs/go-ipfs/commands"
13
lgc "github.com/ipfs/go-ipfs/commands/legacy"
14
+ cmdenv "github.com/ipfs/go-ipfs/core/commands/cmdenv"
15
e "github.com/ipfs/go-ipfs/core/commands/e"
16
corerepo "github.com/ipfs/go-ipfs/core/corerepo"
17
fsrepo "github.com/ipfs/go-ipfs/repo/fsrepo"
@@ -165,7 +166,7 @@ Version string The repo version.
166
cmdkit.BoolOption("human", "Output sizes in MiB."),
167
},
168
Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) {
168
- n, err := GetNode(env)
169
+ n, err := cmdenv.GetNode(env)
170
if err != nil {
171
res.SetError(err, cmdkit.ErrNormal)
172
return
core/commands/resolve.go
+5
-8
@@ -9,6 +9,7 @@ import (
9
cmds "github.com/ipfs/go-ipfs/commands"
10
"github.com/ipfs/go-ipfs/core"
11
e "github.com/ipfs/go-ipfs/core/commands/e"
12
+ ncmd "github.com/ipfs/go-ipfs/core/commands/name"
13
ns "github.com/ipfs/go-ipfs/namesys"
14
nsopts "github.com/ipfs/go-ipfs/namesys/opts"
15
path "gx/ipfs/QmdMPBephdLYNESkruDX2hcDTgFYhoCt4LimWhgnomSdV2/go-path"
@@ -16,10 +17,6 @@ import (
17
"gx/ipfs/QmSP88ryZkHSRn1fnngAaV2Vcn63WUJzAavnRM9CVdU1Ky/go-ipfs-cmdkit"
18
)
19
19
-type ResolvedPath struct {
20
- Path path.Path
21
-}
22
-
20
var ResolveCmd = &cmds.Command{
21
Helptext: cmdkit.HelpText{
22
Tagline: "Resolve the value of names to IPFS.",
@@ -113,7 +110,7 @@ Resolve the value of an IPFS DAG path:
110
res.SetError(err, cmdkit.ErrNormal)
111
return
112
}
116
- res.SetOutput(&ResolvedPath{p})
113
+ res.SetOutput(&ncmd.ResolvedPath{Path: p})
114
return
115
}
116
@@ -132,7 +129,7 @@ Resolve the value of an IPFS DAG path:
129
130
c := node.Cid()
131
135
- res.SetOutput(&ResolvedPath{path.FromCid(c)})
132
+ res.SetOutput(&ncmd.ResolvedPath{Path: path.FromCid(c)})
133
},
134
Marshalers: cmds.MarshalerMap{
135
cmds.Text: func(res cmds.Response) (io.Reader, error) {
@@ -141,12 +138,12 @@ Resolve the value of an IPFS DAG path:
138
return nil, err
139
}
140
144
- output, ok := v.(*ResolvedPath)
141
+ output, ok := v.(*ncmd.ResolvedPath)
142
if !ok {
143
return nil, e.TypeErr(output, v)
144
}
145
return strings.NewReader(output.Path.String() + "\n"), nil
146
},
147
},
151
- Type: ResolvedPath{},
148
+ Type: ncmd.ResolvedPath{},
149
}
core/commands/root.go
+9
-5
@@ -1,6 +1,7 @@
1
package commands
2
3
import (
4
+ "errors"
5
"io"
6
"strings"
7
@@ -8,6 +9,7 @@ import (
9
lgc "github.com/ipfs/go-ipfs/commands/legacy"
10
dag "github.com/ipfs/go-ipfs/core/commands/dag"
11
e "github.com/ipfs/go-ipfs/core/commands/e"
12
+ name "github.com/ipfs/go-ipfs/core/commands/name"
13
ocmd "github.com/ipfs/go-ipfs/core/commands/object"
14
unixfs "github.com/ipfs/go-ipfs/core/commands/unixfs"
15
@@ -18,6 +20,8 @@ import (
20
21
var log = logging.Logger("core/commands")
22
23
+var ErrNotOnline = errors.New("this command must be run in online mode. Try running 'ipfs daemon' first")
24
+
25
const (
26
ApiOption = "api"
27
)
@@ -125,7 +129,7 @@ var rootSubcommands = map[string]*cmds.Command{
129
"log": lgc.NewCommand(LogCmd),
130
"ls": lgc.NewCommand(LsCmd),
131
"mount": lgc.NewCommand(MountCmd),
128
- "name": lgc.NewCommand(NameCmd),
132
+ "name": name.NameCmd,
133
"object": ocmd.ObjectCmd,
134
"pin": lgc.NewCommand(PinCmd),
135
"ping": lgc.NewCommand(PingCmd),
@@ -160,11 +164,11 @@ var rootROSubcommands = map[string]*cmds.Command{
164
"get": GetCmd,
165
"dns": lgc.NewCommand(DNSCmd),
166
"ls": lgc.NewCommand(LsCmd),
163
- "name": lgc.NewCommand(&oldcmds.Command{
164
- Subcommands: map[string]*oldcmds.Command{
165
- "resolve": IpnsCmd,
167
+ "name": &cmds.Command{
168
+ Subcommands: map[string]*cmds.Command{
169
+ "resolve": name.IpnsCmd,
170
},
167
- }),
171
+ },
172
"object": lgc.NewCommand(&oldcmds.Command{
173
Subcommands: map[string]*oldcmds.Command{
174
"data": ocmd.ObjectDataCmd,
core/commands/shutdown.go
+3
-1
@@ -3,6 +3,8 @@ package commands
3
import (
4
"fmt"
5
6
+ cmdenv "github.com/ipfs/go-ipfs/core/commands/cmdenv"
7
+
8
cmds "gx/ipfs/QmPTfgFTo9PFr1PvPKyKoeMgBvYPh6cX3aDP7DHKVbnCbi/go-ipfs-cmds"
9
"gx/ipfs/QmSP88ryZkHSRn1fnngAaV2Vcn63WUJzAavnRM9CVdU1Ky/go-ipfs-cmdkit"
10
)
@@ -12,7 +14,7 @@ var daemonShutdownCmd = &cmds.Command{
14
Tagline: "Shut down the ipfs daemon",
15
},
16
Run: func(req *cmds.Request, re cmds.ResponseEmitter, env cmds.Environment) {
15
- nd, err := GetNode(env)
17
+ nd, err := cmdenv.GetNode(env)
18
if err != nil {
19
re.SetError(err, cmdkit.ErrNormal)
20
return
core/commands/stat.go
+4
-2
@@ -7,6 +7,8 @@ import (
7
"os"
8
"time"
9
10
+ cmdenv "github.com/ipfs/go-ipfs/core/commands/cmdenv"
11
+
12
humanize "gx/ipfs/QmPSBJL4momYnE7DcUyk2DVhD6rH488ZmHBGLbxNdhU44K/go-humanize"
13
cmds "gx/ipfs/QmPTfgFTo9PFr1PvPKyKoeMgBvYPh6cX3aDP7DHKVbnCbi/go-ipfs-cmds"
14
peer "gx/ipfs/QmQsErDt8Qgw1XrsXf2BpEzDgGWtB1YLsTAARBup5b6B9W/go-libp2p-peer"
@@ -80,7 +82,7 @@ Example:
82
},
83
84
Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) {
83
- nd, err := GetNode(env)
85
+ nd, err := cmdenv.GetNode(env)
86
if err != nil {
87
res.SetError(err, cmdkit.ErrNormal)
88
return
@@ -88,7 +90,7 @@ Example:
90
91
// Must be online!
92
if !nd.OnlineMode() {
91
- res.SetError(errNotOnline, cmdkit.ErrClient)
93
+ res.SetError(ErrNotOnline, cmdkit.ErrClient)
94
return
95
}
96
core/commands/swarm.go
+9
-9
@@ -72,7 +72,7 @@ var swarmPeersCmd = &cmds.Command{
72
}
73
74
if n.PeerHost == nil {
75
- res.SetError(errNotOnline, cmdkit.ErrClient)
75
+ res.SetError(ErrNotOnline, cmdkit.ErrClient)
76
return
77
}
78
@@ -223,7 +223,7 @@ var swarmAddrsCmd = &cmds.Command{
223
}
224
225
if n.PeerHost == nil {
226
- res.SetError(errNotOnline, cmdkit.ErrClient)
226
+ res.SetError(ErrNotOnline, cmdkit.ErrClient)
227
return
228
}
229
@@ -291,7 +291,7 @@ var swarmAddrsLocalCmd = &cmds.Command{
291
}
292
293
if n.PeerHost == nil {
294
- res.SetError(errNotOnline, cmdkit.ErrClient)
294
+ res.SetError(ErrNotOnline, cmdkit.ErrClient)
295
return
296
}
297
@@ -331,7 +331,7 @@ var swarmAddrsListenCmd = &cmds.Command{
331
}
332
333
if n.PeerHost == nil {
334
- res.SetError(errNotOnline, cmdkit.ErrClient)
334
+ res.SetError(ErrNotOnline, cmdkit.ErrClient)
335
return
336
}
337
@@ -381,7 +381,7 @@ ipfs swarm connect /ip4/104.131.131.82/tcp/4001/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3
381
addrs := req.Arguments()
382
383
if n.PeerHost == nil {
384
- res.SetError(errNotOnline, cmdkit.ErrClient)
384
+ res.SetError(ErrNotOnline, cmdkit.ErrClient)
385
return
386
}
387
@@ -446,7 +446,7 @@ it will reconnect.
446
addrs := req.Arguments()
447
448
if n.PeerHost == nil {
449
- res.SetError(errNotOnline, cmdkit.ErrClient)
449
+ res.SetError(ErrNotOnline, cmdkit.ErrClient)
450
return
451
}
452
@@ -593,7 +593,7 @@ Filters default to those specified under the "Swarm.AddrFilters" config key.
593
}
594
595
if n.PeerHost == nil {
596
- res.SetError(errNotOnline, cmdkit.ErrNormal)
596
+ res.SetError(ErrNotOnline, cmdkit.ErrNormal)
597
return
598
}
599
@@ -641,7 +641,7 @@ add your filters to the ipfs config file.
641
}
642
643
if n.PeerHost == nil {
644
- res.SetError(errNotOnline, cmdkit.ErrNormal)
644
+ res.SetError(ErrNotOnline, cmdkit.ErrNormal)
645
return
646
}
647
@@ -714,7 +714,7 @@ remove your filters from the ipfs config file.
714
}
715
716
if n.PeerHost == nil {
717
- res.SetError(errNotOnline, cmdkit.ErrNormal)
717
+ res.SetError(ErrNotOnline, cmdkit.ErrNormal)
718
return
719
}
720
core/commands/urlstore.go
+5
-4
@@ -5,13 +5,14 @@ import (
5
"io"
6
"net/http"
7
8
+ cmdenv "github.com/ipfs/go-ipfs/core/commands/cmdenv"
9
filestore "github.com/ipfs/go-ipfs/filestore"
9
- balanced "gx/ipfs/QmQjEpRiwVvtowhq69dAtB4jhioPVFXiCcWZm9Sfgn7eqc/go-unixfs/importer/balanced"
10
- ihelper "gx/ipfs/QmQjEpRiwVvtowhq69dAtB4jhioPVFXiCcWZm9Sfgn7eqc/go-unixfs/importer/helpers"
11
- trickle "gx/ipfs/QmQjEpRiwVvtowhq69dAtB4jhioPVFXiCcWZm9Sfgn7eqc/go-unixfs/importer/trickle"
10
11
cmds "gx/ipfs/QmPTfgFTo9PFr1PvPKyKoeMgBvYPh6cX3aDP7DHKVbnCbi/go-ipfs-cmds"
12
mh "gx/ipfs/QmPnFwZ2JXKnXgMw8CdBPxn7FWh6LLdjUjxV1fKHuJnkr8/go-multihash"
13
+ balanced "gx/ipfs/QmQjEpRiwVvtowhq69dAtB4jhioPVFXiCcWZm9Sfgn7eqc/go-unixfs/importer/balanced"
14
+ ihelper "gx/ipfs/QmQjEpRiwVvtowhq69dAtB4jhioPVFXiCcWZm9Sfgn7eqc/go-unixfs/importer/helpers"
15
+ trickle "gx/ipfs/QmQjEpRiwVvtowhq69dAtB4jhioPVFXiCcWZm9Sfgn7eqc/go-unixfs/importer/trickle"
16
cmdkit "gx/ipfs/QmSP88ryZkHSRn1fnngAaV2Vcn63WUJzAavnRM9CVdU1Ky/go-ipfs-cmdkit"
17
chunk "gx/ipfs/QmXzBbJo2sLf3uwjNTeoWYiJV7CjAhkiA4twtLvwJSSNdK/go-ipfs-chunker"
18
cid "gx/ipfs/QmZFbDTY9jfSBms2MchvYM9oYRbAF19K7Pby47yDBfpPrb/go-cid"
@@ -53,7 +54,7 @@ time.
54
55
Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) {
56
url := req.Arguments[0]
56
- n, err := GetNode(env)
57
+ n, err := cmdenv.GetNode(env)
58
if err != nil {
59
res.SetError(err, cmdkit.ErrNormal)
60
return