Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-dms3-cmds
Commits
60e99c38
Commit
60e99c38
authored
Nov 12, 2014
by
Matt Bell
Committed by
Juan Batiz-Benet
Nov 14, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
commands/cli: Transitionary commit - Generate helptext from HelpText fields if they aren't empty
parent
56c2ddad
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
1 deletion
+36
-1
cli/helptext.go
cli/helptext.go
+36
-1
No files found.
cli/helptext.go
View file @
60e99c38
...
...
@@ -23,6 +23,7 @@ const (
type
helpFields
struct
{
Indent
string
Usage
string
Path
string
ArgUsage
string
Tagline
string
...
...
@@ -32,7 +33,7 @@ type helpFields struct {
Description
string
}
const
usageFormat
=
"{{.Path}}{{if .ArgUsage}} {{.ArgUsage}}{{end}} - {{.Tagline}}"
const
usageFormat
=
"{{
if .Usage}}{{.Usage}}{{else}}{{
.Path}}{{if .ArgUsage}} {{.ArgUsage}}{{end}} - {{.Tagline}}
{{end}}
"
const
longHelpFormat
=
`
{{.Indent}}{{template "usage" .}}
...
...
@@ -101,6 +102,7 @@ func LongHelp(rootName string, root *cmds.Command, path []string, out io.Writer)
pathStr
+=
" "
+
strings
.
Join
(
path
,
" "
)
}
// TODO: get the fields from the HelpText struct by default (when commands are ported to use it)
fields
:=
helpFields
{
Indent
:
indentStr
,
Path
:
pathStr
,
...
...
@@ -112,6 +114,17 @@ func LongHelp(rootName string, root *cmds.Command, path []string, out io.Writer)
Description
:
cmd
.
Help
,
}
// TODO: don't do these checks, just use these fields by default (when commands get ported to it)
if
len
(
cmd
.
Helptext
.
Tagline
)
>
0
{
fields
.
Tagline
=
cmd
.
Helptext
.
Tagline
}
if
len
(
cmd
.
Helptext
.
ShortDescription
)
>
0
{
fields
.
Description
=
cmd
.
Helptext
.
ShortDescription
}
if
len
(
cmd
.
Helptext
.
Usage
)
>
0
{
fields
.
Usage
=
cmd
.
Helptext
.
Subcommands
}
// autogen fields that are empty
if
len
(
cmd
.
ArgumentHelp
)
==
0
{
fields
.
Arguments
=
strings
.
Join
(
argumentText
(
cmd
),
"
\n
"
)
...
...
@@ -151,6 +164,28 @@ func ShortHelp(rootName string, root *cmds.Command, path []string, out io.Writer
Description
:
cmd
.
Help
,
}
// TODO: don't do these checks, just use these fields by default (when commands get ported to it)
if
len
(
cmd
.
Helptext
.
Tagline
)
>
0
{
fields
.
Tagline
=
cmd
.
Helptext
.
Tagline
}
if
len
(
cmd
.
Helptext
.
Arguments
)
>
0
{
fields
.
Arguments
=
cmd
.
Helptext
.
Arguments
}
if
len
(
cmd
.
Helptext
.
Options
)
>
0
{
fields
.
Options
=
cmd
.
Helptext
.
Options
}
if
len
(
cmd
.
Helptext
.
Subcommands
)
>
0
{
fields
.
Subcommands
=
cmd
.
Helptext
.
Subcommands
}
if
len
(
cmd
.
Helptext
.
LongDescription
)
>
0
{
fields
.
Description
=
cmd
.
Helptext
.
LongDescription
}
else
if
len
(
cmd
.
Helptext
.
ShortDescription
)
>
0
{
fields
.
Description
=
cmd
.
Helptext
.
ShortDescription
}
if
len
(
cmd
.
Helptext
.
Usage
)
>
0
{
fields
.
Usage
=
cmd
.
Helptext
.
Subcommands
}
fields
.
Description
=
indentString
(
fields
.
Description
,
indentStr
)
return
shortHelpTemplate
.
Execute
(
out
,
fields
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment