From 78d36230d522dbde6a72c8938ac5db788b0965b1 Mon Sep 17 00:00:00 2001 From: Matt Bell Date: Mon, 12 Jan 2015 11:29:10 -0800 Subject: [PATCH 1/3] commands/cli: When parsing stdin as string argument, split lines into separate tokens --- commands/cli/parse.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/commands/cli/parse.go b/commands/cli/parse.go index ee6b1656d..0968bcae2 100644 --- a/commands/cli/parse.go +++ b/commands/cli/parse.go @@ -260,7 +260,8 @@ func appendStdinAsString(args []string, stdin *os.File) ([]string, *os.File, err return nil, nil, err } - return append(args, buf.String()), nil, nil + input := strings.TrimSpace(buf.String()) + return append(args, strings.Split(input, "\n")...), nil, nil } func appendFile(args []cmds.File, inputs []string, argDef *cmds.Argument, recursive bool) ([]cmds.File, []string, error) { From 70adc21d08bc304b02c89e5b0f9a61dbe0a0372c Mon Sep 17 00:00:00 2001 From: Matt Bell Date: Mon, 12 Jan 2015 11:32:25 -0800 Subject: [PATCH 2/3] core/commands: Enable stdin arguments for 'add' and 'cat', resolves #542 --- core/commands/add.go | 2 +- core/commands/cat.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/core/commands/add.go b/core/commands/add.go index 50cf293bb..2da6ba42c 100644 --- a/core/commands/add.go +++ b/core/commands/add.go @@ -37,7 +37,7 @@ remains to be implemented. }, Arguments: []cmds.Argument{ - cmds.FileArg("path", true, true, "The path to a file to be added to IPFS").EnableRecursive(), + cmds.FileArg("path", true, true, "The path to a file to be added to IPFS").EnableRecursive().EnableStdin(), }, Options: []cmds.Option{ cmds.OptionRecursivePath, // a builtin option that allows recursive paths (-r, --recursive) diff --git a/core/commands/cat.go b/core/commands/cat.go index 01b6142c7..fe67cdb91 100644 --- a/core/commands/cat.go +++ b/core/commands/cat.go @@ -18,7 +18,7 @@ it contains. }, 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) (interface{}, error) { node, err := req.Context().GetNode() From 86bb8ca7a710c2b1196480f385d63ab362411731 Mon Sep 17 00:00:00 2001 From: Matt Bell Date: Mon, 12 Jan 2015 20:15:02 -0800 Subject: [PATCH 3/3] core/commands: Enabled stdin for various command arguments --- core/commands/block.go | 4 ++-- core/commands/id.go | 2 +- core/commands/ls.go | 2 +- core/commands/object.go | 8 ++++---- core/commands/pin.go | 4 ++-- core/commands/ping.go | 2 +- core/commands/publish.go | 2 +- core/commands/refs.go | 2 +- core/commands/resolve.go | 2 +- core/commands/swarm.go | 2 +- 10 files changed, 15 insertions(+), 15 deletions(-) diff --git a/core/commands/block.go b/core/commands/block.go index 9ccdbe67b..2df004407 100644 --- a/core/commands/block.go +++ b/core/commands/block.go @@ -55,7 +55,7 @@ on raw ipfs blocks. It outputs the following to stdout: }, Arguments: []cmds.Argument{ - cmds.StringArg("key", true, false, "The base58 multihash of an existing block to get"), + cmds.StringArg("key", true, false, "The base58 multihash of an existing block to get").EnableStdin(), }, Run: func(req cmds.Request) (interface{}, error) { b, err := getBlockForKey(req, req.Arguments()[0]) @@ -87,7 +87,7 @@ It outputs to stdout, and is a base58 encoded multihash. }, Arguments: []cmds.Argument{ - cmds.StringArg("key", true, false, "The base58 multihash of an existing block to get"), + cmds.StringArg("key", true, false, "The base58 multihash of an existing block to get").EnableStdin(), }, Run: func(req cmds.Request) (interface{}, error) { b, err := getBlockForKey(req, req.Arguments()[0]) diff --git a/core/commands/id.go b/core/commands/id.go index c535470d9..0452a2fdf 100644 --- a/core/commands/id.go +++ b/core/commands/id.go @@ -43,7 +43,7 @@ if no peer is specified, prints out local peers info. `, }, 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(), }, Run: func(req cmds.Request) (interface{}, error) { node, err := req.Context().GetNode() diff --git a/core/commands/ls.go b/core/commands/ls.go index 35fef8fc2..43b38339a 100644 --- a/core/commands/ls.go +++ b/core/commands/ls.go @@ -35,7 +35,7 @@ it contains, with the following 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(), }, Run: func(req cmds.Request) (interface{}, error) { node, err := req.Context().GetNode() diff --git a/core/commands/object.go b/core/commands/object.go index 026496f58..e977698b5 100644 --- a/core/commands/object.go +++ b/core/commands/object.go @@ -69,7 +69,7 @@ output 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) (interface{}, error) { n, err := req.Context().GetNode() @@ -93,7 +93,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(), }, Run: func(req cmds.Request) (interface{}, error) { n, err := req.Context().GetNode() @@ -135,7 +135,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) (interface{}, error) { n, err := req.Context().GetNode() @@ -199,7 +199,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) (interface{}, error) { n, err := req.Context().GetNode() diff --git a/core/commands/pin.go b/core/commands/pin.go index d9d8e830a..3436ebe82 100644 --- a/core/commands/pin.go +++ b/core/commands/pin.go @@ -31,7 +31,7 @@ on disk. }, Arguments: []cmds.Argument{ - cmds.StringArg("ipfs-path", true, true, "Path to object(s) to be pinned"), + cmds.StringArg("ipfs-path", true, true, "Path to object(s) to be pinned").EnableStdin(), }, Options: []cmds.Option{ cmds.BoolOption("recursive", "r", "Recursively pin the object linked to by the specified object(s)"), @@ -71,7 +71,7 @@ collected if needed. }, Arguments: []cmds.Argument{ - cmds.StringArg("ipfs-path", true, true, "Path to object(s) to be unpinned"), + cmds.StringArg("ipfs-path", true, true, "Path to object(s) to be unpinned").EnableStdin(), }, Options: []cmds.Option{ cmds.BoolOption("recursive", "r", "Recursively unpin the object linked to by the specified object(s)"), diff --git a/core/commands/ping.go b/core/commands/ping.go index a4166ffdd..2cc1da01d 100644 --- a/core/commands/ping.go +++ b/core/commands/ping.go @@ -37,7 +37,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"), diff --git a/core/commands/publish.go b/core/commands/publish.go index 757adf27c..4304ef1e8 100644 --- a/core/commands/publish.go +++ b/core/commands/publish.go @@ -44,7 +44,7 @@ Publish a to another public key: Arguments: []cmds.Argument{ cmds.StringArg("name", false, false, "The IPNS name to publish to. Defaults to your node's peerID"), - cmds.StringArg("ipfs-path", true, false, "IPFS path of the obejct to be published at "), + cmds.StringArg("ipfs-path", true, false, "IPFS path of the obejct to be published at ").EnableStdin(), }, Run: func(req cmds.Request) (interface{}, error) { log.Debug("Begin Publish") diff --git a/core/commands/refs.go b/core/commands/refs.go index d9999cdde..3aa38d2dd 100644 --- a/core/commands/refs.go +++ b/core/commands/refs.go @@ -45,7 +45,7 @@ Note: list all refs recursively with -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. tokens: "), diff --git a/core/commands/resolve.go b/core/commands/resolve.go index 8fb67e755..d76cf8f8f 100644 --- a/core/commands/resolve.go +++ b/core/commands/resolve.go @@ -38,7 +38,7 @@ Resolve te value of another name: }, Arguments: []cmds.Argument{ - cmds.StringArg("name", false, false, "The IPNS name to resolve. Defaults to your node's peerID."), + cmds.StringArg("name", false, false, "The IPNS name to resolve. Defaults to your node's peerID.").EnableStdin(), }, Run: func(req cmds.Request) (interface{}, error) { diff --git a/core/commands/swarm.go b/core/commands/swarm.go index 4345acecb..6fa3c8e93 100644 --- a/core/commands/swarm.go +++ b/core/commands/swarm.go @@ -83,7 +83,7 @@ ipfs swarm connect /ip4/104.131.131.82/tcp/4001/QmaCpDMGvV2BGHeYERUEnRQAwe3N8Szb `, }, 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) (interface{}, error) { ctx := context.TODO()