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
3d94e89d
Commit
3d94e89d
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: Made error messages more visible
parent
c542cb52
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
16 deletions
+24
-16
cmd/ipfs2/main.go
cmd/ipfs2/main.go
+24
-16
No files found.
cmd/ipfs2/main.go
View file @
3d94e89d
...
...
@@ -23,14 +23,17 @@ import (
// log is the command logger
var
log
=
u
.
Logger
(
"cmd/ipfs"
)
const
heapProfile
=
"ipfs.mprof"
const
(
heapProfile
=
"ipfs.mprof"
errorFormat
=
"ERROR: %v
\n\n
"
)
func
main
()
{
args
:=
os
.
Args
[
1
:
]
req
,
root
:=
createRequest
(
args
)
handleOptions
(
req
,
root
)
res
:=
callCommand
(
req
,
root
)
outputResponse
(
res
)
outputResponse
(
res
,
root
)
if
u
.
Debug
{
err
:=
writeHeapProfileToFile
()
...
...
@@ -57,17 +60,18 @@ func createRequest(args []string) (cmds.Request, *cmds.Command) {
// e.g. incorrect number of args, or nonexistent subcommand)
if
err
!=
nil
{
// if the -help flag wasn't specified, show the error message
// or if a path was returned (user specified a valid subcommand), show the error message
// (this means there was an option or argument error)
if
options
!=
nil
||
path
!=
nil
&&
len
(
path
)
>
0
{
help
:=
false
if
options
!=
nil
{
opt
,
_
:=
options
.
Option
(
"help"
)
help
,
_
:=
opt
.
(
bool
)
if
!
help
{
fmt
.
Println
(
err
)
help
,
_
=
opt
.
(
bool
)
}
}
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
)
if
!
help
{
fmt
.
Printf
(
errorFormat
,
err
)
}
}
// when generating help for the root command, we don't want the autogenerated subcommand text
...
...
@@ -222,13 +226,17 @@ func callCommand(req cmds.Request, root *cmds.Command) cmds.Response {
return
res
}
func
outputResponse
(
res
cmds
.
Response
)
{
func
outputResponse
(
res
cmds
.
Response
,
root
*
cmds
.
Command
)
{
if
res
.
Error
()
!=
nil
{
fmt
.
Print
ln
(
res
.
Error
()
.
Error
())
fmt
.
Print
f
(
errorFormat
,
res
.
Error
()
.
Error
())
if
res
.
Request
()
.
Command
()
.
Help
!=
""
&&
res
.
Error
()
.
Code
==
cmds
.
ErrClient
{
// TODO: convert from markdown to ANSI terminal format?
fmt
.
Println
(
res
.
Request
()
.
Command
()
.
Help
)
if
res
.
Error
()
.
Code
==
cmds
.
ErrClient
{
helpText
,
err
:=
cmdsCli
.
HelpText
(
"ipfs"
,
root
,
res
.
Request
()
.
Path
())
if
err
!=
nil
{
fmt
.
Println
(
err
.
Error
())
}
else
{
fmt
.
Println
(
helpText
)
}
}
os
.
Exit
(
1
)
...
...
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