@cryptotaxi247 / kubo / commits / 475d73088

Added Default logic to publish

Part of #2484 License: MIT Signed-off-by: Richard Littauer <richard.littauer@gmail.com>

Richard Littauer committed May 12, 2016 at 11:52 UTC 475d73088c8d25a3657406fb511375290dcaa95e
1 file changed +12 -19
core/commands/publish.go
+12 -19
@@ -50,12 +50,12 @@ Publish an <ipfs-path> to another public key (not implemented):
50 cmds.StringArg("ipfs-path", true, false, "IPFS path of the object to be published.").EnableStdin(),
51 },
52 Options: []cmds.Option{
53 - cmds.BoolOption("resolve", "Resolve given path before publishing (default=true)."),
54 - cmds.StringOption("lifetime", "t", `Time duration that the record will be valid for. Default: 24h.
53 + cmds.BoolOption("resolve", "Resolve given path before publishing.").Default(true),
54 + cmds.StringOption("lifetime", "t", `Time duration that the record will be valid for.
55
56 This accepts durations such as "300s", "1.5h" or "2h45m". Valid time units are
57 "ns", "us" (or "µs"), "ms", "s", "m", "h".
58 - `),
58 + `).Default("24h"),
59 cmds.StringOption("ttl", "Time duration this record should be cached for (caution: experimental)."),
60 },
61 Run: func(req cmds.Request, res cmds.Response) {
@@ -86,26 +86,19 @@ Publish an <ipfs-path> to another public key (not implemented):
86 return
87 }
88
89 - popts := &publishOpts{
90 - verifyExists: true,
91 - pubValidTime: time.Hour * 24,
92 - }
89 + popts := new(publishOpts)
90
94 - verif, found, _ := req.Option("resolve").Bool()
95 - if found {
96 - popts.verifyExists = verif
97 - }
98 - validtime, found, _ := req.Option("lifetime").String()
99 - if found {
100 - d, err := time.ParseDuration(validtime)
101 - if err != nil {
102 - res.SetError(fmt.Errorf("error parsing lifetime option: %s", err), cmds.ErrNormal)
103 - return
104 - }
91 + popts.verifyExists, _, _ = req.Option("resolve").Bool()
92
106 - popts.pubValidTime = d
93 + validtime, _, _ := req.Option("lifetime").String()
94 + d, err := time.ParseDuration(validtime)
95 + if err != nil {
96 + res.SetError(fmt.Errorf("error parsing lifetime option: %s", err), cmds.ErrNormal)
97 + return
98 }
99
100 + popts.pubValidTime = d
101 +
102 ctx := req.Context()
103 if ttl, found, _ := req.Option("ttl").String(); found {
104 d, err := time.ParseDuration(ttl)