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-unixfs
Commits
ec8be23c
Commit
ec8be23c
authored
Nov 12, 2014
by
Juan Batiz-Benet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cmds/main decomposed handleParseError
parent
c25bf522
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
43 additions
and
39 deletions
+43
-39
cmd/ipfs2/main.go
cmd/ipfs2/main.go
+43
-39
No files found.
cmd/ipfs2/main.go
View file @
ec8be23c
...
...
@@ -92,17 +92,47 @@ func createRequest(args []string) (cmds.Request, *cmds.Command, error) {
// handle parse error (which means the commandline input was wrong,
// e.g. incorrect number of args, or nonexistent subcommand)
if
err
!=
nil
{
return
nil
,
nil
,
handleParseError
(
req
,
root
,
cmd
,
path
)
}
configPath
,
err
:=
getConfigRoot
(
req
)
if
err
!=
nil
{
return
nil
,
nil
,
err
}
conf
,
err
:=
getConfig
(
configPath
)
if
err
!=
nil
{
return
nil
,
nil
,
err
}
ctx
:=
req
.
Context
()
ctx
.
ConfigRoot
=
configPath
ctx
.
Config
=
conf
// if no encoding was specified by user, default to plaintext encoding
// (if command doesn't support plaintext, use JSON instead)
if
!
req
.
Option
(
"encoding"
)
.
Found
()
{
if
req
.
Command
()
.
Marshallers
!=
nil
&&
req
.
Command
()
.
Marshallers
[
cmds
.
Text
]
!=
nil
{
req
.
SetOption
(
"encoding"
,
cmds
.
Text
)
}
else
{
req
.
SetOption
(
"encoding"
,
cmds
.
JSON
)
}
}
return
req
,
root
,
nil
}
func
handleParseError
(
req
cmds
.
Request
,
root
*
cmds
.
Command
,
cmd
*
cmds
.
Command
,
path
[]
string
)
(
err
error
)
{
var
longHelp
,
shortHelp
bool
if
req
!=
nil
{
// help and h are defined in the root. We expect them to be bool.
longHelp
,
_
,
err
=
req
.
Option
(
"help"
)
.
Bool
()
if
err
!=
nil
{
return
nil
,
nil
,
err
return
err
}
shortHelp
,
_
,
err
=
req
.
Option
(
"h"
)
.
Bool
()
if
err
!=
nil
{
return
nil
,
nil
,
err
return
err
}
}
...
...
@@ -130,33 +160,7 @@ func createRequest(args []string) (cmds.Request, *cmds.Command, error) {
if
htErr
!=
nil
{
fmt
.
Println
(
htErr
)
}
return
nil
,
nil
,
err
}
configPath
,
err
:=
getConfigRoot
(
req
)
if
err
!=
nil
{
return
nil
,
nil
,
err
}
conf
,
err
:=
getConfig
(
configPath
)
if
err
!=
nil
{
return
nil
,
nil
,
err
}
ctx
:=
req
.
Context
()
ctx
.
ConfigRoot
=
configPath
ctx
.
Config
=
conf
// if no encoding was specified by user, default to plaintext encoding
// (if command doesn't support plaintext, use JSON instead)
if
!
req
.
Option
(
"encoding"
)
.
Found
()
{
if
req
.
Command
()
.
Marshallers
!=
nil
&&
req
.
Command
()
.
Marshallers
[
cmds
.
Text
]
!=
nil
{
req
.
SetOption
(
"encoding"
,
cmds
.
Text
)
}
else
{
req
.
SetOption
(
"encoding"
,
cmds
.
JSON
)
}
}
return
req
,
root
,
nil
return
err
}
func
handleHelpOption
(
req
cmds
.
Request
,
root
*
cmds
.
Command
)
(
helpTextDisplayed
bool
,
err
error
)
{
...
...
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