Merge pull request #545 from jbenet/stdin-input

Stdin Input
This commit is contained in:
Juan Batiz-Benet 2015-01-13 23:27:04 -08:00
commit 07b35e6a59
13 changed files with 19 additions and 18 deletions

View File

@ -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) {

View File

@ -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)

View File

@ -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 <key> 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])

View File

@ -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()

View File

@ -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()

View File

@ -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()

View File

@ -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()

View File

@ -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)"),

View File

@ -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"),

View File

@ -44,7 +44,7 @@ Publish a <ref> 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 <name>"),
cmds.StringArg("ipfs-path", true, false, "IPFS path of the obejct to be published at <name>").EnableStdin(),
},
Run: func(req cmds.Request) (interface{}, error) {
log.Debug("Begin Publish")

View File

@ -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: <src> <dst> <linkname>"),

View File

@ -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) {

View File

@ -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()