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
Commits
165c6954
Commit
165c6954
authored
Nov 08, 2014
by
Matt Bell
Committed by
Juan Batiz-Benet
Nov 14, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cmd/ipfs2: Output generated help text on error or help flag
parent
3255bb02
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
45 additions
and
13 deletions
+45
-13
cmd/ipfs2/main.go
cmd/ipfs2/main.go
+45
-13
No files found.
cmd/ipfs2/main.go
View file @
165c6954
...
...
@@ -41,22 +41,49 @@ func main() {
}
func
createRequest
(
args
[]
string
)
(
cmds
.
Request
,
*
cmds
.
Command
)
{
req
,
root
,
cmd
,
err
:=
cmdsCli
.
Parse
(
args
,
Root
,
commands
.
Root
)
if
err
!=
nil
{
fmt
.
Println
(
err
)
if
cmd
!=
nil
{
if
cmd
.
Help
!=
""
{
fmt
.
Println
(
cmd
.
Help
)
}
}
else
{
fmt
.
Println
(
Root
.
Help
)
req
,
root
,
cmd
,
path
,
err
:=
cmdsCli
.
Parse
(
args
,
Root
,
commands
.
Root
)
var
options
cmds
.
Request
if
req
!=
nil
&&
root
!=
nil
{
var
err2
error
options
,
err2
=
getOptions
(
req
,
root
)
if
err2
!=
nil
{
fmt
.
Println
(
err2
)
os
.
Exit
(
1
)
}
os
.
Exit
(
1
)
}
options
,
err
:=
getOptions
(
req
,
root
)
// handle parse error (which means the commandline input was wrong,
// e.g. incorrect number of args, or nonexistent subcommand)
if
err
!=
nil
{
fmt
.
Println
(
err
)
// if the -help flag wasn't specified, show the error message
if
options
!=
nil
{
opt
,
_
:=
options
.
Option
(
"help"
)
help
,
_
:=
opt
.
(
bool
)
if
!
help
{
fmt
.
Println
(
err
)
}
}
else
if
path
!=
nil
&&
len
(
path
)
>
0
{
// if a path was returned (user specified a valid subcommand), show the error message
// (this means there was an option or argument error)
fmt
.
Println
(
err
)
}
// when generating help for the root command, we don't want the autogenerated subcommand text
// (since we have better hand-made subcommand list in the root Help field)
if
cmd
==
nil
{
root
=
&*
commands
.
Root
root
.
Subcommands
=
nil
}
// generate the help text for the command the user was trying to call (or root)
helpText
,
err
:=
cmdsCli
.
HelpText
(
"ipfs"
,
root
,
path
)
if
err
!=
nil
{
fmt
.
Println
(
err
)
}
else
{
fmt
.
Println
(
helpText
)
}
os
.
Exit
(
1
)
}
...
...
@@ -96,7 +123,12 @@ func handleOptions(req cmds.Request, root *cmds.Command) {
if
help
,
found
:=
options
.
Option
(
"help"
);
found
{
if
helpBool
,
ok
:=
help
.
(
bool
);
helpBool
&&
ok
{
fmt
.
Println
(
req
.
Command
()
.
Help
)
helpText
,
err
:=
cmdsCli
.
HelpText
(
"ipfs"
,
root
,
req
.
Path
())
if
err
!=
nil
{
fmt
.
Println
(
err
.
Error
())
}
else
{
fmt
.
Println
(
helpText
)
}
os
.
Exit
(
0
)
}
else
if
!
ok
{
fmt
.
Println
(
"error: expected 'help' option to be a bool"
)
...
...
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