@cryptotaxi247 / kubo / commits / e91b2b8ae

use makeCommand for publish + resolve

Juan Batiz-Benet committed Oct 2, 2014 at 02:50 UTC e91b2b8aeccea78470dc19f0a8fbd19799dd7a55
2 files changed +14 -71
cmd/ipfs/publish.go
+7 -36
@@ -1,13 +1,9 @@
1 package main
2
3 import (
4 - "os"
5 -
4 "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/gonuts/flag"
5 "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/commander"
6 "github.com/jbenet/go-ipfs/core/commands"
9 - "github.com/jbenet/go-ipfs/daemon"
10 - u "github.com/jbenet/go-ipfs/util"
7 )
8
9 var cmdIpfsPub = &commander.Command{
@@ -24,35 +20,10 @@ func init() {
20 cmdIpfsPub.Flag.String("k", "", "Specify key to use for publishing.")
21 }
22
27 -func pubCmd(c *commander.Command, inp []string) error {
28 - if len(inp) < 1 {
29 - u.POut(c.Long)
30 - return nil
31 - }
32 -
33 - conf, err := getConfigDir(c.Parent)
34 - if err != nil {
35 - return err
36 - }
37 -
38 - cmd := daemon.NewCommand()
39 - cmd.Command = "publish"
40 - cmd.Args = inp
41 - cmd.Opts["k"] = c.Flag.Lookup("k").Value.Get()
42 - err = daemon.SendCommand(cmd, conf)
43 - if err != nil {
44 - u.DOut("Executing command locally.\n")
45 - // Do locally
46 - conf, err := getConfigDir(c.Parent)
47 - if err != nil {
48 - return err
49 - }
50 - n, err := localNode(conf, true)
51 - if err != nil {
52 - return err
53 - }
54 -
55 - return commands.Publish(n, cmd.Args, cmd.Opts, os.Stdout)
56 - }
57 - return nil
58 -}
23 +var pubCmd = makeCommand(command{
24 + name: "publish",
25 + args: 1,
26 + flags: []string{"k"},
27 + online: true,
28 + cmdFn: commands.Publish,
29 +})
cmd/ipfs/resolve.go
+7 -35
@@ -1,15 +1,9 @@
1 package main
2
3 import (
4 - "fmt"
5 - "os"
6 - "time"
7 -
4 "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/gonuts/flag"
5 "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/commander"
6 "github.com/jbenet/go-ipfs/core/commands"
11 - "github.com/jbenet/go-ipfs/daemon"
12 - u "github.com/jbenet/go-ipfs/util"
7 )
8
9 var cmdIpfsResolve = &commander.Command{
@@ -22,32 +16,10 @@ var cmdIpfsResolve = &commander.Command{
16 Flag: *flag.NewFlagSet("ipfs-resolve", flag.ExitOnError),
17 }
18
25 -func resolveCmd(c *commander.Command, inp []string) error {
26 - if len(inp) < 1 {
27 - u.POut(c.Long)
28 - return nil
29 - }
30 - conf, err := getConfigDir(c.Parent)
31 - if err != nil {
32 - return err
33 - }
34 -
35 - cmd := daemon.NewCommand()
36 - cmd.Command = "resolve"
37 - cmd.Args = inp
38 - err = daemon.SendCommand(cmd, conf)
39 - if err != nil {
40 - now := time.Now()
41 - // Resolve requires working DHT
42 - n, err := localNode(conf, true)
43 - if err != nil {
44 - return err
45 - }
46 -
47 - took := time.Now().Sub(now)
48 - fmt.Printf("localNode creation took %s\n", took.String())
49 -
50 - return commands.Resolve(n, cmd.Args, cmd.Opts, os.Stdout)
51 - }
52 - return nil
53 -}
19 +var resolveCmd = makeCommand(command{
20 + name: "resolve",
21 + args: 1,
22 + flags: nil,
23 + online: true,
24 + cmdFn: commands.Resolve,
25 +})