Added Default logic to object object and patch
Part of #2484. License: MIT Signed-off-by: Richard Littauer <richard.littauer@gmail.com>
Richard Littauer committed
May 12, 2016 at 11:35 UTC
c68aa06c5d383b6b6446cb566b5c651762a437f9
2 files changed
+7
-10
core/commands/object/object.go
+4
-7
@@ -113,7 +113,7 @@ multihash.
113
cmds.StringArg("key", true, false, "Key of the object to retrieve, in base58-encoded multihash format.").EnableStdin(),
114
},
115
Options: []cmds.Option{
116
- cmds.BoolOption("headers", "v", "Print table headers (Hash, Size, Name)."),
116
+ cmds.BoolOption("headers", "v", "Print table headers (Hash, Size, Name).").Default(false),
117
},
118
Run: func(req cmds.Request, res cmds.Response) {
119
n, err := req.InvocContext().GetNode()
@@ -335,7 +335,7 @@ And then run:
335
cmds.FileArg("data", true, false, "Data to be stored as a DAG object.").EnableStdin(),
336
},
337
Options: []cmds.Option{
338
- cmds.StringOption("inputenc", "Encoding type of input data, either \"protobuf\" or \"json\"."),
338
+ cmds.StringOption("inputenc", "Encoding type of input data. One of: {\"protobuf\", \"json\"}.").Default("json"),
339
cmds.StringOption("datafieldenc", "Encoding type of the data field, either \"text\" or \"base64\".").Default("text"),
340
},
341
Run: func(req cmds.Request, res cmds.Response) {
@@ -351,16 +351,13 @@ And then run:
351
return
352
}
353
354
- inputenc, found, err := req.Option("inputenc").String()
354
+ inputenc, _, err := req.Option("inputenc").String()
355
if err != nil {
356
res.SetError(err, cmds.ErrNormal)
357
return
358
}
359
- if !found {
360
- inputenc = "json"
361
- }
359
363
- datafieldenc, found, err := req.Option("datafieldenc").String()
360
+ datafieldenc, _, err := req.Option("datafieldenc").String()
361
if err != nil {
362
res.SetError(err, cmds.ErrNormal)
363
return
core/commands/object/patch.go
+3
-3
@@ -246,14 +246,14 @@ This takes an empty directory, and adds a link named 'foo' under it, pointing to
246
a file containing 'bar', and returns the hash of the new object.
247
`,
248
},
249
- Options: []cmds.Option{
250
- cmds.BoolOption("p", "create", "Create intermediary nodes."),
251
- },
249
Arguments: []cmds.Argument{
250
cmds.StringArg("root", true, false, "The hash of the node to modify."),
251
cmds.StringArg("name", true, false, "Name of link to create."),
252
cmds.StringArg("ref", true, false, "IPFS object to add link to."),
253
},
254
+ Options: []cmds.Option{
255
+ cmds.BoolOption("p", "create", "Create intermediary nodes.").Default(false),
256
+ },
257
Run: func(req cmds.Request, res cmds.Response) {
258
nd, err := req.InvocContext().GetNode()
259
if err != nil {