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
24814a41
Commit
24814a41
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
core/commands2: Set root subcommands in init to prevent initialization loops
parent
6ae09b16
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
54 additions
and
52 deletions
+54
-52
core/commands2/root.go
core/commands2/root.go
+54
-52
No files found.
core/commands2/root.go
View file @
24814a41
...
...
@@ -50,65 +50,67 @@ Plumbing commands:
Use "ipfs help <command>" for more information about a command.
`
,
Subcommands
:
map
[
string
]
*
cmds
.
Command
{
"cat"
:
catCmd
,
"ls"
:
lsCmd
,
"init"
:
initCmd
,
// test subcommands
// TODO: remove these when we don't need them anymore
"beep"
:
&
cmds
.
Command
{
Run
:
func
(
res
cmds
.
Response
,
req
cmds
.
Request
)
{
v
:=
&
TestOutput
{
"hello, world"
,
1337
}
res
.
SetValue
(
v
)
},
Format
:
func
(
res
cmds
.
Response
)
(
string
,
error
)
{
v
:=
res
.
Value
()
.
(
*
TestOutput
)
s
:=
fmt
.
Sprintf
(
"Foo: %s
\n
"
,
v
.
Foo
)
s
+=
fmt
.
Sprintf
(
"Bar: %v
\n
"
,
v
.
Bar
)
return
s
,
nil
},
Type
:
&
TestOutput
{},
}
var
rootSubcommands
=
map
[
string
]
*
cmds
.
Command
{
"cat"
:
catCmd
,
"ls"
:
lsCmd
,
"commands"
:
commandsCmd
,
"init"
:
initCmd
,
"daemon"
:
daemonCmd
,
// test subcommands
// TODO: remove these when we don't need them anymore
"beep"
:
&
cmds
.
Command
{
Run
:
func
(
res
cmds
.
Response
,
req
cmds
.
Request
)
{
v
:=
&
TestOutput
{
"hello, world"
,
1337
}
res
.
SetValue
(
v
)
},
Format
:
func
(
res
cmds
.
Response
)
(
string
,
error
)
{
v
:=
res
.
Value
()
.
(
*
TestOutput
)
s
:=
fmt
.
Sprintf
(
"Foo: %s
\n
"
,
v
.
Foo
)
s
+=
fmt
.
Sprintf
(
"Bar: %v
\n
"
,
v
.
Bar
)
return
s
,
nil
},
Type
:
&
TestOutput
{},
},
"boop"
:
&
cmds
.
Command
{
Run
:
func
(
res
cmds
.
Response
,
req
cmds
.
Request
)
{
v
:=
strings
.
NewReader
(
"hello, world"
)
res
.
SetValue
(
v
)
},
"boop"
:
&
cmds
.
Command
{
Run
:
func
(
res
cmds
.
Response
,
req
cmds
.
Request
)
{
v
:=
strings
.
NewReader
(
"hello, world"
)
res
.
SetValue
(
v
)
},
},
"warp"
:
&
cmds
.
Command
{
Options
:
[]
cmds
.
Option
{
cmds
.
Option
{[]
string
{
"power"
,
"p"
},
cmds
.
Float
},
},
"warp"
:
&
cmds
.
Command
{
Options
:
[]
cmds
.
Option
{
cmds
.
Option
{[]
string
{
"power"
,
"p"
},
cmds
.
Float
},
},
Run
:
func
(
res
cmds
.
Response
,
req
cmds
.
Request
)
{
threshold
:=
1.21
if
power
,
found
:=
req
.
Option
(
"power"
);
found
&&
power
.
(
float64
)
>=
threshold
{
res
.
SetValue
(
struct
{
Status
string
Power
float64
}{
"Flux capacitor activated!"
,
power
.
(
float64
)})
}
else
{
err
:=
fmt
.
Errorf
(
"Insufficient power (%v jiggawatts required)"
,
threshold
)
res
.
SetError
(
err
,
cmds
.
ErrClient
)
}
},
Run
:
func
(
res
cmds
.
Response
,
req
cmds
.
Request
)
{
threshold
:=
1.21
if
power
,
found
:=
req
.
Option
(
"power"
);
found
&&
power
.
(
float64
)
>=
threshold
{
res
.
SetValue
(
struct
{
Status
string
Power
float64
}{
"Flux capacitor activated!"
,
power
.
(
float64
)})
}
else
{
err
:=
fmt
.
Errorf
(
"Insufficient power (%v jiggawatts required)"
,
threshold
)
res
.
SetError
(
err
,
cmds
.
ErrClient
)
}
},
"args"
:
&
cmds
.
Command
{
Run
:
func
(
res
cmds
.
Response
,
req
cmds
.
Request
)
{
res
.
SetValue
(
req
.
Arguments
())
},
},
"args"
:
&
cmds
.
Command
{
Run
:
func
(
res
cmds
.
Response
,
req
cmds
.
Request
)
{
res
.
SetValue
(
req
.
Arguments
())
},
"echo"
:
&
cmds
.
Command
{
Run
:
func
(
res
cmds
.
Response
,
req
cmds
.
Request
)
{
res
.
SetValue
(
req
.
Stream
())
},
},
"echo"
:
&
cmds
.
Command
{
Run
:
func
(
res
cmds
.
Response
,
req
cmds
.
Request
)
{
res
.
SetValue
(
req
.
Stream
())
},
},
}
func
init
()
{
Root
.
Subcommands
[
"daemon"
]
=
daemonCmd
Root
.
Subcommands
[
"commands"
]
=
commandsCmd
Root
.
Subcommands
=
rootSubcommands
}
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