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
0c205f56
Commit
0c205f56
authored
Oct 30, 2014
by
Matt Bell
Committed by
Juan Batiz-Benet
Nov 14, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
core/commands2: Added 'commands' command
parent
921d3a51
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
57 additions
and
0 deletions
+57
-0
core/commands2/commands.go
core/commands2/commands.go
+56
-0
core/commands2/root.go
core/commands2/root.go
+1
-0
No files found.
core/commands2/commands.go
0 → 100644
View file @
0c205f56
package
commands
import
(
"fmt"
"strings"
cmds
"github.com/jbenet/go-ipfs/commands"
)
type
Command
struct
{
Name
string
Subcommands
[]
Command
}
var
commandsCmd
=
&
cmds
.
Command
{
Help
:
"TODO"
,
Run
:
func
(
res
cmds
.
Response
,
req
cmds
.
Request
)
{
root
:=
outputCommand
(
"ipfs"
,
Root
)
res
.
SetValue
(
&
root
)
},
Format
:
func
(
res
cmds
.
Response
)
(
string
,
error
)
{
v
:=
res
.
Value
()
.
(
*
Command
)
return
formatCommand
(
v
,
0
),
nil
},
Type
:
&
Command
{},
}
func
outputCommand
(
name
string
,
cmd
*
cmds
.
Command
)
Command
{
output
:=
Command
{
Name
:
name
,
Subcommands
:
make
([]
Command
,
len
(
cmd
.
Subcommands
)),
}
i
:=
0
for
name
,
sub
:=
range
cmd
.
Subcommands
{
output
.
Subcommands
[
i
]
=
outputCommand
(
name
,
sub
)
i
++
}
return
output
}
func
formatCommand
(
cmd
*
Command
,
depth
int
)
string
{
var
s
string
if
depth
>
0
{
indent
:=
strings
.
Repeat
(
" "
,
depth
-
1
)
s
=
fmt
.
Sprintf
(
"%s%s
\n
"
,
indent
,
cmd
.
Name
)
}
for
_
,
sub
:=
range
cmd
.
Subcommands
{
s
+=
formatCommand
(
&
sub
,
depth
+
1
)
}
return
s
}
core/commands2/root.go
View file @
0c205f56
...
...
@@ -110,4 +110,5 @@ Use "ipfs help <command>" for more information about a command.
func
init
()
{
Root
.
Subcommands
[
"daemon"
]
=
daemonCmd
Root
.
Subcommands
[
"commands"
]
=
commandsCmd
}
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