1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-06-26 23:53:19 +08:00

re-enable the stdin

License: MIT
Signed-off-by: Jeromy <why@ipfs.io>
This commit is contained in:
Jeromy
2016-07-08 16:39:15 -07:00
parent cd46743717
commit 5d301cb8ec
17 changed files with 39 additions and 59 deletions

View File

@ -132,13 +132,13 @@ var bootstrapRemoveCmd = &cmds.Command{
}, },
Arguments: []cmds.Argument{ Arguments: []cmds.Argument{
cmds.StringArg("peer", false, true, peerOptionDesc), cmds.StringArg("peer", false, true, peerOptionDesc).EnableStdin(),
}, },
Options: []cmds.Option{ Options: []cmds.Option{
cmds.BoolOption("all", "Remove all bootstrap peers.").Default(false), cmds.BoolOption("all", "Remove all bootstrap peers.").Default(false),
}, },
Run: func(req cmds.Request, res cmds.Response) { Run: func(req cmds.Request, res cmds.Response) {
input, err := config.ParseBootstrapPeers(req.Arguments()) all, _, err := req.Option("all").Bool()
if err != nil { if err != nil {
res.SetError(err, cmds.ErrNormal) res.SetError(err, cmds.ErrNormal)
return return
@ -156,16 +156,16 @@ var bootstrapRemoveCmd = &cmds.Command{
return return
} }
all, _, err := req.Option("all").Bool()
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
}
var removed []config.BootstrapPeer var removed []config.BootstrapPeer
if all { if all {
removed, err = bootstrapRemoveAll(r, cfg) removed, err = bootstrapRemoveAll(r, cfg)
} else { } else {
input, perr := config.ParseBootstrapPeers(req.Arguments())
if perr != nil {
res.SetError(perr, cmds.ErrNormal)
return
}
removed, err = bootstrapRemove(r, cfg, input) removed, err = bootstrapRemove(r, cfg, input)
} }
if err != nil { if err != nil {

View File

@ -20,7 +20,7 @@ var CatCmd = &cmds.Command{
}, },
Arguments: []cmds.Argument{ 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) { Run: func(req cmds.Request, res cmds.Response) {
node, err := req.InvocContext().GetNode() node, err := req.InvocContext().GetNode()

View File

@ -459,7 +459,7 @@ NOTE: A value may not exceed 2048 bytes.
Arguments: []cmds.Argument{ Arguments: []cmds.Argument{
cmds.StringArg("key", true, false, "The key to store the value at."), 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{ Options: []cmds.Option{
cmds.BoolOption("verbose", "v", "Print extra information.").Default(false), cmds.BoolOption("verbose", "v", "Print extra information.").Default(false),

View File

@ -44,7 +44,7 @@ The resolver can recursively resolve:
}, },
Arguments: []cmds.Argument{ 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{ Options: []cmds.Option{
cmds.BoolOption("recursive", "r", "Resolve until the result is not a DNS link.").Default(false), cmds.BoolOption("recursive", "r", "Resolve until the result is not a DNS link.").Default(false),

View File

@ -37,7 +37,7 @@ may also specify the level of compression by specifying '-l=<1-9>'.
}, },
Arguments: []cmds.Argument{ 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{ Options: []cmds.Option{
cmds.StringOption("output", "o", "The path where the output should be stored."), cmds.StringOption("output", "o", "The path where the output should be stored."),

View File

@ -58,7 +58,7 @@ EXAMPLE:
`, `,
}, },
Arguments: []cmds.Argument{ 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{ Options: []cmds.Option{
cmds.StringOption("format", "f", "Optional output format."), cmds.StringOption("format", "f", "Optional output format."),

View File

@ -42,7 +42,7 @@ format:
}, },
Arguments: []cmds.Argument{ 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{ Options: []cmds.Option{
cmds.BoolOption("headers", "v", "Print table headers (Hash, Size, Name).").Default(false), cmds.BoolOption("headers", "v", "Print table headers (Hash, Size, Name).").Default(false),

View File

@ -78,7 +78,7 @@ is the raw data of the object.
}, },
Arguments: []cmds.Argument{ 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) { Run: func(req cmds.Request, res cmds.Response) {
n, err := req.InvocContext().GetNode() n, err := req.InvocContext().GetNode()
@ -108,7 +108,7 @@ multihash.
}, },
Arguments: []cmds.Argument{ 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{ Options: []cmds.Option{
cmds.BoolOption("headers", "v", "Print table headers (Hash, Size, Name).").Default(false), 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{ 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) { Run: func(req cmds.Request, res cmds.Response) {
n, err := req.InvocContext().GetNode() n, err := req.InvocContext().GetNode()
@ -246,7 +246,7 @@ var ObjectStatCmd = &cmds.Command{
}, },
Arguments: []cmds.Argument{ 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) { Run: func(req cmds.Request, res cmds.Response) {
n, err := req.InvocContext().GetNode() n, err := req.InvocContext().GetNode()

View File

@ -71,6 +71,11 @@ var addPinCmd = &cmds.Command{
}, },
Marshalers: cmds.MarshalerMap{ Marshalers: cmds.MarshalerMap{
cmds.Text: func(res cmds.Response) (io.Reader, error) { cmds.Text: func(res cmds.Response) (io.Reader, error) {
added, ok := res.Output().(*PinOutput)
if !ok {
return nil, u.ErrCast()
}
var pintype string var pintype string
rec, found, _ := res.Request().Option("recursive").Bool() rec, found, _ := res.Request().Option("recursive").Bool()
if rec || !found { if rec || !found {
@ -79,17 +84,11 @@ var addPinCmd = &cmds.Command{
pintype = "directly" pintype = "directly"
} }
po, ok := res.Output().(*PinOutput)
if !ok {
return nil, u.ErrCast()
}
buf := new(bytes.Buffer) buf := new(bytes.Buffer)
for _, k := range po.Pins { for _, k := range added.Pins {
fmt.Fprintf(buf, "pinned %s %s\n", k, pintype) fmt.Fprintf(buf, "pinned %s %s\n", k, pintype)
} }
return buf, nil return buf, nil
}, },
}, },
} }

View File

@ -36,7 +36,7 @@ trip latency information.
`, `,
}, },
Arguments: []cmds.Argument{ 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{ Options: []cmds.Option{
cmds.IntOption("count", "n", "Number of ping messages to send.").Default(10), cmds.IntOption("count", "n", "Number of ping messages to send.").Default(10),

View File

@ -47,7 +47,7 @@ Publish an <ipfs-path> to another public key (not implemented):
}, },
Arguments: []cmds.Argument{ 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{ Options: []cmds.Option{
cmds.BoolOption("resolve", "Resolve given path before publishing.").Default(true), cmds.BoolOption("resolve", "Resolve given path before publishing.").Default(true),

View File

@ -46,7 +46,7 @@ NOTE: List all references recursively by using the flag '-r'.
"local": RefsLocalCmd, "local": RefsLocalCmd,
}, },
Arguments: []cmds.Argument{ 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{ Options: []cmds.Option{
cmds.StringOption("format", "Emit edges with given format. Available tokens: <src> <dst> <linkname>.").Default("<dst>"), cmds.StringOption("format", "Emit edges with given format. Available tokens: <src> <dst> <linkname>.").Default("<dst>"),

View File

@ -56,7 +56,7 @@ Resolve the value of an IPFS DAG path:
}, },
Arguments: []cmds.Argument{ 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{ Options: []cmds.Option{
cmds.BoolOption("recursive", "r", "Resolve until the result is an IPFS name.").Default(false), cmds.BoolOption("recursive", "r", "Resolve until the result is an IPFS name.").Default(false),

View File

@ -215,7 +215,7 @@ ipfs swarm connect /ip4/104.131.131.82/tcp/4001/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3
`, `,
}, },
Arguments: []cmds.Argument{ 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) { Run: func(req cmds.Request, res cmds.Response) {
ctx := req.Context() ctx := req.Context()
@ -283,7 +283,7 @@ it will reconnect.
`, `,
}, },
Arguments: []cmds.Argument{ 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) { Run: func(req cmds.Request, res cmds.Response) {
n, err := req.InvocContext().GetNode() n, err := req.InvocContext().GetNode()
@ -451,7 +451,7 @@ add your filters to the ipfs config file.
`, `,
}, },
Arguments: []cmds.Argument{ 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) { Run: func(req cmds.Request, res cmds.Response) {
n, err := req.InvocContext().GetNode() n, err := req.InvocContext().GetNode()
@ -523,7 +523,7 @@ remove your filters from the ipfs config file.
`, `,
}, },
Arguments: []cmds.Argument{ 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) { Run: func(req cmds.Request, res cmds.Response) {
n, err := req.InvocContext().GetNode() n, err := req.InvocContext().GetNode()

View File

@ -83,7 +83,7 @@ var tarCatCmd = &cmds.Command{
}, },
Arguments: []cmds.Argument{ 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) { Run: func(req cmds.Request, res cmds.Response) {
nd, err := req.InvocContext().GetNode() nd, err := req.InvocContext().GetNode()

View File

@ -63,7 +63,7 @@ Example:
}, },
Arguments: []cmds.Argument{ 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) { Run: func(req cmds.Request, res cmds.Response) {
node, err := req.InvocContext().GetNode() node, err := req.InvocContext().GetNode()

View File

@ -212,7 +212,7 @@ test_expect_success "ipfs cat output looks good" '
' '
test_expect_success "ipfs cat accept hash from built input" ' 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" ' 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" ' 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" ' 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" ' 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" ' 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_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" ' test_expect_success "go-random is installed" '
type random type random
' '
test_add_cat_5MB test_add_cat_5MB