From 5d301cb8ec7c8a7d61921f208114296f989ae06a Mon Sep 17 00:00:00 2001 From: Jeromy Date: Fri, 8 Jul 2016 16:39:15 -0700 Subject: [PATCH] re-enable the stdin License: MIT Signed-off-by: Jeromy --- core/commands/bootstrap.go | 16 ++++++++-------- core/commands/cat.go | 2 +- core/commands/dht.go | 2 +- core/commands/dns.go | 2 +- core/commands/get.go | 2 +- core/commands/id.go | 2 +- core/commands/ls.go | 2 +- core/commands/object/object.go | 8 ++++---- core/commands/pin.go | 13 ++++++------- core/commands/ping.go | 2 +- core/commands/publish.go | 2 +- core/commands/refs.go | 2 +- core/commands/resolve.go | 2 +- core/commands/swarm.go | 8 ++++---- core/commands/tar.go | 2 +- core/commands/unixfs/ls.go | 2 +- test/sharness/t0040-add-and-cat.sh | 29 +++++------------------------ 17 files changed, 39 insertions(+), 59 deletions(-) diff --git a/core/commands/bootstrap.go b/core/commands/bootstrap.go index 1eebd7550..8ff9881c9 100644 --- a/core/commands/bootstrap.go +++ b/core/commands/bootstrap.go @@ -132,13 +132,13 @@ var bootstrapRemoveCmd = &cmds.Command{ }, Arguments: []cmds.Argument{ - cmds.StringArg("peer", false, true, peerOptionDesc), + cmds.StringArg("peer", false, true, peerOptionDesc).EnableStdin(), }, Options: []cmds.Option{ cmds.BoolOption("all", "Remove all bootstrap peers.").Default(false), }, Run: func(req cmds.Request, res cmds.Response) { - input, err := config.ParseBootstrapPeers(req.Arguments()) + all, _, err := req.Option("all").Bool() if err != nil { res.SetError(err, cmds.ErrNormal) return @@ -156,16 +156,16 @@ var bootstrapRemoveCmd = &cmds.Command{ return } - all, _, err := req.Option("all").Bool() - if err != nil { - res.SetError(err, cmds.ErrNormal) - return - } - var removed []config.BootstrapPeer if all { removed, err = bootstrapRemoveAll(r, cfg) } else { + input, perr := config.ParseBootstrapPeers(req.Arguments()) + if perr != nil { + res.SetError(perr, cmds.ErrNormal) + return + } + removed, err = bootstrapRemove(r, cfg, input) } if err != nil { diff --git a/core/commands/cat.go b/core/commands/cat.go index 062dd78ab..a42bc2406 100644 --- a/core/commands/cat.go +++ b/core/commands/cat.go @@ -20,7 +20,7 @@ var CatCmd = &cmds.Command{ }, Arguments: []cmds.Argument{ - cmds.StringArg("ipfs-path", true, true, "The path to the IPFS object(s) to be outputted."), + cmds.StringArg("ipfs-path", true, true, "The path to the IPFS object(s) to be outputted.").EnableStdin(), }, Run: func(req cmds.Request, res cmds.Response) { node, err := req.InvocContext().GetNode() diff --git a/core/commands/dht.go b/core/commands/dht.go index d9bc60178..2d1149427 100644 --- a/core/commands/dht.go +++ b/core/commands/dht.go @@ -459,7 +459,7 @@ NOTE: A value may not exceed 2048 bytes. Arguments: []cmds.Argument{ cmds.StringArg("key", true, false, "The key to store the value at."), - cmds.StringArg("value", true, false, "The value to store."), + cmds.StringArg("value", true, false, "The value to store.").EnableStdin(), }, Options: []cmds.Option{ cmds.BoolOption("verbose", "v", "Print extra information.").Default(false), diff --git a/core/commands/dns.go b/core/commands/dns.go index c60fae48d..3468aed2a 100644 --- a/core/commands/dns.go +++ b/core/commands/dns.go @@ -44,7 +44,7 @@ The resolver can recursively resolve: }, Arguments: []cmds.Argument{ - cmds.StringArg("domain-name", true, false, "The domain-name name to resolve."), + cmds.StringArg("domain-name", true, false, "The domain-name name to resolve.").EnableStdin(), }, Options: []cmds.Option{ cmds.BoolOption("recursive", "r", "Resolve until the result is not a DNS link.").Default(false), diff --git a/core/commands/get.go b/core/commands/get.go index 16b8cf912..784f4ced7 100644 --- a/core/commands/get.go +++ b/core/commands/get.go @@ -37,7 +37,7 @@ may also specify the level of compression by specifying '-l=<1-9>'. }, Arguments: []cmds.Argument{ - cmds.StringArg("ipfs-path", true, false, "The path to the IPFS object(s) to be outputted."), + cmds.StringArg("ipfs-path", true, false, "The path to the IPFS object(s) to be outputted.").EnableStdin(), }, Options: []cmds.Option{ cmds.StringOption("output", "o", "The path where the output should be stored."), diff --git a/core/commands/id.go b/core/commands/id.go index 28ddb1dda..5d8338447 100644 --- a/core/commands/id.go +++ b/core/commands/id.go @@ -58,7 +58,7 @@ EXAMPLE: `, }, Arguments: []cmds.Argument{ - cmds.StringArg("peerid", false, false, "Peer.ID of node to look up."), + cmds.StringArg("peerid", false, false, "Peer.ID of node to look up.").EnableStdin(), }, Options: []cmds.Option{ cmds.StringOption("format", "f", "Optional output format."), diff --git a/core/commands/ls.go b/core/commands/ls.go index b9ccf1e73..9bcfd7956 100644 --- a/core/commands/ls.go +++ b/core/commands/ls.go @@ -42,7 +42,7 @@ format: }, Arguments: []cmds.Argument{ - cmds.StringArg("ipfs-path", true, true, "The path to the IPFS object(s) to list links from."), + cmds.StringArg("ipfs-path", true, true, "The path to the IPFS object(s) to list links from.").EnableStdin(), }, Options: []cmds.Option{ cmds.BoolOption("headers", "v", "Print table headers (Hash, Size, Name).").Default(false), diff --git a/core/commands/object/object.go b/core/commands/object/object.go index c08d15d09..5c9ed3b4e 100644 --- a/core/commands/object/object.go +++ b/core/commands/object/object.go @@ -78,7 +78,7 @@ is the raw data of the object. }, Arguments: []cmds.Argument{ - cmds.StringArg("key", true, false, "Key of the object to retrieve, in base58-encoded multihash format."), + cmds.StringArg("key", true, false, "Key of the object to retrieve, in base58-encoded multihash format.").EnableStdin(), }, Run: func(req cmds.Request, res cmds.Response) { n, err := req.InvocContext().GetNode() @@ -108,7 +108,7 @@ multihash. }, Arguments: []cmds.Argument{ - cmds.StringArg("key", true, false, "Key of the object to retrieve, in base58-encoded multihash format."), + cmds.StringArg("key", true, false, "Key of the object to retrieve, in base58-encoded multihash format.").EnableStdin(), }, Options: []cmds.Option{ cmds.BoolOption("headers", "v", "Print table headers (Hash, Size, Name).").Default(false), @@ -179,7 +179,7 @@ This command outputs data in the following encodings: }, Arguments: []cmds.Argument{ - cmds.StringArg("key", true, false, "Key of the object to retrieve, in base58-encoded multihash format."), + cmds.StringArg("key", true, false, "Key of the object to retrieve, in base58-encoded multihash format.").EnableStdin(), }, Run: func(req cmds.Request, res cmds.Response) { n, err := req.InvocContext().GetNode() @@ -246,7 +246,7 @@ var ObjectStatCmd = &cmds.Command{ }, Arguments: []cmds.Argument{ - cmds.StringArg("key", true, false, "Key of the object to retrieve, in base58-encoded multihash format."), + cmds.StringArg("key", true, false, "Key of the object to retrieve, in base58-encoded multihash format.").EnableStdin(), }, Run: func(req cmds.Request, res cmds.Response) { n, err := req.InvocContext().GetNode() diff --git a/core/commands/pin.go b/core/commands/pin.go index c9c95d063..0842b35ca 100644 --- a/core/commands/pin.go +++ b/core/commands/pin.go @@ -71,6 +71,11 @@ var addPinCmd = &cmds.Command{ }, Marshalers: cmds.MarshalerMap{ cmds.Text: func(res cmds.Response) (io.Reader, error) { + added, ok := res.Output().(*PinOutput) + if !ok { + return nil, u.ErrCast() + } + var pintype string rec, found, _ := res.Request().Option("recursive").Bool() if rec || !found { @@ -79,17 +84,11 @@ var addPinCmd = &cmds.Command{ pintype = "directly" } - po, ok := res.Output().(*PinOutput) - if !ok { - return nil, u.ErrCast() - } - buf := new(bytes.Buffer) - for _, k := range po.Pins { + for _, k := range added.Pins { fmt.Fprintf(buf, "pinned %s %s\n", k, pintype) } return buf, nil - }, }, } diff --git a/core/commands/ping.go b/core/commands/ping.go index ea80659f0..9659b2b9e 100644 --- a/core/commands/ping.go +++ b/core/commands/ping.go @@ -36,7 +36,7 @@ trip latency information. `, }, Arguments: []cmds.Argument{ - cmds.StringArg("peer ID", true, true, "ID of peer to be pinged."), + cmds.StringArg("peer ID", true, true, "ID of peer to be pinged.").EnableStdin(), }, Options: []cmds.Option{ cmds.IntOption("count", "n", "Number of ping messages to send.").Default(10), diff --git a/core/commands/publish.go b/core/commands/publish.go index 32fd548a1..405aae6ad 100644 --- a/core/commands/publish.go +++ b/core/commands/publish.go @@ -47,7 +47,7 @@ Publish an to another public key (not implemented): }, Arguments: []cmds.Argument{ - cmds.StringArg("ipfs-path", true, false, "IPFS path of the object to be published."), + cmds.StringArg("ipfs-path", true, false, "IPFS path of the object to be published.").EnableStdin(), }, Options: []cmds.Option{ cmds.BoolOption("resolve", "Resolve given path before publishing.").Default(true), diff --git a/core/commands/refs.go b/core/commands/refs.go index 2da60dd2b..75ffffc88 100644 --- a/core/commands/refs.go +++ b/core/commands/refs.go @@ -46,7 +46,7 @@ NOTE: List all references recursively by using the flag '-r'. "local": RefsLocalCmd, }, Arguments: []cmds.Argument{ - cmds.StringArg("ipfs-path", true, true, "Path to the object(s) to list refs from."), + cmds.StringArg("ipfs-path", true, true, "Path to the object(s) to list refs from.").EnableStdin(), }, Options: []cmds.Option{ cmds.StringOption("format", "Emit edges with given format. Available tokens: .").Default(""), diff --git a/core/commands/resolve.go b/core/commands/resolve.go index c8eacc566..692141a57 100644 --- a/core/commands/resolve.go +++ b/core/commands/resolve.go @@ -56,7 +56,7 @@ Resolve the value of an IPFS DAG path: }, Arguments: []cmds.Argument{ - cmds.StringArg("name", true, false, "The name to resolve."), + cmds.StringArg("name", true, false, "The name to resolve.").EnableStdin(), }, Options: []cmds.Option{ cmds.BoolOption("recursive", "r", "Resolve until the result is an IPFS name.").Default(false), diff --git a/core/commands/swarm.go b/core/commands/swarm.go index a61a55aab..4703a6bfe 100644 --- a/core/commands/swarm.go +++ b/core/commands/swarm.go @@ -215,7 +215,7 @@ ipfs swarm connect /ip4/104.131.131.82/tcp/4001/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3 `, }, Arguments: []cmds.Argument{ - cmds.StringArg("address", true, true, "Address of peer to connect to."), + cmds.StringArg("address", true, true, "Address of peer to connect to.").EnableStdin(), }, Run: func(req cmds.Request, res cmds.Response) { ctx := req.Context() @@ -283,7 +283,7 @@ it will reconnect. `, }, Arguments: []cmds.Argument{ - cmds.StringArg("address", true, true, "Address of peer to disconnect from."), + cmds.StringArg("address", true, true, "Address of peer to disconnect from.").EnableStdin(), }, Run: func(req cmds.Request, res cmds.Response) { n, err := req.InvocContext().GetNode() @@ -451,7 +451,7 @@ add your filters to the ipfs config file. `, }, Arguments: []cmds.Argument{ - cmds.StringArg("address", true, true, "Multiaddr to filter."), + cmds.StringArg("address", true, true, "Multiaddr to filter.").EnableStdin(), }, Run: func(req cmds.Request, res cmds.Response) { n, err := req.InvocContext().GetNode() @@ -523,7 +523,7 @@ remove your filters from the ipfs config file. `, }, Arguments: []cmds.Argument{ - cmds.StringArg("address", true, true, "Multiaddr filter to remove."), + cmds.StringArg("address", true, true, "Multiaddr filter to remove.").EnableStdin(), }, Run: func(req cmds.Request, res cmds.Response) { n, err := req.InvocContext().GetNode() diff --git a/core/commands/tar.go b/core/commands/tar.go index f89a069b3..074478184 100644 --- a/core/commands/tar.go +++ b/core/commands/tar.go @@ -83,7 +83,7 @@ var tarCatCmd = &cmds.Command{ }, Arguments: []cmds.Argument{ - cmds.StringArg("path", true, false, "IPFS path of archive to export."), + cmds.StringArg("path", true, false, "IPFS path of archive to export.").EnableStdin(), }, Run: func(req cmds.Request, res cmds.Response) { nd, err := req.InvocContext().GetNode() diff --git a/core/commands/unixfs/ls.go b/core/commands/unixfs/ls.go index d9e72a879..1b1fa2a8d 100644 --- a/core/commands/unixfs/ls.go +++ b/core/commands/unixfs/ls.go @@ -63,7 +63,7 @@ Example: }, Arguments: []cmds.Argument{ - cmds.StringArg("ipfs-path", true, true, "The path to the IPFS object(s) to list links from."), + cmds.StringArg("ipfs-path", true, true, "The path to the IPFS object(s) to list links from.").EnableStdin(), }, Run: func(req cmds.Request, res cmds.Response) { node, err := req.InvocContext().GetNode() diff --git a/test/sharness/t0040-add-and-cat.sh b/test/sharness/t0040-add-and-cat.sh index b7e28d4ec..4ca68abe8 100755 --- a/test/sharness/t0040-add-and-cat.sh +++ b/test/sharness/t0040-add-and-cat.sh @@ -212,7 +212,7 @@ test_expect_success "ipfs cat output looks good" ' ' test_expect_success "ipfs cat accept hash from built input" ' - echo "$HASH" | xargs ipfs cat >actual + echo "$HASH" | ipfs cat >actual ' test_expect_success "ipfs cat output looks good" ' @@ -268,7 +268,7 @@ test_expect_success "'ipfs add' output looks good" ' ' test_expect_success "'ipfs cat' with built input succeeds" ' - echo "$HASH" | xargs ipfs cat >actual + echo "$HASH" | ipfs cat >actual ' test_expect_success "ipfs cat with built input output looks good" ' @@ -319,7 +319,7 @@ test_expect_success "'ipfs add -rn' output looks good" ' ' test_expect_success "ipfs cat accept many hashes from built input" ' - { echo "$MARS"; echo "$VENUS"; } | xargs ipfs cat >actual + { echo "$MARS"; echo "$VENUS"; } | ipfs cat >actual ' test_expect_success "ipfs cat output looks good" ' @@ -335,28 +335,9 @@ test_expect_success "ipfs cat output looks good" ' test_cmp expected actual ' -test_expect_success "ipfs cat with both arg and built input" ' - echo "$MARS" | xargs ipfs cat "$VENUS" >actual -' - -test_expect_success "ipfs cat output looks good" ' - cat mountdir/planets/venus.txt mountdir/planets/mars.txt >expected && - test_cmp expected actual -' - -test_expect_success "ipfs cat with two args and built input" ' - echo "$MARS" | xargs ipfs cat "$VENUS" "$VENUS" >actual -' - -test_expect_success "ipfs cat output looks good" ' - cat mountdir/planets/venus.txt mountdir/planets/venus.txt \ - mountdir/planets/mars.txt >expected && - test_cmp expected actual -' - test_expect_success "go-random is installed" ' - type random - ' + type random +' test_add_cat_5MB