@cryptotaxi247 / kubo / commits / bc84ffafe

enable stdin input for ipfs object put

Henry committed Mar 7, 2015 at 14:01 UTC bc84ffafe30916adca1db07da9729c034cc45dff
1 file changed +21 -12
core/commands/object.go
+21 -12
@@ -35,11 +35,11 @@ var ObjectCmd = &cmds.Command{
35 'ipfs object' is a plumbing command used to manipulate DAG objects
36 directly.`,
37 Synopsis: `
38 -ipfs object get <key> - Get the DAG node named by <key>
39 -ipfs object put <data> <encoding> - Stores input, outputs its key
40 -ipfs object data <key> - Outputs raw bytes in an object
41 -ipfs object links <key> - Outputs links pointed to by object
42 -ipfs object stat <key> - Outputs statistics of object
38 +ipfs object get <key> - Get the DAG node named by <key>
39 +ipfs object put <data> - Stores input, outputs its key
40 +ipfs object data <key> - Outputs raw bytes in an object
41 +ipfs object links <key> - Outputs links pointed to by object
42 +ipfs object stat <key> - Outputs statistics of object
43 `,
44 },
45
@@ -274,16 +274,18 @@ It reads from stdin, and the output is a base58 encoded multihash.
274 'ipfs object put' is a plumbing command for storing DAG nodes.
275 It reads from stdin, and the output is a base58 encoded multihash.
276
277 -Data should be in the format specified by <encoding>.
278 -<encoding> may be one of the following:
277 +Data should be in the format specified by the --inputenc flag.
278 +--inputenc may be one of the following:
279 * "protobuf"
280 - * "json"
280 + * "json" (default)
281 `,
282 },
283
284 Arguments: []cmds.Argument{
285 - cmds.FileArg("data", true, false, "Data to be stored as a DAG object"),
286 - cmds.StringArg("encoding", true, false, "Encoding type of <data>, either \"protobuf\" or \"json\""),
285 + cmds.FileArg("data", true, false, "Data to be stored as a DAG object").EnableStdin(),
286 + },
287 + Options: []cmds.Option{
288 + cmds.StringOption("inputenc", "Encoding type of input data, either \"protobuf\" or \"json\""),
289 },
290 Run: func(req cmds.Request, res cmds.Response) {
291 n, err := req.Context().GetNode()
@@ -298,9 +300,16 @@ Data should be in the format specified by <encoding>.
300 return
301 }
302
301 - encoding := req.Arguments()[0]
303 + inputenc, found, err := req.Option("inputenc").String()
304 + if err != nil {
305 + res.SetError(err, cmds.ErrNormal)
306 + return
307 + }
308 + if !found {
309 + inputenc = "json"
310 + }
311
303 - output, err := objectPut(n, input, encoding)
312 + output, err := objectPut(n, input, inputenc)
313 if err != nil {
314 errType := cmds.ErrNormal
315 if err == ErrUnknownObjectEnc {