mirror of
https://github.com/ipfs/kubo.git
synced 2025-10-13 01:37:02 +08:00
use makeCommand for publish + resolve
This commit is contained in:
@ -1,13 +1,9 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
|
||||||
|
|
||||||
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/gonuts/flag"
|
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/gonuts/flag"
|
||||||
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/commander"
|
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/commander"
|
||||||
"github.com/jbenet/go-ipfs/core/commands"
|
"github.com/jbenet/go-ipfs/core/commands"
|
||||||
"github.com/jbenet/go-ipfs/daemon"
|
|
||||||
u "github.com/jbenet/go-ipfs/util"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var cmdIpfsPub = &commander.Command{
|
var cmdIpfsPub = &commander.Command{
|
||||||
@ -24,35 +20,10 @@ func init() {
|
|||||||
cmdIpfsPub.Flag.String("k", "", "Specify key to use for publishing.")
|
cmdIpfsPub.Flag.String("k", "", "Specify key to use for publishing.")
|
||||||
}
|
}
|
||||||
|
|
||||||
func pubCmd(c *commander.Command, inp []string) error {
|
var pubCmd = makeCommand(command{
|
||||||
if len(inp) < 1 {
|
name: "publish",
|
||||||
u.POut(c.Long)
|
args: 1,
|
||||||
return nil
|
flags: []string{"k"},
|
||||||
}
|
online: true,
|
||||||
|
cmdFn: commands.Publish,
|
||||||
conf, err := getConfigDir(c.Parent)
|
})
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
cmd := daemon.NewCommand()
|
|
||||||
cmd.Command = "publish"
|
|
||||||
cmd.Args = inp
|
|
||||||
cmd.Opts["k"] = c.Flag.Lookup("k").Value.Get()
|
|
||||||
err = daemon.SendCommand(cmd, conf)
|
|
||||||
if err != nil {
|
|
||||||
u.DOut("Executing command locally.\n")
|
|
||||||
// Do locally
|
|
||||||
conf, err := getConfigDir(c.Parent)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
n, err := localNode(conf, true)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return commands.Publish(n, cmd.Args, cmd.Opts, os.Stdout)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
@ -1,15 +1,9 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/gonuts/flag"
|
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/gonuts/flag"
|
||||||
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/commander"
|
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/commander"
|
||||||
"github.com/jbenet/go-ipfs/core/commands"
|
"github.com/jbenet/go-ipfs/core/commands"
|
||||||
"github.com/jbenet/go-ipfs/daemon"
|
|
||||||
u "github.com/jbenet/go-ipfs/util"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var cmdIpfsResolve = &commander.Command{
|
var cmdIpfsResolve = &commander.Command{
|
||||||
@ -22,32 +16,10 @@ var cmdIpfsResolve = &commander.Command{
|
|||||||
Flag: *flag.NewFlagSet("ipfs-resolve", flag.ExitOnError),
|
Flag: *flag.NewFlagSet("ipfs-resolve", flag.ExitOnError),
|
||||||
}
|
}
|
||||||
|
|
||||||
func resolveCmd(c *commander.Command, inp []string) error {
|
var resolveCmd = makeCommand(command{
|
||||||
if len(inp) < 1 {
|
name: "resolve",
|
||||||
u.POut(c.Long)
|
args: 1,
|
||||||
return nil
|
flags: nil,
|
||||||
}
|
online: true,
|
||||||
conf, err := getConfigDir(c.Parent)
|
cmdFn: commands.Resolve,
|
||||||
if err != nil {
|
})
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
cmd := daemon.NewCommand()
|
|
||||||
cmd.Command = "resolve"
|
|
||||||
cmd.Args = inp
|
|
||||||
err = daemon.SendCommand(cmd, conf)
|
|
||||||
if err != nil {
|
|
||||||
now := time.Now()
|
|
||||||
// Resolve requires working DHT
|
|
||||||
n, err := localNode(conf, true)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
took := time.Now().Sub(now)
|
|
||||||
fmt.Printf("localNode creation took %s\n", took.String())
|
|
||||||
|
|
||||||
return commands.Resolve(n, cmd.Args, cmd.Opts, os.Stdout)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
Reference in New Issue
Block a user