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
503bd672
Commit
503bd672
authored
Nov 11, 2014
by
Matt Bell
Committed by
Juan Batiz-Benet
Nov 14, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
commands: Allow overriding helptext sections with hand-written strings
parent
f6281e5a
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
8 deletions
+31
-8
cli/helptext.go
cli/helptext.go
+24
-6
command.go
command.go
+7
-2
No files found.
cli/helptext.go
View file @
503bd672
...
@@ -36,18 +36,36 @@ func HelpText(rootName string, root *cmds.Command, path []string) (string, error
...
@@ -36,18 +36,36 @@ func HelpText(rootName string, root *cmds.Command, path []string) (string, error
}
}
if
cmd
.
Arguments
!=
nil
{
if
cmd
.
Arguments
!=
nil
{
lines
:=
indent
(
argumentText
(
cmd
),
" "
)
if
len
(
cmd
.
ArgumentHelp
)
>
0
{
s
+=
fmt
.
Sprintf
(
"Arguments:
\n
%v
\n\n
"
,
strings
.
Join
(
lines
,
"
\n
"
))
s
+=
cmd
.
ArgumentHelp
}
else
{
section
:=
strings
.
Join
(
indent
(
argumentText
(
cmd
),
" "
),
"
\n
"
)
s
+=
fmt
.
Sprintf
(
"Arguments:
\n
%v"
,
section
)
}
s
+=
"
\n\n
"
}
}
if
cmd
.
Subcommands
!=
nil
{
if
cmd
.
Subcommands
!=
nil
{
lines
:=
indent
(
subcommandText
(
cmd
,
rootName
,
path
),
" "
)
if
len
(
cmd
.
SubcommandHelp
)
>
0
{
s
+=
fmt
.
Sprintf
(
"Subcommands:
\n
%v
\n\n
"
,
strings
.
Join
(
lines
,
"
\n
"
))
s
+=
cmd
.
SubcommandHelp
}
else
{
section
:=
strings
.
Join
(
indent
(
subcommandText
(
cmd
,
rootName
,
path
),
" "
),
"
\n
"
)
s
+=
fmt
.
Sprintf
(
"Subcommands:
\n
%v"
,
section
)
}
s
+=
"
\n\n
"
}
}
if
cmd
.
Options
!=
nil
{
if
cmd
.
Options
!=
nil
{
lines
:=
indent
(
optionText
(
cmd
),
" "
)
if
len
(
cmd
.
OptionHelp
)
>
0
{
s
+=
fmt
.
Sprintf
(
"Options:
\n
%v
\n\n
"
,
strings
.
Join
(
lines
,
"
\n
"
))
s
+=
cmd
.
OptionHelp
}
else
{
section
:=
strings
.
Join
(
indent
(
optionText
(
cmd
),
" "
),
"
\n
"
)
s
+=
fmt
.
Sprintf
(
"Options:
\n
%v"
,
section
)
}
s
+=
"
\n\n
"
}
}
return
s
,
nil
return
s
,
nil
...
...
command.go
View file @
503bd672
...
@@ -28,8 +28,13 @@ type Marshaller func(Response) ([]byte, error)
...
@@ -28,8 +28,13 @@ type Marshaller func(Response) ([]byte, error)
// Command is a runnable command, with input arguments and options (flags).
// Command is a runnable command, with input arguments and options (flags).
// It can also have Subcommands, to group units of work into sets.
// It can also have Subcommands, to group units of work into sets.
type
Command
struct
{
type
Command
struct
{
// MAYBE_TODO: move all the text fields into a struct
// MAYBE_TODO: move these out of command and put them somewhere in commands/cli
Description
string
Description
string
Help
string
Help
string
SubcommandHelp
string
OptionHelp
string
ArgumentHelp
string
Options
[]
Option
Options
[]
Option
Arguments
[]
Argument
Arguments
[]
Argument
...
...
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