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
3dd7a9a5
Commit
3dd7a9a5
authored
Nov 03, 2014
by
Matt Bell
Committed by
Juan Batiz-Benet
Nov 14, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cmd/ipfs2: Broke up main into subfunctions
parent
7c1e4578
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
60 additions
and
30 deletions
+60
-30
cmd/ipfs2/main.go
cmd/ipfs2/main.go
+60
-30
No files found.
cmd/ipfs2/main.go
View file @
3dd7a9a5
...
@@ -21,7 +21,13 @@ var log = u.Logger("cmd/ipfs")
...
@@ -21,7 +21,13 @@ var log = u.Logger("cmd/ipfs")
func
main
()
{
func
main
()
{
args
:=
os
.
Args
[
1
:
]
args
:=
os
.
Args
[
1
:
]
req
,
root
:=
createRequest
(
args
)
handleOptions
(
req
,
root
)
res
:=
callCommand
(
req
,
root
)
outputResponse
(
res
)
}
func
createRequest
(
args
[]
string
)
(
cmds
.
Request
,
*
cmds
.
Command
)
{
req
,
root
,
err
:=
cmdsCli
.
Parse
(
args
,
Root
,
commands
.
Root
)
req
,
root
,
err
:=
cmdsCli
.
Parse
(
args
,
Root
,
commands
.
Root
)
if
err
!=
nil
{
if
err
!=
nil
{
fmt
.
Println
(
err
)
fmt
.
Println
(
err
)
...
@@ -35,6 +41,40 @@ func main() {
...
@@ -35,6 +41,40 @@ func main() {
os
.
Exit
(
1
)
os
.
Exit
(
1
)
}
}
configPath
,
err
:=
getConfigRoot
(
options
)
if
err
!=
nil
{
fmt
.
Println
(
err
)
os
.
Exit
(
1
)
}
conf
,
err
:=
getConfig
(
configPath
)
if
err
!=
nil
{
fmt
.
Println
(
err
)
os
.
Exit
(
1
)
}
ctx
:=
req
.
Context
()
ctx
.
ConfigRoot
=
configPath
ctx
.
Config
=
conf
if
_
,
found
:=
options
.
Option
(
"encoding"
);
!
found
{
if
req
.
Command
()
.
Format
!=
nil
{
req
.
SetOption
(
"encoding"
,
cmds
.
Text
)
}
else
{
req
.
SetOption
(
"encoding"
,
cmds
.
JSON
)
}
}
return
req
,
root
}
func
handleOptions
(
req
cmds
.
Request
,
root
*
cmds
.
Command
)
{
options
,
err
:=
getOptions
(
req
,
root
)
if
err
!=
nil
{
fmt
.
Println
(
err
)
os
.
Exit
(
1
)
}
if
help
,
found
:=
options
.
Option
(
"help"
);
found
{
if
help
,
found
:=
options
.
Option
(
"help"
);
found
{
if
helpBool
,
ok
:=
help
.
(
bool
);
helpBool
&&
ok
{
if
helpBool
,
ok
:=
help
.
(
bool
);
helpBool
&&
ok
{
fmt
.
Println
(
req
.
Command
()
.
Help
)
fmt
.
Println
(
req
.
Command
()
.
Help
)
...
@@ -65,39 +105,25 @@ func main() {
...
@@ -65,39 +105,25 @@ func main() {
os
.
Exit
(
1
)
os
.
Exit
(
1
)
}
}
}
}
}
configPath
,
err
:=
getConfigRoot
(
options
)
func
callCommand
(
req
cmds
.
Request
,
root
*
cmds
.
Command
)
cmds
.
Response
{
if
err
!=
nil
{
fmt
.
Println
(
err
)
os
.
Exit
(
1
)
}
conf
,
err
:=
getConfig
(
configPath
)
if
err
!=
nil
{
fmt
.
Println
(
err
)
os
.
Exit
(
1
)
}
ctx
:=
req
.
Context
()
ctx
.
ConfigRoot
=
configPath
ctx
.
Config
=
conf
if
_
,
found
:=
options
.
Option
(
"encoding"
);
!
found
{
if
req
.
Command
()
.
Format
!=
nil
{
req
.
SetOption
(
"encoding"
,
cmds
.
Text
)
}
else
{
req
.
SetOption
(
"encoding"
,
cmds
.
JSON
)
}
}
var
res
cmds
.
Response
var
res
cmds
.
Response
if
root
==
Root
{
if
root
==
Root
{
res
=
root
.
Call
(
req
)
res
=
root
.
Call
(
req
)
}
else
{
}
else
{
options
,
err
:=
getOptions
(
req
,
root
)
if
err
!=
nil
{
fmt
.
Println
(
err
)
os
.
Exit
(
1
)
}
var
found
bool
var
found
bool
var
local
interface
{}
localBool
:=
false
localBool
:=
false
if
local
,
found
:
=
options
.
Option
(
"local"
);
found
{
if
local
,
found
=
options
.
Option
(
"local"
);
found
{
var
ok
bool
var
ok
bool
localBool
,
ok
=
local
.
(
bool
)
localBool
,
ok
=
local
.
(
bool
)
if
!
ok
{
if
!
ok
{
...
@@ -106,7 +132,7 @@ func main() {
...
@@ -106,7 +132,7 @@ func main() {
}
}
}
}
if
(
!
found
||
!
localBool
)
&&
daemon
.
Locked
(
c
onfig
Path
)
{
if
(
!
found
||
!
localBool
)
&&
daemon
.
Locked
(
req
.
Context
()
.
C
onfig
Root
)
{
res
,
err
=
cmdsHttp
.
Send
(
req
)
res
,
err
=
cmdsHttp
.
Send
(
req
)
if
err
!=
nil
{
if
err
!=
nil
{
fmt
.
Println
(
err
)
fmt
.
Println
(
err
)
...
@@ -114,23 +140,27 @@ func main() {
...
@@ -114,23 +140,27 @@ func main() {
}
}
}
else
{
}
else
{
node
,
err
:=
core
.
NewIpfsNode
(
c
onf
,
false
)
node
,
err
:=
core
.
NewIpfsNode
(
req
.
Context
()
.
C
onf
ig
,
false
)
if
err
!=
nil
{
if
err
!=
nil
{
fmt
.
Println
(
err
)
fmt
.
Println
(
err
)
os
.
Exit
(
1
)
os
.
Exit
(
1
)
}
}
ctx
.
Node
=
node
req
.
Context
()
.
Node
=
node
res
=
root
.
Call
(
req
)
res
=
root
.
Call
(
req
)
}
}
}
}
return
res
}
func
outputResponse
(
res
cmds
.
Response
)
{
if
res
.
Error
()
!=
nil
{
if
res
.
Error
()
!=
nil
{
fmt
.
Println
(
res
.
Error
()
.
Error
())
fmt
.
Println
(
res
.
Error
()
.
Error
())
if
re
q
.
Command
()
.
Help
!=
""
&&
res
.
Error
()
.
Code
==
cmds
.
ErrClient
{
if
re
s
.
Request
()
.
Command
()
.
Help
!=
""
&&
res
.
Error
()
.
Code
==
cmds
.
ErrClient
{
// TODO: convert from markdown to ANSI terminal format?
// TODO: convert from markdown to ANSI terminal format?
fmt
.
Println
(
re
q
.
Command
()
.
Help
)
fmt
.
Println
(
re
s
.
Request
()
.
Command
()
.
Help
)
}
}
os
.
Exit
(
1
)
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