@cryptotaxi247 / kubo / commits / 465cce995

remove duplicate files

these weren't actually modified when commands2 was introduced. they're exact replicas of the ones that presently exist in core/commands.

Brian Tiger Chow committed Oct 29, 2014 at 00:19 UTC 465cce9950a8406208919466a9256aede5b563c5
9 files changed -388
core/commands2/commands.go deleted
-12
@@ -1,12 +0,0 @@
1 -package commands
2 -
3 -import (
4 - "io"
5 -
6 - "github.com/jbenet/go-ipfs/core"
7 - u "github.com/jbenet/go-ipfs/util"
8 -)
9 -
10 -var log = u.Logger("commands")
11 -
12 -type CmdFunc func(*core.IpfsNode, []string, map[string]interface{}, io.Writer) error
core/commands2/diag.go deleted
-49
@@ -1,49 +0,0 @@
1 -package commands
2 -
3 -import (
4 - "encoding/json"
5 - "errors"
6 - "fmt"
7 - "io"
8 - "time"
9 -
10 - "github.com/jbenet/go-ipfs/core"
11 - diagn "github.com/jbenet/go-ipfs/diagnostics"
12 -)
13 -
14 -func PrintDiagnostics(info []*diagn.DiagInfo, out io.Writer) {
15 - for _, i := range info {
16 - fmt.Fprintf(out, "Peer: %s\n", i.ID)
17 - fmt.Fprintf(out, "\tUp for: %s\n", i.LifeSpan.String())
18 - fmt.Fprintf(out, "\tConnected To:\n")
19 - for _, c := range i.Connections {
20 - fmt.Fprintf(out, "\t%s\n\t\tLatency = %s\n", c.ID, c.Latency.String())
21 - }
22 - fmt.Fprintln(out)
23 - }
24 -
25 -}
26 -
27 -func Diag(n *core.IpfsNode, args []string, opts map[string]interface{}, out io.Writer) error {
28 - if n.Diagnostics == nil {
29 - return errors.New("Cannot run diagnostic in offline mode!")
30 - }
31 - info, err := n.Diagnostics.GetDiagnostic(time.Second * 20)
32 - if err != nil {
33 - return err
34 - }
35 - raw, ok := opts["raw"].(bool)
36 - if !ok {
37 - return errors.New("incorrect value to parameter 'raw'")
38 - }
39 - if raw {
40 - enc := json.NewEncoder(out)
41 - err = enc.Encode(info)
42 - if err != nil {
43 - return err
44 - }
45 - } else {
46 - PrintDiagnostics(info, out)
47 - }
48 - return nil
49 -}
core/commands2/log.go deleted
-18
@@ -1,18 +0,0 @@
1 -package commands
2 -
3 -import (
4 - "io"
5 -
6 - "github.com/jbenet/go-ipfs/core"
7 - u "github.com/jbenet/go-ipfs/util"
8 -)
9 -
10 -// Log changes the log level of a subsystem
11 -func Log(n *core.IpfsNode, args []string, opts map[string]interface{}, out io.Writer) error {
12 - if err := u.SetLogLevel(args[0], args[1]); err != nil {
13 - return err
14 - }
15 -
16 - log.Info("Changed LogLevel of %q to %q", args[0], args[1])
17 - return nil
18 -}
core/commands2/ls.go deleted
-22
@@ -1,22 +0,0 @@
1 -package commands
2 -
3 -import (
4 - "fmt"
5 - "io"
6 -
7 - "github.com/jbenet/go-ipfs/core"
8 -)
9 -
10 -func Ls(n *core.IpfsNode, args []string, opts map[string]interface{}, out io.Writer) error {
11 - for _, fn := range args {
12 - dagnode, err := n.Resolver.ResolvePath(fn)
13 - if err != nil {
14 - return fmt.Errorf("ls error: %v", err)
15 - }
16 -
17 - for _, link := range dagnode.Links {
18 - fmt.Fprintf(out, "%s %d %s\n", link.Hash.B58String(), link.Size, link.Name)
19 - }
20 - }
21 - return nil
22 -}
core/commands2/pin.go deleted
-58
@@ -1,58 +0,0 @@
1 -package commands
2 -
3 -import (
4 - "fmt"
5 - "io"
6 -
7 - "github.com/jbenet/go-ipfs/core"
8 -)
9 -
10 -func Pin(n *core.IpfsNode, args []string, opts map[string]interface{}, out io.Writer) error {
11 -
12 - // set recursive flag
13 - recursive, _ := opts["r"].(bool) // false if cast fails.
14 -
15 - // if recursive, set depth flag
16 - depth := 1 // default (non recursive)
17 - if d, ok := opts["d"].(int); recursive && ok {
18 - depth = d
19 - }
20 - if depth < -1 {
21 - return fmt.Errorf("ipfs pin: called with invalid depth: %v", depth)
22 - }
23 -
24 - fmt.Printf("recursive, depth: %v, %v\n", recursive, depth)
25 -
26 - for _, fn := range args {
27 - dagnode, err := n.Resolver.ResolvePath(fn)
28 - if err != nil {
29 - return fmt.Errorf("pin error: %v", err)
30 - }
31 -
32 - err = n.Pinning.Pin(dagnode, recursive)
33 - if err != nil {
34 - return fmt.Errorf("pin: %v", err)
35 - }
36 - }
37 - return n.Pinning.Flush()
38 -}
39 -
40 -func Unpin(n *core.IpfsNode, args []string, opts map[string]interface{}, out io.Writer) error {
41 -
42 - // set recursive flag
43 - recursive, _ := opts["r"].(bool) // false if cast fails.
44 -
45 - for _, fn := range args {
46 - dagnode, err := n.Resolver.ResolvePath(fn)
47 - if err != nil {
48 - return fmt.Errorf("pin error: %v", err)
49 - }
50 -
51 - k, _ := dagnode.Key()
52 - err = n.Pinning.Unpin(k, recursive)
53 - if err != nil {
54 - return fmt.Errorf("pin: %v", err)
55 - }
56 - }
57 - return n.Pinning.Flush()
58 -}
core/commands2/publish.go deleted
-53
@@ -1,53 +0,0 @@
1 -package commands
2 -
3 -import (
4 - "errors"
5 - "fmt"
6 - "io"
7 -
8 - "github.com/jbenet/go-ipfs/core"
9 - u "github.com/jbenet/go-ipfs/util"
10 -
11 - nsys "github.com/jbenet/go-ipfs/namesys"
12 -)
13 -
14 -func Publish(n *core.IpfsNode, args []string, opts map[string]interface{}, out io.Writer) error {
15 - log.Debug("Begin Publish")
16 -
17 - if n.Identity == nil {
18 - return errors.New("Identity not loaded!")
19 - }
20 -
21 - // name := ""
22 - ref := ""
23 -
24 - switch len(args) {
25 - case 2:
26 - // name = args[0]
27 - ref = args[1]
28 - return errors.New("keychains not yet implemented")
29 - case 1:
30 - // name = n.Identity.ID.String()
31 - ref = args[0]
32 -
33 - default:
34 - return fmt.Errorf("Publish expects 1 or 2 args; got %d.", len(args))
35 - }
36 -
37 - // later, n.Keychain.Get(name).PrivKey
38 - k := n.Identity.PrivKey()
39 -
40 - pub := nsys.NewRoutingPublisher(n.Routing)
41 - err := pub.Publish(k, ref)
42 - if err != nil {
43 - return err
44 - }
45 -
46 - hash, err := k.GetPublic().Hash()
47 - if err != nil {
48 - return err
49 - }
50 - fmt.Fprintf(out, "published name %s to %s\n", u.Key(hash), ref)
51 -
52 - return nil
53 -}
core/commands2/refs.go deleted
-65
@@ -1,65 +0,0 @@
1 -package commands
2 -
3 -import (
4 - "io"
5 -
6 - mh "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multihash"
7 - "github.com/jbenet/go-ipfs/core"
8 - mdag "github.com/jbenet/go-ipfs/merkledag"
9 - u "github.com/jbenet/go-ipfs/util"
10 -)
11 -
12 -func Refs(n *core.IpfsNode, args []string, opts map[string]interface{}, out io.Writer) error {
13 - unique, ok := opts["u"].(bool)
14 - if !ok {
15 - unique = false
16 - }
17 -
18 - recursive, ok := opts["r"].(bool)
19 - if !ok {
20 - recursive = false
21 - }
22 -
23 - var refsSeen map[u.Key]bool
24 - if unique {
25 - refsSeen = make(map[u.Key]bool)
26 - }
27 -
28 - for _, fn := range args {
29 - nd, err := n.Resolver.ResolvePath(fn)
30 - if err != nil {
31 - return err
32 - }
33 -
34 - printRefs(n, nd, refsSeen, recursive)
35 - }
36 - return nil
37 -}
38 -
39 -func printRefs(n *core.IpfsNode, nd *mdag.Node, refSeen map[u.Key]bool, recursive bool) {
40 - for _, link := range nd.Links {
41 - printRef(link.Hash, refSeen)
42 -
43 - if recursive {
44 - nd, err := n.DAG.Get(u.Key(link.Hash))
45 - if err != nil {
46 - log.Errorf("error: cannot retrieve %s (%s)", link.Hash.B58String(), err)
47 - return
48 - }
49 -
50 - printRefs(n, nd, refSeen, recursive)
51 - }
52 - }
53 -}
54 -
55 -func printRef(h mh.Multihash, refsSeen map[u.Key]bool) {
56 - if refsSeen != nil {
57 - _, found := refsSeen[u.Key(h)]
58 - if found {
59 - return
60 - }
61 - refsSeen[u.Key(h)] = true
62 - }
63 -
64 - u.POut("%s\n", h.B58String())
65 -}
core/commands2/resolve.go deleted
-35
@@ -1,35 +0,0 @@
1 -package commands
2 -
3 -import (
4 - "errors"
5 - "fmt"
6 - "io"
7 -
8 - "github.com/jbenet/go-ipfs/core"
9 -)
10 -
11 -func Resolve(n *core.IpfsNode, args []string, opts map[string]interface{}, out io.Writer) error {
12 -
13 - name := ""
14 -
15 - switch len(args) {
16 - case 1:
17 - name = args[0]
18 - case 0:
19 - if n.Identity == nil {
20 - return errors.New("Identity not loaded!")
21 - }
22 - name = n.Identity.ID().String()
23 -
24 - default:
25 - return fmt.Errorf("Publish expects 1 or 2 args; got %d.", len(args))
26 - }
27 -
28 - res, err := n.Namesys.Resolve(name)
29 - if err != nil {
30 - return err
31 - }
32 -
33 - fmt.Fprintf(out, "%s\n", res)
34 - return nil
35 -}
core/commands2/update.go deleted
-76
@@ -1,76 +0,0 @@
1 -package commands
2 -
3 -import (
4 - "errors"
5 - "fmt"
6 - "io"
7 - "os"
8 -
9 - "github.com/jbenet/go-ipfs/core"
10 - "github.com/jbenet/go-ipfs/updates"
11 -)
12 -
13 -// UpdateApply applys an update of the ipfs binary and shuts down the node if successful
14 -func UpdateApply(n *core.IpfsNode, args []string, opts map[string]interface{}, out io.Writer) error {
15 - fmt.Fprintln(out, "Current Version:", updates.Version)
16 - u, err := updates.CheckForUpdate()
17 - if err != nil {
18 - return err
19 - }
20 -
21 - if u == nil {
22 - fmt.Fprintln(out, "No update available")
23 - return nil
24 - }
25 - fmt.Fprintln(out, "New Version:", u.Version)
26 -
27 - _, onDaemon := opts["onDaemon"]
28 - force := opts["force"].(bool)
29 - if onDaemon && !force {
30 - return fmt.Errorf(`Error: update must stop running ipfs service.
31 -You may want to abort the update, or shut the service down manually.
32 -To shut it down automatically, run:
33 -
34 - ipfs update --force
35 -`)
36 - }
37 -
38 - if err = updates.Apply(u); err != nil {
39 - fmt.Fprint(out, err.Error())
40 - return fmt.Errorf("Couldn't apply update: %v", err)
41 - }
42 -
43 - fmt.Fprintln(out, "Updated applied!")
44 - if onDaemon {
45 - if force {
46 - fmt.Fprintln(out, "Shutting down ipfs service.")
47 - os.Exit(1) // is there a cleaner shutdown routine?
48 - } else {
49 - fmt.Fprintln(out, "You can now restart the ipfs service.")
50 - }
51 - }
52 -
53 - return nil
54 -}
55 -
56 -// UpdateCheck checks wether there is an update available
57 -func UpdateCheck(n *core.IpfsNode, args []string, opts map[string]interface{}, out io.Writer) error {
58 - fmt.Fprintln(out, "Current Version:", updates.Version)
59 - u, err := updates.CheckForUpdate()
60 - if err != nil {
61 - return err
62 - }
63 -
64 - if u == nil {
65 - fmt.Fprintln(out, "No update available")
66 - return nil
67 - }
68 -
69 - fmt.Fprintln(out, "New Version:", u.Version)
70 - return nil
71 -}
72 -
73 -// UpdateLog lists the version available online
74 -func UpdateLog(n *core.IpfsNode, args []string, opts map[string]interface{}, out io.Writer) error {
75 - return errors.New("Not yet implemented")
76 -}