Commit 465cce99 authored by Brian Tiger Chow's avatar Brian Tiger Chow Committed by Juan Batiz-Benet

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.
parent 78b5fbff
package commands
import (
"io"
"github.com/jbenet/go-ipfs/core"
u "github.com/jbenet/go-ipfs/util"
)
var log = u.Logger("commands")
type CmdFunc func(*core.IpfsNode, []string, map[string]interface{}, io.Writer) error
package commands
import (
"encoding/json"
"errors"
"fmt"
"io"
"time"
"github.com/jbenet/go-ipfs/core"
diagn "github.com/jbenet/go-ipfs/diagnostics"
)
func PrintDiagnostics(info []*diagn.DiagInfo, out io.Writer) {
for _, i := range info {
fmt.Fprintf(out, "Peer: %s\n", i.ID)
fmt.Fprintf(out, "\tUp for: %s\n", i.LifeSpan.String())
fmt.Fprintf(out, "\tConnected To:\n")
for _, c := range i.Connections {
fmt.Fprintf(out, "\t%s\n\t\tLatency = %s\n", c.ID, c.Latency.String())
}
fmt.Fprintln(out)
}
}
func Diag(n *core.IpfsNode, args []string, opts map[string]interface{}, out io.Writer) error {
if n.Diagnostics == nil {
return errors.New("Cannot run diagnostic in offline mode!")
}
info, err := n.Diagnostics.GetDiagnostic(time.Second * 20)
if err != nil {
return err
}
raw, ok := opts["raw"].(bool)
if !ok {
return errors.New("incorrect value to parameter 'raw'")
}
if raw {
enc := json.NewEncoder(out)
err = enc.Encode(info)
if err != nil {
return err
}
} else {
PrintDiagnostics(info, out)
}
return nil
}
package commands
import (
"io"
"github.com/jbenet/go-ipfs/core"
u "github.com/jbenet/go-ipfs/util"
)
// Log changes the log level of a subsystem
func Log(n *core.IpfsNode, args []string, opts map[string]interface{}, out io.Writer) error {
if err := u.SetLogLevel(args[0], args[1]); err != nil {
return err
}
log.Info("Changed LogLevel of %q to %q", args[0], args[1])
return nil
}
package commands
import (
"fmt"
"io"
"github.com/jbenet/go-ipfs/core"
)
func Ls(n *core.IpfsNode, args []string, opts map[string]interface{}, out io.Writer) error {
for _, fn := range args {
dagnode, err := n.Resolver.ResolvePath(fn)
if err != nil {
return fmt.Errorf("ls error: %v", err)
}
for _, link := range dagnode.Links {
fmt.Fprintf(out, "%s %d %s\n", link.Hash.B58String(), link.Size, link.Name)
}
}
return nil
}
package commands
import (
"fmt"
"io"
"github.com/jbenet/go-ipfs/core"
)
func Pin(n *core.IpfsNode, args []string, opts map[string]interface{}, out io.Writer) error {
// set recursive flag
recursive, _ := opts["r"].(bool) // false if cast fails.
// if recursive, set depth flag
depth := 1 // default (non recursive)
if d, ok := opts["d"].(int); recursive && ok {
depth = d
}
if depth < -1 {
return fmt.Errorf("ipfs pin: called with invalid depth: %v", depth)
}
fmt.Printf("recursive, depth: %v, %v\n", recursive, depth)
for _, fn := range args {
dagnode, err := n.Resolver.ResolvePath(fn)
if err != nil {
return fmt.Errorf("pin error: %v", err)
}
err = n.Pinning.Pin(dagnode, recursive)
if err != nil {
return fmt.Errorf("pin: %v", err)
}
}
return n.Pinning.Flush()
}
func Unpin(n *core.IpfsNode, args []string, opts map[string]interface{}, out io.Writer) error {
// set recursive flag
recursive, _ := opts["r"].(bool) // false if cast fails.
for _, fn := range args {
dagnode, err := n.Resolver.ResolvePath(fn)
if err != nil {
return fmt.Errorf("pin error: %v", err)
}
k, _ := dagnode.Key()
err = n.Pinning.Unpin(k, recursive)
if err != nil {
return fmt.Errorf("pin: %v", err)
}
}
return n.Pinning.Flush()
}
package commands
import (
"errors"
"fmt"
"io"
"github.com/jbenet/go-ipfs/core"
u "github.com/jbenet/go-ipfs/util"
nsys "github.com/jbenet/go-ipfs/namesys"
)
func Publish(n *core.IpfsNode, args []string, opts map[string]interface{}, out io.Writer) error {
log.Debug("Begin Publish")
if n.Identity == nil {
return errors.New("Identity not loaded!")
}
// name := ""
ref := ""
switch len(args) {
case 2:
// name = args[0]
ref = args[1]
return errors.New("keychains not yet implemented")
case 1:
// name = n.Identity.ID.String()
ref = args[0]
default:
return fmt.Errorf("Publish expects 1 or 2 args; got %d.", len(args))
}
// later, n.Keychain.Get(name).PrivKey
k := n.Identity.PrivKey()
pub := nsys.NewRoutingPublisher(n.Routing)
err := pub.Publish(k, ref)
if err != nil {
return err
}
hash, err := k.GetPublic().Hash()
if err != nil {
return err
}
fmt.Fprintf(out, "published name %s to %s\n", u.Key(hash), ref)
return nil
}
package commands
import (
"io"
mh "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multihash"
"github.com/jbenet/go-ipfs/core"
mdag "github.com/jbenet/go-ipfs/merkledag"
u "github.com/jbenet/go-ipfs/util"
)
func Refs(n *core.IpfsNode, args []string, opts map[string]interface{}, out io.Writer) error {
unique, ok := opts["u"].(bool)
if !ok {
unique = false
}
recursive, ok := opts["r"].(bool)
if !ok {
recursive = false
}
var refsSeen map[u.Key]bool
if unique {
refsSeen = make(map[u.Key]bool)
}
for _, fn := range args {
nd, err := n.Resolver.ResolvePath(fn)
if err != nil {
return err
}
printRefs(n, nd, refsSeen, recursive)
}
return nil
}
func printRefs(n *core.IpfsNode, nd *mdag.Node, refSeen map[u.Key]bool, recursive bool) {
for _, link := range nd.Links {
printRef(link.Hash, refSeen)
if recursive {
nd, err := n.DAG.Get(u.Key(link.Hash))
if err != nil {
log.Errorf("error: cannot retrieve %s (%s)", link.Hash.B58String(), err)
return
}
printRefs(n, nd, refSeen, recursive)
}
}
}
func printRef(h mh.Multihash, refsSeen map[u.Key]bool) {
if refsSeen != nil {
_, found := refsSeen[u.Key(h)]
if found {
return
}
refsSeen[u.Key(h)] = true
}
u.POut("%s\n", h.B58String())
}
package commands
import (
"errors"
"fmt"
"io"
"github.com/jbenet/go-ipfs/core"
)
func Resolve(n *core.IpfsNode, args []string, opts map[string]interface{}, out io.Writer) error {
name := ""
switch len(args) {
case 1:
name = args[0]
case 0:
if n.Identity == nil {
return errors.New("Identity not loaded!")
}
name = n.Identity.ID().String()
default:
return fmt.Errorf("Publish expects 1 or 2 args; got %d.", len(args))
}
res, err := n.Namesys.Resolve(name)
if err != nil {
return err
}
fmt.Fprintf(out, "%s\n", res)
return nil
}
package commands
import (
"errors"
"fmt"
"io"
"os"
"github.com/jbenet/go-ipfs/core"
"github.com/jbenet/go-ipfs/updates"
)
// UpdateApply applys an update of the ipfs binary and shuts down the node if successful
func UpdateApply(n *core.IpfsNode, args []string, opts map[string]interface{}, out io.Writer) error {
fmt.Fprintln(out, "Current Version:", updates.Version)
u, err := updates.CheckForUpdate()
if err != nil {
return err
}
if u == nil {
fmt.Fprintln(out, "No update available")
return nil
}
fmt.Fprintln(out, "New Version:", u.Version)
_, onDaemon := opts["onDaemon"]
force := opts["force"].(bool)
if onDaemon && !force {
return fmt.Errorf(`Error: update must stop running ipfs service.
You may want to abort the update, or shut the service down manually.
To shut it down automatically, run:
ipfs update --force
`)
}
if err = updates.Apply(u); err != nil {
fmt.Fprint(out, err.Error())
return fmt.Errorf("Couldn't apply update: %v", err)
}
fmt.Fprintln(out, "Updated applied!")
if onDaemon {
if force {
fmt.Fprintln(out, "Shutting down ipfs service.")
os.Exit(1) // is there a cleaner shutdown routine?
} else {
fmt.Fprintln(out, "You can now restart the ipfs service.")
}
}
return nil
}
// UpdateCheck checks wether there is an update available
func UpdateCheck(n *core.IpfsNode, args []string, opts map[string]interface{}, out io.Writer) error {
fmt.Fprintln(out, "Current Version:", updates.Version)
u, err := updates.CheckForUpdate()
if err != nil {
return err
}
if u == nil {
fmt.Fprintln(out, "No update available")
return nil
}
fmt.Fprintln(out, "New Version:", u.Version)
return nil
}
// UpdateLog lists the version available online
func UpdateLog(n *core.IpfsNode, args []string, opts map[string]interface{}, out io.Writer) error {
return errors.New("Not yet implemented")
}
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