@cryptotaxi247 / kubo / commits / 646920b0d

commands: Got rid of old helptext fields, use HelpText struct fields in helptext generator

Matt Bell committed Nov 13, 2014 at 00:10 UTC 646920b0dd39161af59e01bf214ad0eddc1ee1f2
2 files changed +15 -52
commands/cli/helptext.go
+15 -45
@@ -130,38 +130,31 @@ func LongHelp(rootName string, root *cmds.Command, path []string, out io.Writer)
130 pathStr += " " + strings.Join(path, " ")
131 }
132
133 - // TODO: get the fields from the HelpText struct by default (when commands are ported to use it)
133 fields := helpFields{
134 Indent: indentStr,
135 Path: pathStr,
136 ArgUsage: usageText(cmd),
138 - Tagline: cmd.Description,
139 - Arguments: cmd.ArgumentHelp,
140 - Options: cmd.OptionHelp,
137 + Tagline: cmd.Helptext.Tagline,
138 + Arguments: cmd.Helptext.Arguments,
139 + Options: cmd.Helptext.Options,
140 Synopsis: cmd.Helptext.Synopsis,
142 - Subcommands: cmd.SubcommandHelp,
143 - Description: cmd.Help,
141 + Subcommands: cmd.Helptext.Subcommands,
142 + Description: cmd.Helptext.ShortDescription,
143 + Usage: cmd.Helptext.Usage,
144 }
145
146 - // TODO: don't do these checks, just use these fields by default (when commands get ported to it)
147 - if len(cmd.Helptext.Tagline) > 0 {
148 - fields.Tagline = cmd.Helptext.Tagline
149 - }
150 - if len(cmd.Helptext.ShortDescription) > 0 {
151 - fields.Description = cmd.Helptext.ShortDescription
152 - }
153 - if len(cmd.Helptext.Usage) > 0 {
154 - fields.Usage = cmd.Helptext.Subcommands
146 + if len(cmd.Helptext.LongDescription) > 0 {
147 + fields.Description = cmd.Helptext.LongDescription
148 }
149
150 // autogen fields that are empty
158 - if len(cmd.ArgumentHelp) == 0 {
151 + if len(fields.Arguments) == 0 {
152 fields.Arguments = strings.Join(argumentText(cmd), "\n")
153 }
161 - if len(cmd.OptionHelp) == 0 {
154 + if len(fields.Options) == 0 {
155 fields.Options = strings.Join(optionText(cmd), "\n")
156 }
164 - if len(cmd.SubcommandHelp) == 0 {
157 + if len(fields.Subcommands) == 0 {
158 fields.Subcommands = strings.Join(subcommandText(cmd, rootName, path), "\n")
159 }
160
@@ -195,29 +188,10 @@ func ShortHelp(rootName string, root *cmds.Command, path []string, out io.Writer
188 Indent: indentStr,
189 Path: pathStr,
190 ArgUsage: usageText(cmd),
198 - Tagline: cmd.Description,
191 + Tagline: cmd.Helptext.Tagline,
192 Synopsis: cmd.Helptext.Synopsis,
200 - Description: cmd.Help,
201 - }
202 -
203 - // TODO: don't do these checks, just use these fields by default (when commands get ported to it)
204 - if len(cmd.Helptext.Tagline) > 0 {
205 - fields.Tagline = cmd.Helptext.Tagline
206 - }
207 - if len(cmd.Helptext.Arguments) > 0 {
208 - fields.Arguments = cmd.Helptext.Arguments
209 - }
210 - if len(cmd.Helptext.Options) > 0 {
211 - fields.Options = cmd.Helptext.Options
212 - }
213 - if len(cmd.Helptext.Subcommands) > 0 {
214 - fields.Subcommands = cmd.Helptext.Subcommands
215 - }
216 - if len(cmd.Helptext.ShortDescription) > 0 {
217 - fields.Description = cmd.Helptext.ShortDescription
218 - }
219 - if len(cmd.Helptext.Usage) > 0 {
220 - fields.Usage = cmd.Helptext.Subcommands
193 + Description: cmd.Helptext.ShortDescription,
194 + Usage: cmd.Helptext.Usage,
195 }
196
197 // trim the extra newlines (see TrimNewlines doc)
@@ -311,11 +285,7 @@ func subcommandText(cmd *cmds.Command, rootName string, path []string) []string
285 if len(usage) > 0 {
286 usage = " " + usage
287 }
314 - if len(sub.Helptext.Tagline) > 0 {
315 - lines[i] = fmt.Sprintf("%v%v%v - %v", prefix, name, usage, sub.Helptext.Tagline)
316 - } else {
317 - lines[i] = fmt.Sprintf("%v%v%v - %v", prefix, name, usage, sub.Description)
318 - }
288 + lines[i] = fmt.Sprintf("%v%v%v - %v", prefix, name, usage, sub.Helptext.Tagline)
289 i++
290 }
291
commands/command.go
-7
@@ -44,13 +44,6 @@ type HelpText struct {
44 // Command is a runnable command, with input arguments and options (flags).
45 // It can also have Subcommands, to group units of work into sets.
46 type Command struct {
47 - // TODO: remove these fields after porting commands to HelpText struct
48 - Description string
49 - Help string
50 - SubcommandHelp string
51 - OptionHelp string
52 - ArgumentHelp string
53 -
47 Options []Option
48 Arguments []Argument
49 Run Function