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
c70ca4dd
Commit
c70ca4dd
authored
Oct 31, 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 'publish' command
parent
d8afd9a9
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
70 additions
and
0 deletions
+70
-0
core/commands2/publish.go
core/commands2/publish.go
+69
-0
core/commands2/root.go
core/commands2/root.go
+1
-0
No files found.
core/commands2/publish.go
0 → 100644
View file @
c70ca4dd
package
commands
import
(
"errors"
"fmt"
cmds
"github.com/jbenet/go-ipfs/commands"
nsys
"github.com/jbenet/go-ipfs/namesys"
u
"github.com/jbenet/go-ipfs/util"
)
type
PublishOutput
struct
{
Name
,
Value
string
}
var
publishCmd
=
&
cmds
.
Command
{
Help
:
"TODO"
,
Run
:
func
(
res
cmds
.
Response
,
req
cmds
.
Request
)
{
n
:=
req
.
Context
()
.
Node
args
:=
req
.
Arguments
()
if
n
.
Identity
==
nil
{
res
.
SetError
(
errors
.
New
(
"Identity not loaded!"
),
cmds
.
ErrNormal
)
return
}
// name := ""
ref
:=
""
switch
len
(
args
)
{
case
2
:
// name = args[0]
ref
=
args
[
1
]
res
.
SetError
(
errors
.
New
(
"keychains not yet implemented"
),
cmds
.
ErrNormal
)
return
case
1
:
// name = n.Identity.ID.String()
ref
=
args
[
0
]
default
:
res
.
SetError
(
fmt
.
Errorf
(
"Publish expects 1 or 2 args; got %d."
,
len
(
args
)),
cmds
.
ErrClient
)
}
// later, n.Keychain.Get(name).PrivKey
k
:=
n
.
Identity
.
PrivKey
()
pub
:=
nsys
.
NewRoutingPublisher
(
n
.
Routing
)
err
:=
pub
.
Publish
(
k
,
ref
)
if
err
!=
nil
{
res
.
SetError
(
err
,
cmds
.
ErrNormal
)
return
}
hash
,
err
:=
k
.
GetPublic
()
.
Hash
()
if
err
!=
nil
{
res
.
SetError
(
err
,
cmds
.
ErrNormal
)
return
}
res
.
SetValue
(
&
PublishOutput
{
Name
:
u
.
Key
(
hash
)
.
String
(),
Value
:
ref
,
})
},
Format
:
func
(
res
cmds
.
Response
)
(
string
,
error
)
{
v
:=
res
.
Value
()
.
(
*
PublishOutput
)
return
fmt
.
Sprintf
(
"Published name %s to %s
\n
"
,
v
.
Name
,
v
.
Value
),
nil
},
Type
:
&
PublishOutput
{},
}
core/commands2/root.go
View file @
c70ca4dd
...
...
@@ -56,6 +56,7 @@ var rootSubcommands = map[string]*cmds.Command{
"cat"
:
catCmd
,
"ls"
:
lsCmd
,
"commands"
:
commandsCmd
,
"publish"
:
publishCmd
,
// test subcommands
// TODO: remove these when we don't need them anymore
...
...
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