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
1342575d
Commit
1342575d
authored
Nov 12, 2014
by
Juan Batiz-Benet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cmds2/commands: better sorting
parent
7daf8889
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
15 deletions
+21
-15
core/commands2/commands.go
core/commands2/commands.go
+21
-15
No files found.
core/commands2/commands.go
View file @
1342575d
package
commands
import
(
"fmt"
"bytes"
"sort"
cmds
"github.com/jbenet/go-ipfs/commands"
)
...
...
@@ -21,21 +22,24 @@ func CommandsCmd(root *cmds.Command) *cmds.Command {
},
Run
:
func
(
req
cmds
.
Request
)
(
interface
{},
error
)
{
root
:=
outputC
omman
d
(
"ipfs"
,
root
)
root
:=
cmd2
outputC
m
d
(
"ipfs"
,
root
)
return
&
root
,
nil
},
Marshallers
:
map
[
cmds
.
EncodingType
]
cmds
.
Marshaller
{
cmds
.
Text
:
func
(
res
cmds
.
Response
)
([]
byte
,
error
)
{
v
:=
res
.
Output
()
.
(
*
Command
)
s
:=
formatCommand
(
""
,
v
)
return
[]
byte
(
s
),
nil
var
buf
bytes
.
Buffer
for
_
,
s
:=
range
cmdPathStrings
(
v
)
{
buf
.
Write
([]
byte
(
s
+
"
\n
"
))
}
return
buf
.
Bytes
(),
nil
},
},
Type
:
&
Command
{},
}
}
func
outputC
omman
d
(
name
string
,
cmd
*
cmds
.
Command
)
Command
{
func
cmd2
outputC
m
d
(
name
string
,
cmd
*
cmds
.
Command
)
Command
{
output
:=
Command
{
Name
:
name
,
Subcommands
:
make
([]
Command
,
len
(
cmd
.
Subcommands
)),
...
...
@@ -43,23 +47,25 @@ func outputCommand(name string, cmd *cmds.Command) Command {
i
:=
0
for
name
,
sub
:=
range
cmd
.
Subcommands
{
output
.
Subcommands
[
i
]
=
outputC
omman
d
(
name
,
sub
)
output
.
Subcommands
[
i
]
=
cmd2
outputC
m
d
(
name
,
sub
)
i
++
}
return
output
}
func
formatCommand
(
prefix
string
,
cmd
*
Command
)
string
{
if
len
(
prefix
)
>
0
{
prefix
+=
" "
}
s
:=
fmt
.
Sprintf
(
"%s%s
\n
"
,
prefix
,
cmd
.
Name
)
func
cmdPathStrings
(
cmd
*
Command
)
[]
string
{
var
cmds
[]
string
prefix
+=
cmd
.
Name
for
_
,
sub
:=
range
cmd
.
Subcommands
{
s
+=
formatCommand
(
prefix
,
&
sub
)
var
recurse
func
(
prefix
string
,
cmd
*
Command
)
recurse
=
func
(
prefix
string
,
cmd
*
Command
)
{
cmds
=
append
(
cmds
,
prefix
+
cmd
.
Name
)
for
_
,
sub
:=
range
cmd
.
Subcommands
{
recurse
(
prefix
+
cmd
.
Name
+
" "
,
&
sub
)
}
}
return
s
recurse
(
""
,
cmd
)
sort
.
Sort
(
sort
.
StringSlice
(
cmds
))
return
cmds
}
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