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
38318a6c
Commit
38318a6c
authored
Nov 02, 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 output for 'add' command
parent
77fea892
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
2 deletions
+31
-2
core/commands2/add.go
core/commands2/add.go
+31
-2
No files found.
core/commands2/add.go
View file @
38318a6c
...
...
@@ -13,6 +13,10 @@ import (
// Error indicating the max depth has been exceded.
var
ErrDepthLimitExceeded
=
fmt
.
Errorf
(
"depth limit exceeded"
)
type
AddOutput
struct
{
Added
[]
Object
}
var
addCmd
=
&
cmds
.
Command
{
Options
:
[]
cmds
.
Option
{
cmds
.
Option
{[]
string
{
"recursive"
,
"r"
},
cmds
.
Bool
},
...
...
@@ -29,16 +33,41 @@ var addCmd = &cmds.Command{
//if r, _ := opt.(bool); found && r {
//}
added
:=
make
([]
Object
,
len
(
req
.
Arguments
()))
// add every path in args
for
_
,
arg
:=
range
req
.
Arguments
()
{
for
i
,
arg
:=
range
req
.
Arguments
()
{
// Add the file
node
,
err
:=
add
(
n
,
arg
.
(
io
.
Reader
))
if
err
!=
nil
{
res
.
SetError
(
err
,
cmds
.
ErrNormal
)
return
}
k
,
err
:=
node
.
Key
()
if
err
!=
nil
{
res
.
SetError
(
err
,
cmds
.
ErrNormal
)
return
}
fmt
.
Println
(
node
.
Key
())
added
[
i
]
=
Object
{
k
.
String
(),
nil
}
}
res
.
SetValue
(
&
AddOutput
{
added
})
},
Format
:
func
(
res
cmds
.
Response
)
(
string
,
error
)
{
v
:=
res
.
Value
()
.
(
*
AddOutput
)
.
Added
if
len
(
v
)
==
1
{
return
fmt
.
Sprintf
(
"Added object: %s
\n
"
,
v
[
0
]
.
Hash
),
nil
}
s
:=
fmt
.
Sprintf
(
"Added %v objects:
\n
"
,
len
(
v
))
for
_
,
obj
:=
range
v
{
s
+=
fmt
.
Sprintf
(
"- %s
\n
"
,
obj
.
Hash
)
}
return
s
,
nil
},
Type
:
&
AddOutput
{},
}
func
add
(
n
*
core
.
IpfsNode
,
in
io
.
Reader
)
(
*
dag
.
Node
,
error
)
{
...
...
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