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
d700a2ce
Commit
d700a2ce
authored
10 years ago
by
Matt Bell
Committed by
Juan Batiz-Benet
10 years ago
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cmd/ipfs2: Cleaned up main option checking (no longer need temporary Request)
parent
eebb4375
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
48 deletions
+8
-48
cmd/ipfs2/main.go
cmd/ipfs2/main.go
+8
-48
No files found.
cmd/ipfs2/main.go
View file @
d700a2ce
...
@@ -59,28 +59,16 @@ func main() {
...
@@ -59,28 +59,16 @@ func main() {
func
createRequest
(
args
[]
string
)
(
cmds
.
Request
,
*
cmds
.
Command
)
{
func
createRequest
(
args
[]
string
)
(
cmds
.
Request
,
*
cmds
.
Command
)
{
req
,
root
,
cmd
,
path
,
err
:=
cmdsCli
.
Parse
(
args
,
Root
,
commands
.
Root
)
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
)
exit
(
1
)
}
}
// handle parse error (which means the commandline input was wrong,
// handle parse error (which means the commandline input was wrong,
// e.g. incorrect number of args, or nonexistent subcommand)
// e.g. incorrect number of args, or nonexistent subcommand)
if
err
!=
nil
{
if
err
!=
nil
{
// if the -help flag wasn't specified, show the error message
// 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
// or if a path was returned (user specified a valid subcommand), show the error message
// (this means there was an option or argument error)
// (this means there was an option or argument error)
if
options
!=
nil
||
path
!=
nil
&&
len
(
path
)
>
0
{
if
path
!=
nil
&&
len
(
path
)
>
0
{
help
:=
false
help
:=
false
if
options
!=
nil
{
opt
,
_
:=
req
.
Option
(
"help"
)
opt
,
_
:=
options
.
Option
(
"help"
)
help
,
_
=
opt
.
(
bool
)
help
,
_
=
opt
.
(
bool
)
}
if
!
help
{
if
!
help
{
fmt
.
Printf
(
errorFormat
,
err
)
fmt
.
Printf
(
errorFormat
,
err
)
...
@@ -104,7 +92,7 @@ func createRequest(args []string) (cmds.Request, *cmds.Command) {
...
@@ -104,7 +92,7 @@ func createRequest(args []string) (cmds.Request, *cmds.Command) {
exit
(
1
)
exit
(
1
)
}
}
configPath
,
err
:=
getConfigRoot
(
options
)
configPath
,
err
:=
getConfigRoot
(
req
)
if
err
!=
nil
{
if
err
!=
nil
{
fmt
.
Println
(
err
)
fmt
.
Println
(
err
)
exit
(
1
)
exit
(
1
)
...
@@ -120,7 +108,7 @@ func createRequest(args []string) (cmds.Request, *cmds.Command) {
...
@@ -120,7 +108,7 @@ func createRequest(args []string) (cmds.Request, *cmds.Command) {
ctx
.
ConfigRoot
=
configPath
ctx
.
ConfigRoot
=
configPath
ctx
.
Config
=
conf
ctx
.
Config
=
conf
if
_
,
found
:=
options
.
Option
(
"encoding"
);
!
found
{
if
_
,
found
:=
req
.
Option
(
"encoding"
);
!
found
{
if
req
.
Command
()
.
Marshallers
!=
nil
&&
req
.
Command
()
.
Marshallers
[
cmds
.
Text
]
!=
nil
{
if
req
.
Command
()
.
Marshallers
!=
nil
&&
req
.
Command
()
.
Marshallers
[
cmds
.
Text
]
!=
nil
{
req
.
SetOption
(
"encoding"
,
cmds
.
Text
)
req
.
SetOption
(
"encoding"
,
cmds
.
Text
)
}
else
{
}
else
{
...
@@ -132,13 +120,7 @@ func createRequest(args []string) (cmds.Request, *cmds.Command) {
...
@@ -132,13 +120,7 @@ func createRequest(args []string) (cmds.Request, *cmds.Command) {
}
}
func
handleOptions
(
req
cmds
.
Request
,
root
*
cmds
.
Command
)
{
func
handleOptions
(
req
cmds
.
Request
,
root
*
cmds
.
Command
)
{
options
,
err
:=
getOptions
(
req
,
root
)
if
help
,
found
:=
req
.
Option
(
"help"
);
found
{
if
err
!=
nil
{
fmt
.
Println
(
err
)
exit
(
1
)
}
if
help
,
found
:=
options
.
Option
(
"help"
);
found
{
if
helpBool
,
ok
:=
help
.
(
bool
);
helpBool
&&
ok
{
if
helpBool
,
ok
:=
help
.
(
bool
);
helpBool
&&
ok
{
helpText
,
err
:=
cmdsCli
.
HelpText
(
"ipfs"
,
root
,
req
.
Path
())
helpText
,
err
:=
cmdsCli
.
HelpText
(
"ipfs"
,
root
,
req
.
Path
())
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -153,7 +135,7 @@ func handleOptions(req cmds.Request, root *cmds.Command) {
...
@@ -153,7 +135,7 @@ func handleOptions(req cmds.Request, root *cmds.Command) {
}
}
}
}
if
debug
,
found
:=
options
.
Option
(
"debug"
);
found
{
if
debug
,
found
:=
req
.
Option
(
"debug"
);
found
{
if
debugBool
,
ok
:=
debug
.
(
bool
);
debugBool
&&
ok
{
if
debugBool
,
ok
:=
debug
.
(
bool
);
debugBool
&&
ok
{
u
.
Debug
=
true
u
.
Debug
=
true
...
@@ -172,16 +154,10 @@ func callCommand(req cmds.Request, root *cmds.Command) cmds.Response {
...
@@ -172,16 +154,10 @@ func callCommand(req cmds.Request, root *cmds.Command) cmds.Response {
res
=
root
.
Call
(
req
)
res
=
root
.
Call
(
req
)
}
else
{
}
else
{
options
,
err
:=
getOptions
(
req
,
root
)
if
err
!=
nil
{
fmt
.
Println
(
err
)
exit
(
1
)
}
var
found
bool
var
found
bool
var
local
interface
{}
var
local
interface
{}
localBool
:=
false
localBool
:=
false
if
local
,
found
=
options
.
Option
(
"local"
);
found
{
if
local
,
found
=
req
.
Option
(
"local"
);
found
{
var
ok
bool
var
ok
bool
localBool
,
ok
=
local
.
(
bool
)
localBool
,
ok
=
local
.
(
bool
)
if
!
ok
{
if
!
ok
{
...
@@ -252,22 +228,6 @@ func outputResponse(res cmds.Response, root *cmds.Command) {
...
@@ -252,22 +228,6 @@ func outputResponse(res cmds.Response, root *cmds.Command) {
io
.
Copy
(
os
.
Stdout
,
out
)
io
.
Copy
(
os
.
Stdout
,
out
)
}
}
func
getOptions
(
req
cmds
.
Request
,
root
*
cmds
.
Command
)
(
cmds
.
Request
,
error
)
{
tempReq
:=
cmds
.
NewRequest
(
req
.
Path
(),
req
.
Options
(),
nil
,
nil
)
options
,
err
:=
root
.
GetOptions
(
tempReq
.
Path
())
if
err
!=
nil
{
return
nil
,
err
}
err
=
tempReq
.
ConvertOptions
(
options
)
if
err
!=
nil
{
return
nil
,
err
}
return
tempReq
,
nil
}
func
getConfigRoot
(
req
cmds
.
Request
)
(
string
,
error
)
{
func
getConfigRoot
(
req
cmds
.
Request
)
(
string
,
error
)
{
if
opt
,
found
:=
req
.
Option
(
"config"
);
found
{
if
opt
,
found
:=
req
.
Option
(
"config"
);
found
{
if
optStr
,
ok
:=
opt
.
(
string
);
ok
{
if
optStr
,
ok
:=
opt
.
(
string
);
ok
{
...
...
This diff is collapsed.
Click to expand it.
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