Commit 08bb6f14 authored by Henry's avatar Henry

templates for block commands (updates #138)

parent 8ede8985
package main
import (
flag "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/gonuts/flag"
commander "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/commander"
"github.com/jbenet/go-ipfs/core/commands"
)
var cmdIpfsBlock = &commander.Command{
UsageLine: "block",
Short: "get/put **raw** ipfs blocks",
Long: `ipfs block (get|put) - get/put **raw** ipfs blocks.
ipfs block get <key> > valfile - get block of <key> and write it to valfile
ipfs block put <key> < valfile - pipe valfile to block <key>
Examples:
Get the value of the 'datastore.path' key:
ipfs config datastore.path
Set the value of the 'datastore.path' key:
ipfs config datastore.path ~/.go-ipfs/datastore
`,
// Run: blockGetCmd,
Subcommands: []*commander.Command{
cmdIpfsBlockGet,
cmdIpfsBlockPut,
},
Flag: *flag.NewFlagSet("ipfs-block", flag.ExitOnError),
}
var cmdIpfsBlockGet = &commander.Command{
UsageLine: "get",
Short: "get a row ipfs block",
Run: makeCommand(command{
name: "get",
args: 1,
flags: nil,
online: true,
cmdFn: commands.BlockGet,
}),
}
var cmdIpfsBlockPut = &commander.Command{
UsageLine: "put",
Short: "put a row ipfs block",
Run: makeCommand(command{
name: "put",
args: 1,
flags: nil,
online: true,
cmdFn: commands.BlockPut,
}),
}
......@@ -62,6 +62,7 @@ Use "ipfs help <command>" for more information about a command.
cmdIpfsName,
cmdIpfsBootstrap,
cmdIpfsDiag,
cmdIpfsBlock,
},
Flag: *flag.NewFlagSet("ipfs", flag.ExitOnError),
}
......
package commands
import (
"io"
"io/ioutil"
"os"
"github.com/jbenet/go-ipfs/blocks"
"github.com/jbenet/go-ipfs/core"
u "github.com/jbenet/go-ipfs/util"
)
func BlockGet(n *core.IpfsNode, args []string, opts map[string]interface{}, out io.Writer) error {
k := u.Key(args[0])
u.PErr("Getting block[%s]\n", k)
b, err := n.Blocks.GetBlock(k)
if err != nil {
return err
}
out.Write(b.Data)
return nil
}
func BlockPut(n *core.IpfsNode, args []string, opts map[string]interface{}, out io.Writer) error {
data, err := ioutil.ReadAll(os.Stdin)
if err != nil {
return err
}
b := blocks.NewBlock(data)
u.PErr("Putting block[%s]\n", b.Key())
key, err := n.Blocks.AddBlock(b)
if err != nil {
return err
}
u.PErr("Done. Key: %s\n", key)
return nil
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment