Allow to specify where to put default options in option desciption
License: MIT Signed-off-by: Jakub Sztandera <kubuxu@protonmail.ch>
Jakub Sztandera committed
May 19, 2016 at 18:54 UTC
70342314ae9019d0b27b890440cfccaad59fda30
2 files changed
+10
-6
commands/option.go
+7
-2
@@ -3,6 +3,7 @@ package commands
3
import (
4
"fmt"
5
"reflect"
6
+ "strings"
7
8
"gx/ipfs/QmZNVWh8LLjAavuQ2JXuFmuYH3C11xo988vSgp7UQrTRj1/go-ipfs-util"
9
)
@@ -45,9 +46,13 @@ func (o *option) Description() string {
46
if o.description[len(o.description)-1] != '.' {
47
o.description += "."
48
}
48
-
49
if o.defaultVal != nil {
50
- return fmt.Sprintf("%s Default: %v.", o.description, o.defaultVal)
50
+ if strings.Contains(o.description, "<default>") {
51
+ return strings.Replace(o.description, "<default>",
52
+ fmt.Sprintf("Default: %v.", o.defaultVal), -1)
53
+ } else {
54
+ return fmt.Sprintf("%s Default: %v.", o.description, o.defaultVal)
55
+ }
56
}
57
return o.description
58
}
core/commands/publish.go
+3
-4
@@ -51,11 +51,10 @@ Publish an <ipfs-path> to another public key (not implemented):
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.
55
-
54
+ cmds.StringOption("lifetime", "t",
55
+ `Time duration that the record will be valid for. <default>
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
- `).Default("24h"),
57
+ "ns", "us" (or "µs"), "ms", "s", "m", "h".`).Default("24h"),
58
cmds.StringOption("ttl", "Time duration this record should be cached for (caution: experimental)."),
59
},
60
Run: func(req cmds.Request, res cmds.Response) {