Skip to content

Commit

Permalink
Merge pull request #2744 from ipfs/feature/Options-Default-2702
Browse files Browse the repository at this point in the history
Allow to specify where to put default options in option desciption
  • Loading branch information
whyrusleeping committed May 21, 2016
2 parents 425e0f0 + 7034231 commit 518f7e0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
9 changes: 7 additions & 2 deletions commands/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package commands
import (
"fmt"
"reflect"
"strings"

"gx/ipfs/QmZNVWh8LLjAavuQ2JXuFmuYH3C11xo988vSgp7UQrTRj1/go-ipfs-util"
)
Expand Down Expand Up @@ -45,9 +46,13 @@ func (o *option) Description() string {
if o.description[len(o.description)-1] != '.' {
o.description += "."
}

if o.defaultVal != nil {
return fmt.Sprintf("%s Default: %v.", o.description, o.defaultVal)
if strings.Contains(o.description, "<default>") {
return strings.Replace(o.description, "<default>",
fmt.Sprintf("Default: %v.", o.defaultVal), -1)
} else {
return fmt.Sprintf("%s Default: %v.", o.description, o.defaultVal)
}
}
return o.description
}
Expand Down
7 changes: 3 additions & 4 deletions core/commands/publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,10 @@ Publish an <ipfs-path> to another public key (not implemented):
},
Options: []cmds.Option{
cmds.BoolOption("resolve", "Resolve given path before publishing.").Default(true),
cmds.StringOption("lifetime", "t", `Time duration that the record will be valid for.
cmds.StringOption("lifetime", "t",
`Time duration that the record will be valid for. <default>
This accepts durations such as "300s", "1.5h" or "2h45m". Valid time units are
"ns", "us" (or "µs"), "ms", "s", "m", "h".
`).Default("24h"),
"ns", "us" (or "µs"), "ms", "s", "m", "h".`).Default("24h"),
cmds.StringOption("ttl", "Time duration this record should be cached for (caution: experimental)."),
},
Run: func(req cmds.Request, res cmds.Response) {
Expand Down

0 comments on commit 518f7e0

Please sign in to comment.