@cryptotaxi247 / kubo / commits / 5d301cb8e

re-enable the stdin

License: MIT Signed-off-by: Jeromy <why@ipfs.io>

Jeromy committed Jul 8, 2016 at 16:39 UTC 5d301cb8ec7c8a7d61921f208114296f989ae06a
17 files changed +39 -59
core/commands/bootstrap.go
+8 -8
@@ -132,13 +132,13 @@ var bootstrapRemoveCmd = &cmds.Command{
132 },
133
134 Arguments: []cmds.Argument{
135 - cmds.StringArg("peer", false, true, peerOptionDesc),
135 + cmds.StringArg("peer", false, true, peerOptionDesc).EnableStdin(),
136 },
137 Options: []cmds.Option{
138 cmds.BoolOption("all", "Remove all bootstrap peers.").Default(false),
139 },
140 Run: func(req cmds.Request, res cmds.Response) {
141 - input, err := config.ParseBootstrapPeers(req.Arguments())
141 + all, _, err := req.Option("all").Bool()
142 if err != nil {
143 res.SetError(err, cmds.ErrNormal)
144 return
@@ -156,16 +156,16 @@ var bootstrapRemoveCmd = &cmds.Command{
156 return
157 }
158
159 - all, _, err := req.Option("all").Bool()
160 - if err != nil {
161 - res.SetError(err, cmds.ErrNormal)
162 - return
163 - }
164 -
159 var removed []config.BootstrapPeer
160 if all {
161 removed, err = bootstrapRemoveAll(r, cfg)
162 } else {
163 + input, perr := config.ParseBootstrapPeers(req.Arguments())
164 + if perr != nil {
165 + res.SetError(perr, cmds.ErrNormal)
166 + return
167 + }
168 +
169 removed, err = bootstrapRemove(r, cfg, input)
170 }
171 if err != nil {
core/commands/cat.go
+1 -1
@@ -20,7 +20,7 @@ var CatCmd = &cmds.Command{
20 },
21
22 Arguments: []cmds.Argument{
23 - cmds.StringArg("ipfs-path", true, true, "The path to the IPFS object(s) to be outputted."),
23 + cmds.StringArg("ipfs-path", true, true, "The path to the IPFS object(s) to be outputted.").EnableStdin(),
24 },
25 Run: func(req cmds.Request, res cmds.Response) {
26 node, err := req.InvocContext().GetNode()
core/commands/dht.go
+1 -1
@@ -459,7 +459,7 @@ NOTE: A value may not exceed 2048 bytes.
459
460 Arguments: []cmds.Argument{
461 cmds.StringArg("key", true, false, "The key to store the value at."),
462 - cmds.StringArg("value", true, false, "The value to store."),
462 + cmds.StringArg("value", true, false, "The value to store.").EnableStdin(),
463 },
464 Options: []cmds.Option{
465 cmds.BoolOption("verbose", "v", "Print extra information.").Default(false),
core/commands/dns.go
+1 -1
@@ -44,7 +44,7 @@ The resolver can recursively resolve:
44 },
45
46 Arguments: []cmds.Argument{
47 - cmds.StringArg("domain-name", true, false, "The domain-name name to resolve."),
47 + cmds.StringArg("domain-name", true, false, "The domain-name name to resolve.").EnableStdin(),
48 },
49 Options: []cmds.Option{
50 cmds.BoolOption("recursive", "r", "Resolve until the result is not a DNS link.").Default(false),
core/commands/get.go
+1 -1
@@ -37,7 +37,7 @@ may also specify the level of compression by specifying '-l=<1-9>'.
37 },
38
39 Arguments: []cmds.Argument{
40 - cmds.StringArg("ipfs-path", true, false, "The path to the IPFS object(s) to be outputted."),
40 + cmds.StringArg("ipfs-path", true, false, "The path to the IPFS object(s) to be outputted.").EnableStdin(),
41 },
42 Options: []cmds.Option{
43 cmds.StringOption("output", "o", "The path where the output should be stored."),
core/commands/id.go
+1 -1
@@ -58,7 +58,7 @@ EXAMPLE:
58 `,
59 },
60 Arguments: []cmds.Argument{
61 - cmds.StringArg("peerid", false, false, "Peer.ID of node to look up."),
61 + cmds.StringArg("peerid", false, false, "Peer.ID of node to look up.").EnableStdin(),
62 },
63 Options: []cmds.Option{
64 cmds.StringOption("format", "f", "Optional output format."),
core/commands/ls.go
+1 -1
@@ -42,7 +42,7 @@ format:
42 },
43
44 Arguments: []cmds.Argument{
45 - cmds.StringArg("ipfs-path", true, true, "The path to the IPFS object(s) to list links from."),
45 + cmds.StringArg("ipfs-path", true, true, "The path to the IPFS object(s) to list links from.").EnableStdin(),
46 },
47 Options: []cmds.Option{
48 cmds.BoolOption("headers", "v", "Print table headers (Hash, Size, Name).").Default(false),
core/commands/object/object.go
+4 -4
@@ -78,7 +78,7 @@ is the raw data of the object.
78 },
79
80 Arguments: []cmds.Argument{
81 - cmds.StringArg("key", true, false, "Key of the object to retrieve, in base58-encoded multihash format."),
81 + cmds.StringArg("key", true, false, "Key of the object to retrieve, in base58-encoded multihash format.").EnableStdin(),
82 },
83 Run: func(req cmds.Request, res cmds.Response) {
84 n, err := req.InvocContext().GetNode()
@@ -108,7 +108,7 @@ multihash.
108 },
109
110 Arguments: []cmds.Argument{
111 - cmds.StringArg("key", true, false, "Key of the object to retrieve, in base58-encoded multihash format."),
111 + cmds.StringArg("key", true, false, "Key of the object to retrieve, in base58-encoded multihash format.").EnableStdin(),
112 },
113 Options: []cmds.Option{
114 cmds.BoolOption("headers", "v", "Print table headers (Hash, Size, Name).").Default(false),
@@ -179,7 +179,7 @@ This command outputs data in the following encodings:
179 },
180
181 Arguments: []cmds.Argument{
182 - cmds.StringArg("key", true, false, "Key of the object to retrieve, in base58-encoded multihash format."),
182 + cmds.StringArg("key", true, false, "Key of the object to retrieve, in base58-encoded multihash format.").EnableStdin(),
183 },
184 Run: func(req cmds.Request, res cmds.Response) {
185 n, err := req.InvocContext().GetNode()
@@ -246,7 +246,7 @@ var ObjectStatCmd = &cmds.Command{
246 },
247
248 Arguments: []cmds.Argument{
249 - cmds.StringArg("key", true, false, "Key of the object to retrieve, in base58-encoded multihash format."),
249 + cmds.StringArg("key", true, false, "Key of the object to retrieve, in base58-encoded multihash format.").EnableStdin(),
250 },
251 Run: func(req cmds.Request, res cmds.Response) {
252 n, err := req.InvocContext().GetNode()
core/commands/pin.go
+6 -7
@@ -71,6 +71,11 @@ var addPinCmd = &cmds.Command{
71 },
72 Marshalers: cmds.MarshalerMap{
73 cmds.Text: func(res cmds.Response) (io.Reader, error) {
74 + added, ok := res.Output().(*PinOutput)
75 + if !ok {
76 + return nil, u.ErrCast()
77 + }
78 +
79 var pintype string
80 rec, found, _ := res.Request().Option("recursive").Bool()
81 if rec || !found {
@@ -79,17 +84,11 @@ var addPinCmd = &cmds.Command{
84 pintype = "directly"
85 }
86
82 - po, ok := res.Output().(*PinOutput)
83 - if !ok {
84 - return nil, u.ErrCast()
85 - }
86 -
87 buf := new(bytes.Buffer)
88 - for _, k := range po.Pins {
88 + for _, k := range added.Pins {
89 fmt.Fprintf(buf, "pinned %s %s\n", k, pintype)
90 }
91 return buf, nil
92 -
92 },
93 },
94 }
core/commands/ping.go
+1 -1
@@ -36,7 +36,7 @@ trip latency information.
36 `,
37 },
38 Arguments: []cmds.Argument{
39 - cmds.StringArg("peer ID", true, true, "ID of peer to be pinged."),
39 + cmds.StringArg("peer ID", true, true, "ID of peer to be pinged.").EnableStdin(),
40 },
41 Options: []cmds.Option{
42 cmds.IntOption("count", "n", "Number of ping messages to send.").Default(10),
core/commands/publish.go
+1 -1
@@ -47,7 +47,7 @@ Publish an <ipfs-path> to another public key (not implemented):
47 },
48
49 Arguments: []cmds.Argument{
50 - cmds.StringArg("ipfs-path", true, false, "IPFS path of the object to be published."),
50 + cmds.StringArg("ipfs-path", true, false, "IPFS path of the object to be published.").EnableStdin(),
51 },
52 Options: []cmds.Option{
53 cmds.BoolOption("resolve", "Resolve given path before publishing.").Default(true),
core/commands/refs.go
+1 -1
@@ -46,7 +46,7 @@ NOTE: List all references recursively by using the flag '-r'.
46 "local": RefsLocalCmd,
47 },
48 Arguments: []cmds.Argument{
49 - cmds.StringArg("ipfs-path", true, true, "Path to the object(s) to list refs from."),
49 + cmds.StringArg("ipfs-path", true, true, "Path to the object(s) to list refs from.").EnableStdin(),
50 },
51 Options: []cmds.Option{
52 cmds.StringOption("format", "Emit edges with given format. Available tokens: <src> <dst> <linkname>.").Default("<dst>"),
core/commands/resolve.go
+1 -1
@@ -56,7 +56,7 @@ Resolve the value of an IPFS DAG path:
56 },
57
58 Arguments: []cmds.Argument{
59 - cmds.StringArg("name", true, false, "The name to resolve."),
59 + cmds.StringArg("name", true, false, "The name to resolve.").EnableStdin(),
60 },
61 Options: []cmds.Option{
62 cmds.BoolOption("recursive", "r", "Resolve until the result is an IPFS name.").Default(false),
core/commands/swarm.go
+4 -4
@@ -215,7 +215,7 @@ ipfs swarm connect /ip4/104.131.131.82/tcp/4001/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3
215 `,
216 },
217 Arguments: []cmds.Argument{
218 - cmds.StringArg("address", true, true, "Address of peer to connect to."),
218 + cmds.StringArg("address", true, true, "Address of peer to connect to.").EnableStdin(),
219 },
220 Run: func(req cmds.Request, res cmds.Response) {
221 ctx := req.Context()
@@ -283,7 +283,7 @@ it will reconnect.
283 `,
284 },
285 Arguments: []cmds.Argument{
286 - cmds.StringArg("address", true, true, "Address of peer to disconnect from."),
286 + cmds.StringArg("address", true, true, "Address of peer to disconnect from.").EnableStdin(),
287 },
288 Run: func(req cmds.Request, res cmds.Response) {
289 n, err := req.InvocContext().GetNode()
@@ -451,7 +451,7 @@ add your filters to the ipfs config file.
451 `,
452 },
453 Arguments: []cmds.Argument{
454 - cmds.StringArg("address", true, true, "Multiaddr to filter."),
454 + cmds.StringArg("address", true, true, "Multiaddr to filter.").EnableStdin(),
455 },
456 Run: func(req cmds.Request, res cmds.Response) {
457 n, err := req.InvocContext().GetNode()
@@ -523,7 +523,7 @@ remove your filters from the ipfs config file.
523 `,
524 },
525 Arguments: []cmds.Argument{
526 - cmds.StringArg("address", true, true, "Multiaddr filter to remove."),
526 + cmds.StringArg("address", true, true, "Multiaddr filter to remove.").EnableStdin(),
527 },
528 Run: func(req cmds.Request, res cmds.Response) {
529 n, err := req.InvocContext().GetNode()
core/commands/tar.go
+1 -1
@@ -83,7 +83,7 @@ var tarCatCmd = &cmds.Command{
83 },
84
85 Arguments: []cmds.Argument{
86 - cmds.StringArg("path", true, false, "IPFS path of archive to export."),
86 + cmds.StringArg("path", true, false, "IPFS path of archive to export.").EnableStdin(),
87 },
88 Run: func(req cmds.Request, res cmds.Response) {
89 nd, err := req.InvocContext().GetNode()
core/commands/unixfs/ls.go
+1 -1
@@ -63,7 +63,7 @@ Example:
63 },
64
65 Arguments: []cmds.Argument{
66 - cmds.StringArg("ipfs-path", true, true, "The path to the IPFS object(s) to list links from."),
66 + cmds.StringArg("ipfs-path", true, true, "The path to the IPFS object(s) to list links from.").EnableStdin(),
67 },
68 Run: func(req cmds.Request, res cmds.Response) {
69 node, err := req.InvocContext().GetNode()
test/sharness/t0040-add-and-cat.sh
+5 -24
@@ -212,7 +212,7 @@ test_expect_success "ipfs cat output looks good" '
212 '
213
214 test_expect_success "ipfs cat accept hash from built input" '
215 - echo "$HASH" | xargs ipfs cat >actual
215 + echo "$HASH" | ipfs cat >actual
216 '
217
218 test_expect_success "ipfs cat output looks good" '
@@ -268,7 +268,7 @@ test_expect_success "'ipfs add' output looks good" '
268 '
269
270 test_expect_success "'ipfs cat' with built input succeeds" '
271 - echo "$HASH" | xargs ipfs cat >actual
271 + echo "$HASH" | ipfs cat >actual
272 '
273
274 test_expect_success "ipfs cat with built input output looks good" '
@@ -319,7 +319,7 @@ test_expect_success "'ipfs add -rn' output looks good" '
319 '
320
321 test_expect_success "ipfs cat accept many hashes from built input" '
322 - { echo "$MARS"; echo "$VENUS"; } | xargs ipfs cat >actual
322 + { echo "$MARS"; echo "$VENUS"; } | ipfs cat >actual
323 '
324
325 test_expect_success "ipfs cat output looks good" '
@@ -335,28 +335,9 @@ test_expect_success "ipfs cat output looks good" '
335 test_cmp expected actual
336 '
337
338 -test_expect_success "ipfs cat with both arg and built input" '
339 - echo "$MARS" | xargs ipfs cat "$VENUS" >actual
340 -'
341 -
342 -test_expect_success "ipfs cat output looks good" '
343 - cat mountdir/planets/venus.txt mountdir/planets/mars.txt >expected &&
344 - test_cmp expected actual
345 -'
346 -
347 -test_expect_success "ipfs cat with two args and built input" '
348 - echo "$MARS" | xargs ipfs cat "$VENUS" "$VENUS" >actual
349 -'
350 -
351 -test_expect_success "ipfs cat output looks good" '
352 - cat mountdir/planets/venus.txt mountdir/planets/venus.txt \
353 - mountdir/planets/mars.txt >expected &&
354 - test_cmp expected actual
355 -'
356 -
338 test_expect_success "go-random is installed" '
358 - type random
359 - '
339 + type random
340 +'
341
342 test_add_cat_5MB
343