mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-19 18:05:32 +08:00
enable stdin input for ipfs object put
This commit is contained in:
@ -35,11 +35,11 @@ var ObjectCmd = &cmds.Command{
|
|||||||
'ipfs object' is a plumbing command used to manipulate DAG objects
|
'ipfs object' is a plumbing command used to manipulate DAG objects
|
||||||
directly.`,
|
directly.`,
|
||||||
Synopsis: `
|
Synopsis: `
|
||||||
ipfs object get <key> - Get the DAG node named by <key>
|
ipfs object get <key> - Get the DAG node named by <key>
|
||||||
ipfs object put <data> <encoding> - Stores input, outputs its key
|
ipfs object put <data> - Stores input, outputs its key
|
||||||
ipfs object data <key> - Outputs raw bytes in an object
|
ipfs object data <key> - Outputs raw bytes in an object
|
||||||
ipfs object links <key> - Outputs links pointed to by object
|
ipfs object links <key> - Outputs links pointed to by object
|
||||||
ipfs object stat <key> - Outputs statistics of object
|
ipfs object stat <key> - Outputs statistics of object
|
||||||
`,
|
`,
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -274,16 +274,18 @@ It reads from stdin, and the output is a base58 encoded multihash.
|
|||||||
'ipfs object put' is a plumbing command for storing DAG nodes.
|
'ipfs object put' is a plumbing command for storing DAG nodes.
|
||||||
It reads from stdin, and the output is a base58 encoded multihash.
|
It reads from stdin, and the output is a base58 encoded multihash.
|
||||||
|
|
||||||
Data should be in the format specified by <encoding>.
|
Data should be in the format specified by the --inputenc flag.
|
||||||
<encoding> may be one of the following:
|
--inputenc may be one of the following:
|
||||||
* "protobuf"
|
* "protobuf"
|
||||||
* "json"
|
* "json" (default)
|
||||||
`,
|
`,
|
||||||
},
|
},
|
||||||
|
|
||||||
Arguments: []cmds.Argument{
|
Arguments: []cmds.Argument{
|
||||||
cmds.FileArg("data", true, false, "Data to be stored as a DAG object"),
|
cmds.FileArg("data", true, false, "Data to be stored as a DAG object").EnableStdin(),
|
||||||
cmds.StringArg("encoding", true, false, "Encoding type of <data>, either \"protobuf\" or \"json\""),
|
},
|
||||||
|
Options: []cmds.Option{
|
||||||
|
cmds.StringOption("inputenc", "Encoding type of input data, either \"protobuf\" or \"json\""),
|
||||||
},
|
},
|
||||||
Run: func(req cmds.Request, res cmds.Response) {
|
Run: func(req cmds.Request, res cmds.Response) {
|
||||||
n, err := req.Context().GetNode()
|
n, err := req.Context().GetNode()
|
||||||
@ -298,9 +300,16 @@ Data should be in the format specified by <encoding>.
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
encoding := req.Arguments()[0]
|
inputenc, found, err := req.Option("inputenc").String()
|
||||||
|
if err != nil {
|
||||||
|
res.SetError(err, cmds.ErrNormal)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if !found {
|
||||||
|
inputenc = "json"
|
||||||
|
}
|
||||||
|
|
||||||
output, err := objectPut(n, input, encoding)
|
output, err := objectPut(n, input, inputenc)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errType := cmds.ErrNormal
|
errType := cmds.ErrNormal
|
||||||
if err == ErrUnknownObjectEnc {
|
if err == ErrUnknownObjectEnc {
|
||||||
|
Reference in New Issue
Block a user