mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-20 02:21:48 +08:00
core/commands: Made add command output a channel
core/commands: Don't use pointers for Type field
This commit is contained in:
@ -102,7 +102,7 @@ remains to be implemented.
|
|||||||
}, nil
|
}, nil
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Type: &AddedObject{},
|
Type: AddedObject{},
|
||||||
}
|
}
|
||||||
|
|
||||||
func add(n *core.IpfsNode, readers []io.Reader) ([]*dag.Node, error) {
|
func add(n *core.IpfsNode, readers []io.Reader) ([]*dag.Node, error) {
|
||||||
|
@ -123,7 +123,7 @@ It reads from stdin, and <key> is a base58 encoded multihash.
|
|||||||
Length: len(data),
|
Length: len(data),
|
||||||
}, nil
|
}, nil
|
||||||
},
|
},
|
||||||
Type: &Block{},
|
Type: Block{},
|
||||||
Marshalers: cmds.MarshalerMap{
|
Marshalers: cmds.MarshalerMap{
|
||||||
cmds.Text: func(res cmds.Response) (io.Reader, error) {
|
cmds.Text: func(res cmds.Response) (io.Reader, error) {
|
||||||
block := res.Output().(*Block)
|
block := res.Output().(*Block)
|
||||||
|
@ -112,7 +112,7 @@ in the bootstrap list).
|
|||||||
|
|
||||||
return &BootstrapOutput{added}, nil
|
return &BootstrapOutput{added}, nil
|
||||||
},
|
},
|
||||||
Type: &BootstrapOutput{},
|
Type: BootstrapOutput{},
|
||||||
Marshalers: cmds.MarshalerMap{
|
Marshalers: cmds.MarshalerMap{
|
||||||
cmds.Text: func(res cmds.Response) (io.Reader, error) {
|
cmds.Text: func(res cmds.Response) (io.Reader, error) {
|
||||||
v, ok := res.Output().(*BootstrapOutput)
|
v, ok := res.Output().(*BootstrapOutput)
|
||||||
@ -173,7 +173,7 @@ var bootstrapRemoveCmd = &cmds.Command{
|
|||||||
|
|
||||||
return &BootstrapOutput{removed}, nil
|
return &BootstrapOutput{removed}, nil
|
||||||
},
|
},
|
||||||
Type: &BootstrapOutput{},
|
Type: BootstrapOutput{},
|
||||||
Marshalers: cmds.MarshalerMap{
|
Marshalers: cmds.MarshalerMap{
|
||||||
cmds.Text: func(res cmds.Response) (io.Reader, error) {
|
cmds.Text: func(res cmds.Response) (io.Reader, error) {
|
||||||
v, ok := res.Output().(*BootstrapOutput)
|
v, ok := res.Output().(*BootstrapOutput)
|
||||||
@ -203,7 +203,7 @@ var bootstrapListCmd = &cmds.Command{
|
|||||||
peers := cfg.Bootstrap
|
peers := cfg.Bootstrap
|
||||||
return &BootstrapOutput{peers}, nil
|
return &BootstrapOutput{peers}, nil
|
||||||
},
|
},
|
||||||
Type: &BootstrapOutput{},
|
Type: BootstrapOutput{},
|
||||||
Marshalers: cmds.MarshalerMap{
|
Marshalers: cmds.MarshalerMap{
|
||||||
cmds.Text: bootstrapMarshaler,
|
cmds.Text: bootstrapMarshaler,
|
||||||
},
|
},
|
||||||
|
@ -36,7 +36,7 @@ func CommandsCmd(root *cmds.Command) *cmds.Command {
|
|||||||
return &buf, nil
|
return &buf, nil
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Type: &Command{},
|
Type: Command{},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,7 +95,7 @@ Set the value of the 'datastore.path' key:
|
|||||||
return bytes.NewReader(buf), nil
|
return bytes.NewReader(buf), nil
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Type: &ConfigField{},
|
Type: ConfigField{},
|
||||||
Subcommands: map[string]*cmds.Command{
|
Subcommands: map[string]*cmds.Command{
|
||||||
"show": configShowCmd,
|
"show": configShowCmd,
|
||||||
"edit": configEditCmd,
|
"edit": configEditCmd,
|
||||||
|
@ -84,7 +84,7 @@ connected peers and latencies between them.
|
|||||||
|
|
||||||
return &DiagnosticOutput{output}, nil
|
return &DiagnosticOutput{output}, nil
|
||||||
},
|
},
|
||||||
Type: &DiagnosticOutput{},
|
Type: DiagnosticOutput{},
|
||||||
Marshalers: cmds.MarshalerMap{
|
Marshalers: cmds.MarshalerMap{
|
||||||
cmds.Text: func(r cmds.Response) (io.Reader, error) {
|
cmds.Text: func(r cmds.Response) (io.Reader, error) {
|
||||||
output, ok := r.Output().(*DiagnosticOutput)
|
output, ok := r.Output().(*DiagnosticOutput)
|
||||||
|
@ -91,7 +91,7 @@ if no peer is specified, prints out local peers info.
|
|||||||
return bytes.NewReader(marshaled), nil
|
return bytes.NewReader(marshaled), nil
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Type: &IdOutput{},
|
Type: IdOutput{},
|
||||||
}
|
}
|
||||||
|
|
||||||
func printPeer(ps peer.Peerstore, p peer.ID) (interface{}, error) {
|
func printPeer(ps peer.Peerstore, p peer.ID) (interface{}, error) {
|
||||||
|
@ -48,5 +48,5 @@ output of a running daemon.
|
|||||||
Marshalers: cmds.MarshalerMap{
|
Marshalers: cmds.MarshalerMap{
|
||||||
cmds.Text: MessageTextMarshaler,
|
cmds.Text: MessageTextMarshaler,
|
||||||
},
|
},
|
||||||
Type: &MessageOutput{},
|
Type: MessageOutput{},
|
||||||
}
|
}
|
||||||
|
@ -89,7 +89,7 @@ it contains, with the following format:
|
|||||||
return strings.NewReader(s), nil
|
return strings.NewReader(s), nil
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Type: &LsOutput{},
|
Type: LsOutput{},
|
||||||
}
|
}
|
||||||
|
|
||||||
func marshalLinks(links []Link) (s string) {
|
func marshalLinks(links []Link) (s string) {
|
||||||
|
@ -133,7 +133,7 @@ baz
|
|||||||
output.IPNS = nsdir
|
output.IPNS = nsdir
|
||||||
return &output, nil
|
return &output, nil
|
||||||
},
|
},
|
||||||
Type: &config.Mounts{},
|
Type: config.Mounts{},
|
||||||
Marshalers: cmds.MarshalerMap{
|
Marshalers: cmds.MarshalerMap{
|
||||||
cmds.Text: func(res cmds.Response) (io.Reader, error) {
|
cmds.Text: func(res cmds.Response) (io.Reader, error) {
|
||||||
v := res.Output().(*config.Mounts)
|
v := res.Output().(*config.Mounts)
|
||||||
|
@ -108,7 +108,7 @@ multihash.
|
|||||||
return strings.NewReader(marshalled), nil
|
return strings.NewReader(marshalled), nil
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Type: &Object{},
|
Type: Object{},
|
||||||
}
|
}
|
||||||
|
|
||||||
var objectGetCmd = &cmds.Command{
|
var objectGetCmd = &cmds.Command{
|
||||||
@ -162,7 +162,7 @@ This command outputs data in the following encodings:
|
|||||||
|
|
||||||
return node, nil
|
return node, nil
|
||||||
},
|
},
|
||||||
Type: &Node{},
|
Type: Node{},
|
||||||
Marshalers: cmds.MarshalerMap{
|
Marshalers: cmds.MarshalerMap{
|
||||||
cmds.EncodingType("protobuf"): func(res cmds.Response) (io.Reader, error) {
|
cmds.EncodingType("protobuf"): func(res cmds.Response) (io.Reader, error) {
|
||||||
node := res.Output().(*Node)
|
node := res.Output().(*Node)
|
||||||
@ -232,7 +232,7 @@ Data should be in the format specified by <encoding>.
|
|||||||
return strings.NewReader("added " + object.Hash), nil
|
return strings.NewReader("added " + object.Hash), nil
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Type: &Object{},
|
Type: Object{},
|
||||||
}
|
}
|
||||||
|
|
||||||
// objectData takes a key string and writes out the raw bytes of that node (if there is one)
|
// objectData takes a key string and writes out the raw bytes of that node (if there is one)
|
||||||
|
@ -157,7 +157,7 @@ Use --type=<type> to specify the type of pinned keys to list. Valid values are:
|
|||||||
|
|
||||||
return &KeyList{Keys: keys}, nil
|
return &KeyList{Keys: keys}, nil
|
||||||
},
|
},
|
||||||
Type: &KeyList{},
|
Type: KeyList{},
|
||||||
Marshalers: cmds.MarshalerMap{
|
Marshalers: cmds.MarshalerMap{
|
||||||
cmds.Text: KeyListTextMarshaler,
|
cmds.Text: KeyListTextMarshaler,
|
||||||
},
|
},
|
||||||
|
@ -86,7 +86,7 @@ Publish a <ref> to another public key:
|
|||||||
return strings.NewReader(s), nil
|
return strings.NewReader(s), nil
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Type: &IpnsEntry{},
|
Type: IpnsEntry{},
|
||||||
}
|
}
|
||||||
|
|
||||||
func publish(n *core.IpfsNode, k crypto.PrivKey, ref string) (*IpnsEntry, error) {
|
func publish(n *core.IpfsNode, k crypto.PrivKey, ref string) (*IpnsEntry, error) {
|
||||||
|
@ -71,7 +71,7 @@ Note: list all refs recursively with -r.
|
|||||||
|
|
||||||
return getRefs(n, req.Arguments(), unique, recursive)
|
return getRefs(n, req.Arguments(), unique, recursive)
|
||||||
},
|
},
|
||||||
Type: &KeyList{},
|
Type: KeyList{},
|
||||||
Marshalers: cmds.MarshalerMap{
|
Marshalers: cmds.MarshalerMap{
|
||||||
cmds.Text: KeyListTextMarshaler,
|
cmds.Text: KeyListTextMarshaler,
|
||||||
},
|
},
|
||||||
|
@ -69,7 +69,7 @@ ipfs swarm peers lists the set of peers this node is connected to.
|
|||||||
Marshalers: cmds.MarshalerMap{
|
Marshalers: cmds.MarshalerMap{
|
||||||
cmds.Text: stringListMarshaler,
|
cmds.Text: stringListMarshaler,
|
||||||
},
|
},
|
||||||
Type: &stringList{},
|
Type: stringList{},
|
||||||
}
|
}
|
||||||
|
|
||||||
var swarmConnectCmd = &cmds.Command{
|
var swarmConnectCmd = &cmds.Command{
|
||||||
@ -122,7 +122,7 @@ ipfs swarm connect /ip4/104.131.131.82/tcp/4001/QmaCpDMGvV2BGHeYERUEnRQAwe3N8Szb
|
|||||||
Marshalers: cmds.MarshalerMap{
|
Marshalers: cmds.MarshalerMap{
|
||||||
cmds.Text: stringListMarshaler,
|
cmds.Text: stringListMarshaler,
|
||||||
},
|
},
|
||||||
Type: &stringList{},
|
Type: stringList{},
|
||||||
}
|
}
|
||||||
|
|
||||||
func stringListMarshaler(res cmds.Response) (io.Reader, error) {
|
func stringListMarshaler(res cmds.Response) (io.Reader, error) {
|
||||||
|
@ -29,7 +29,7 @@ var UpdateCmd = &cmds.Command{
|
|||||||
}
|
}
|
||||||
return updateApply(n)
|
return updateApply(n)
|
||||||
},
|
},
|
||||||
Type: &UpdateOutput{},
|
Type: UpdateOutput{},
|
||||||
Subcommands: map[string]*cmds.Command{
|
Subcommands: map[string]*cmds.Command{
|
||||||
"check": UpdateCheckCmd,
|
"check": UpdateCheckCmd,
|
||||||
"log": UpdateLogCmd,
|
"log": UpdateLogCmd,
|
||||||
@ -62,7 +62,7 @@ var UpdateCheckCmd = &cmds.Command{
|
|||||||
}
|
}
|
||||||
return updateCheck(n)
|
return updateCheck(n)
|
||||||
},
|
},
|
||||||
Type: &UpdateOutput{},
|
Type: UpdateOutput{},
|
||||||
Marshalers: cmds.MarshalerMap{
|
Marshalers: cmds.MarshalerMap{
|
||||||
cmds.Text: func(res cmds.Response) (io.Reader, error) {
|
cmds.Text: func(res cmds.Response) (io.Reader, error) {
|
||||||
v := res.Output().(*UpdateOutput)
|
v := res.Output().(*UpdateOutput)
|
||||||
|
@ -41,5 +41,5 @@ var VersionCmd = &cmds.Command{
|
|||||||
return strings.NewReader(fmt.Sprintf("ipfs version %s\n", v.Version)), nil
|
return strings.NewReader(fmt.Sprintf("ipfs version %s\n", v.Version)), nil
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Type: &VersionOutput{},
|
Type: VersionOutput{},
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user