mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-25 04:17:44 +08:00
start adopting cmds3.0 - lots of errors!
- move go-ipfs-cmds/legacy to go-ipfs/commands/legacy - update cmds,cmdkit; go test ./... ok License: MIT Signed-off-by: keks <keks@cryptoscope.co>
This commit is contained in:
parent
2140aa9578
commit
bd9576fa57
@ -13,17 +13,17 @@ import (
|
||||
|
||||
utilmain "github.com/ipfs/go-ipfs/cmd/ipfs/util"
|
||||
"github.com/ipfs/go-ipfs/core"
|
||||
commands "github.com/ipfs/go-ipfs/core/commands"
|
||||
oldcmds "github.com/ipfs/go-ipfs/core/commands"
|
||||
corehttp "github.com/ipfs/go-ipfs/core/corehttp"
|
||||
corerepo "github.com/ipfs/go-ipfs/core/corerepo"
|
||||
nodeMount "github.com/ipfs/go-ipfs/fuse/node"
|
||||
fsrepo "github.com/ipfs/go-ipfs/repo/fsrepo"
|
||||
migrate "github.com/ipfs/go-ipfs/repo/fsrepo/migrations"
|
||||
|
||||
cmds "gx/ipfs/QmP9vZfc5WSjfGTXmwX2EcicMFzmZ6fXn7HTdKYat6ccmH/go-ipfs-cmds"
|
||||
"gx/ipfs/QmQp2a2Hhb7F6eK2A5hN8f9aJy4mtkEikL9Zj4cgB7d1dD/go-ipfs-cmdkit"
|
||||
"gx/ipfs/QmSGL5Uoa6gKHgBBwQG8u1CWKUC8ZnwaZiLgFVTFBR2bxr/go-multiaddr-net"
|
||||
mprome "gx/ipfs/QmSk46nSD78YiuNojYMS8NW6hSCjH95JajqqzzoychZgef/go-metrics-prometheus"
|
||||
cmds "gx/ipfs/QmTwKPLyeRKuDawuy6CAn1kRj1FVoqBEM8sviAUWN7NW9K/go-ipfs-cmds"
|
||||
"gx/ipfs/QmVD1W3MC8Hk1WZgFQPWWmBECJ3X72BgUYf9eCQ4PGzPps/go-ipfs-cmdkit"
|
||||
ma "gx/ipfs/QmW8s4zTsUoX1Q6CeYxVKPyqSKbF7H1YDUyTostBtZ8DaG/go-multiaddr"
|
||||
"gx/ipfs/QmX3QZ5jHEPidwUrymXV1iSCSUhdGxj15sm2gP4jKMef7B/client_golang/prometheus"
|
||||
iconn "gx/ipfs/Qmf82zCaYV8bkztRRoGwwSHVkaYtP2UKBnhpjJz1uFGJjQ/go-libp2p-interface-conn"
|
||||
@ -181,9 +181,8 @@ func defaultMux(path string) corehttp.ServeOption {
|
||||
}
|
||||
}
|
||||
|
||||
func daemonFunc(req cmds.Request, re cmds.ResponseEmitter) {
|
||||
func daemonFunc(req *cmds.Request, re cmds.ResponseEmitter, env interface{}) {
|
||||
// Inject metrics before we do anything
|
||||
|
||||
err := mprome.Inject()
|
||||
if err != nil {
|
||||
log.Errorf("Injecting prometheus handler for metrics failed with message: %s\n", err.Error())
|
||||
@ -192,22 +191,23 @@ func daemonFunc(req cmds.Request, re cmds.ResponseEmitter) {
|
||||
// let the user know we're going.
|
||||
fmt.Printf("Initializing daemon...\n")
|
||||
|
||||
if managed, _, _ := req.Option(adjustFDLimitKwd).Bool(); managed {
|
||||
managefd, _ := req.Options[adjustFDLimitKwd].(bool)
|
||||
if managefd {
|
||||
if err := utilmain.ManageFdLimit(); err != nil {
|
||||
log.Errorf("setting file descriptor limit: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
ctx := req.InvocContext()
|
||||
ctx := env.(*oldcmds.Context)
|
||||
|
||||
go func() {
|
||||
<-req.Context().Done()
|
||||
<-req.Context.Done()
|
||||
fmt.Println("Received interrupt signal, shutting down...")
|
||||
fmt.Println("(Hit ctrl-c again to force-shutdown the daemon.)")
|
||||
}()
|
||||
|
||||
// check transport encryption flag.
|
||||
unencrypted, _, _ := req.Option(unencryptTransportKwd).Bool()
|
||||
unencrypted, _ := req.Options[unencryptTransportKwd].(bool)
|
||||
if unencrypted {
|
||||
log.Warningf(`Running with --%s: All connections are UNENCRYPTED.
|
||||
You will not be able to connect to regular encrypted networks.`, unencryptTransportKwd)
|
||||
@ -216,11 +216,7 @@ func daemonFunc(req cmds.Request, re cmds.ResponseEmitter) {
|
||||
|
||||
// first, whether user has provided the initialization flag. we may be
|
||||
// running in an uninitialized state.
|
||||
initialize, _, err := req.Option(initOptionKwd).Bool()
|
||||
if err != nil {
|
||||
re.SetError(err, cmdkit.ErrNormal)
|
||||
return
|
||||
}
|
||||
initialize, _ := req.Options[initOptionKwd].(bool)
|
||||
|
||||
if initialize {
|
||||
|
||||
@ -242,7 +238,7 @@ func daemonFunc(req cmds.Request, re cmds.ResponseEmitter) {
|
||||
re.SetError(err, cmdkit.ErrNormal)
|
||||
return
|
||||
case fsrepo.ErrNeedMigration:
|
||||
domigrate, found, _ := req.Option(migrateKwd).Bool()
|
||||
domigrate, found := req.Options[migrateKwd].(bool)
|
||||
fmt.Println("Found outdated fs-repo, migrations need to be run.")
|
||||
|
||||
if !found {
|
||||
@ -281,10 +277,10 @@ func daemonFunc(req cmds.Request, re cmds.ResponseEmitter) {
|
||||
return
|
||||
}
|
||||
|
||||
offline, _, _ := req.Option(offlineKwd).Bool()
|
||||
pubsub, _, _ := req.Option(enableFloodSubKwd).Bool()
|
||||
ipnsps, _, _ := req.Option(enableIPNSPubSubKwd).Bool()
|
||||
mplex, _, _ := req.Option(enableMultiplexKwd).Bool()
|
||||
offline, _ := req.Options[offlineKwd].(bool)
|
||||
ipnsps, _, _ := req.Options[enableIPNSPubSubKwd].(bool)
|
||||
pubsub, _ := req.Options[enableFloodSubKwd].(bool)
|
||||
mplex, _ := req.Options[enableMultiplexKwd].(bool)
|
||||
|
||||
// Start assembling node config
|
||||
ncfg := &core.BuildCfg{
|
||||
@ -299,11 +295,7 @@ func daemonFunc(req cmds.Request, re cmds.ResponseEmitter) {
|
||||
//TODO(Kubuxu): refactor Online vs Offline by adding Permanent vs Ephemeral
|
||||
}
|
||||
|
||||
routingOption, _, err := req.Option(routingOptionKwd).String()
|
||||
if err != nil {
|
||||
re.SetError(err, cmdkit.ErrNormal)
|
||||
return
|
||||
}
|
||||
routingOption, _ := req.Options[routingOptionKwd].(string)
|
||||
switch routingOption {
|
||||
case routingOptionSupernodeKwd:
|
||||
re.SetError(errors.New("supernode routing was never fully implemented and has been removed"), cmdkit.ErrNormal)
|
||||
@ -319,7 +311,7 @@ func daemonFunc(req cmds.Request, re cmds.ResponseEmitter) {
|
||||
return
|
||||
}
|
||||
|
||||
node, err := core.NewNode(req.Context(), ncfg)
|
||||
node, err := core.NewNode(req.Context, ncfg)
|
||||
if err != nil {
|
||||
log.Error("error from node construction: ", err)
|
||||
re.SetError(err, cmdkit.ErrNormal)
|
||||
@ -340,7 +332,7 @@ func daemonFunc(req cmds.Request, re cmds.ResponseEmitter) {
|
||||
node.Close()
|
||||
|
||||
select {
|
||||
case <-req.Context().Done():
|
||||
case <-req.Context.Done():
|
||||
log.Info("Gracefully shut down daemon")
|
||||
default:
|
||||
}
|
||||
@ -351,25 +343,21 @@ func daemonFunc(req cmds.Request, re cmds.ResponseEmitter) {
|
||||
}
|
||||
|
||||
// construct api endpoint - every time
|
||||
err, apiErrc := serveHTTPApi(req)
|
||||
err, apiErrc := serveHTTPApi(req, ctx)
|
||||
if err != nil {
|
||||
re.SetError(err, cmdkit.ErrNormal)
|
||||
return
|
||||
}
|
||||
|
||||
// construct fuse mountpoints - if the user provided the --mount flag
|
||||
mount, _, err := req.Option(mountKwd).Bool()
|
||||
if err != nil {
|
||||
re.SetError(err, cmdkit.ErrNormal)
|
||||
return
|
||||
}
|
||||
mount, _ := req.Options[mountKwd].(bool)
|
||||
if mount && offline {
|
||||
re.SetError(errors.New("mount is not currently supported in offline mode"),
|
||||
cmdkit.ErrClient)
|
||||
return
|
||||
}
|
||||
if mount {
|
||||
if err := mountFuse(req); err != nil {
|
||||
if err := mountFuse(req, ctx); err != nil {
|
||||
re.SetError(err, cmdkit.ErrNormal)
|
||||
return
|
||||
}
|
||||
@ -386,7 +374,7 @@ func daemonFunc(req cmds.Request, re cmds.ResponseEmitter) {
|
||||
var gwErrc <-chan error
|
||||
if len(cfg.Addresses.Gateway) > 0 {
|
||||
var err error
|
||||
err, gwErrc = serveHTTPGateway(req)
|
||||
err, gwErrc = serveHTTPGateway(req, ctx)
|
||||
if err != nil {
|
||||
re.SetError(err, cmdkit.ErrNormal)
|
||||
return
|
||||
@ -408,16 +396,13 @@ func daemonFunc(req cmds.Request, re cmds.ResponseEmitter) {
|
||||
}
|
||||
|
||||
// serveHTTPApi collects options, creates listener, prints status message and starts serving requests
|
||||
func serveHTTPApi(req cmds.Request) (error, <-chan error) {
|
||||
cfg, err := req.InvocContext().GetConfig()
|
||||
func serveHTTPApi(req *cmds.Request, cctx *oldcmds.Context) (error, <-chan error) {
|
||||
cfg, err := cctx.GetConfig()
|
||||
if err != nil {
|
||||
return fmt.Errorf("serveHTTPApi: GetConfig() failed: %s", err), nil
|
||||
}
|
||||
|
||||
apiAddr, _, err := req.Option(commands.ApiOption).String()
|
||||
if err != nil {
|
||||
return fmt.Errorf("serveHTTPApi: %s", err), nil
|
||||
}
|
||||
apiAddr, _ := req.Options[oldcmds.ApiOption].(string)
|
||||
if apiAddr == "" {
|
||||
apiAddr = cfg.Addresses.API
|
||||
}
|
||||
@ -438,10 +423,7 @@ func serveHTTPApi(req cmds.Request) (error, <-chan error) {
|
||||
// because this would open up the api to scripting vulnerabilities.
|
||||
// only the webui objects are allowed.
|
||||
// if you know what you're doing, go ahead and pass --unrestricted-api.
|
||||
unrestricted, _, err := req.Option(unrestrictedApiAccessKwd).Bool()
|
||||
if err != nil {
|
||||
return fmt.Errorf("serveHTTPApi: Option(%s) failed: %s", unrestrictedApiAccessKwd, err), nil
|
||||
}
|
||||
unrestricted, _ := req.Options[unrestrictedApiAccessKwd].(bool)
|
||||
gatewayOpt := corehttp.GatewayOption(false, corehttp.WebUIPaths...)
|
||||
if unrestricted {
|
||||
gatewayOpt = corehttp.GatewayOption(true, "/ipfs", "/ipns")
|
||||
@ -449,7 +431,7 @@ func serveHTTPApi(req cmds.Request) (error, <-chan error) {
|
||||
|
||||
var opts = []corehttp.ServeOption{
|
||||
corehttp.MetricsCollectionOption("api"),
|
||||
corehttp.CommandsOption(*req.InvocContext()),
|
||||
corehttp.CommandsOption(*cctx),
|
||||
corehttp.WebUIOption,
|
||||
gatewayOpt,
|
||||
corehttp.VersionOption(),
|
||||
@ -463,7 +445,7 @@ func serveHTTPApi(req cmds.Request) (error, <-chan error) {
|
||||
opts = append(opts, corehttp.RedirectOption("", cfg.Gateway.RootRedirect))
|
||||
}
|
||||
|
||||
node, err := req.InvocContext().ConstructNode()
|
||||
node, err := cctx.ConstructNode()
|
||||
if err != nil {
|
||||
return fmt.Errorf("serveHTTPApi: ConstructNode() failed: %s", err), nil
|
||||
}
|
||||
@ -512,8 +494,8 @@ func printSwarmAddrs(node *core.IpfsNode) {
|
||||
}
|
||||
|
||||
// serveHTTPGateway collects options, creates listener, prints status message and starts serving requests
|
||||
func serveHTTPGateway(req cmds.Request) (error, <-chan error) {
|
||||
cfg, err := req.InvocContext().GetConfig()
|
||||
func serveHTTPGateway(req *cmds.Request, cctx *oldcmds.Context) (error, <-chan error) {
|
||||
cfg, err := cctx.GetConfig()
|
||||
if err != nil {
|
||||
return fmt.Errorf("serveHTTPGateway: GetConfig() failed: %s", err), nil
|
||||
}
|
||||
@ -523,10 +505,7 @@ func serveHTTPGateway(req cmds.Request) (error, <-chan error) {
|
||||
return fmt.Errorf("serveHTTPGateway: invalid gateway address: %q (err: %s)", cfg.Addresses.Gateway, err), nil
|
||||
}
|
||||
|
||||
writable, writableOptionFound, err := req.Option(writableKwd).Bool()
|
||||
if err != nil {
|
||||
return fmt.Errorf("serveHTTPGateway: req.Option(%s) failed: %s", writableKwd, err), nil
|
||||
}
|
||||
writable, writableOptionFound := req.Options[writableKwd].(bool)
|
||||
if !writableOptionFound {
|
||||
writable = cfg.Gateway.Writable
|
||||
}
|
||||
@ -546,7 +525,7 @@ func serveHTTPGateway(req cmds.Request) (error, <-chan error) {
|
||||
|
||||
var opts = []corehttp.ServeOption{
|
||||
corehttp.MetricsCollectionOption("gateway"),
|
||||
corehttp.CommandsROOption(*req.InvocContext()),
|
||||
corehttp.CommandsROOption(*cctx),
|
||||
corehttp.VersionOption(),
|
||||
corehttp.IPNSHostnameOption(),
|
||||
corehttp.GatewayOption(writable, "/ipfs", "/ipns"),
|
||||
@ -556,7 +535,7 @@ func serveHTTPGateway(req cmds.Request) (error, <-chan error) {
|
||||
opts = append(opts, corehttp.RedirectOption("", cfg.Gateway.RootRedirect))
|
||||
}
|
||||
|
||||
node, err := req.InvocContext().ConstructNode()
|
||||
node, err := cctx.ConstructNode()
|
||||
if err != nil {
|
||||
return fmt.Errorf("serveHTTPGateway: ConstructNode() failed: %s", err), nil
|
||||
}
|
||||
@ -570,29 +549,23 @@ func serveHTTPGateway(req cmds.Request) (error, <-chan error) {
|
||||
}
|
||||
|
||||
//collects options and opens the fuse mountpoint
|
||||
func mountFuse(req cmds.Request) error {
|
||||
cfg, err := req.InvocContext().GetConfig()
|
||||
func mountFuse(req *cmds.Request, cctx *oldcmds.Context) error {
|
||||
cfg, err := cctx.GetConfig()
|
||||
if err != nil {
|
||||
return fmt.Errorf("mountFuse: GetConfig() failed: %s", err)
|
||||
}
|
||||
|
||||
fsdir, found, err := req.Option(ipfsMountKwd).String()
|
||||
if err != nil {
|
||||
return fmt.Errorf("mountFuse: req.Option(%s) failed: %s", ipfsMountKwd, err)
|
||||
}
|
||||
fsdir, found := req.Options[ipfsMountKwd].(string)
|
||||
if !found {
|
||||
fsdir = cfg.Mounts.IPFS
|
||||
}
|
||||
|
||||
nsdir, found, err := req.Option(ipnsMountKwd).String()
|
||||
if err != nil {
|
||||
return fmt.Errorf("mountFuse: req.Option(%s) failed: %s", ipnsMountKwd, err)
|
||||
}
|
||||
nsdir, found := req.Options[ipnsMountKwd].(string)
|
||||
if !found {
|
||||
nsdir = cfg.Mounts.IPNS
|
||||
}
|
||||
|
||||
node, err := req.InvocContext().ConstructNode()
|
||||
node, err := cctx.ConstructNode()
|
||||
if err != nil {
|
||||
return fmt.Errorf("mountFuse: ConstructNode() failed: %s", err)
|
||||
}
|
||||
@ -606,18 +579,15 @@ func mountFuse(req cmds.Request) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func maybeRunGC(req cmds.Request, node *core.IpfsNode) (error, <-chan error) {
|
||||
enableGC, _, err := req.Option(enableGCKwd).Bool()
|
||||
if err != nil {
|
||||
return err, nil
|
||||
}
|
||||
func maybeRunGC(req *cmds.Request, node *core.IpfsNode) (error, <-chan error) {
|
||||
enableGC, _ := req.Options[enableGCKwd].(bool)
|
||||
if !enableGC {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
errc := make(chan error)
|
||||
go func() {
|
||||
errc <- corerepo.PeriodicGC(req.Context(), node)
|
||||
errc <- corerepo.PeriodicGC(req.Context, node)
|
||||
close(errc)
|
||||
}()
|
||||
return nil, errc
|
||||
|
||||
@ -17,7 +17,7 @@ import (
|
||||
config "github.com/ipfs/go-ipfs/repo/config"
|
||||
fsrepo "github.com/ipfs/go-ipfs/repo/fsrepo"
|
||||
|
||||
"gx/ipfs/QmQp2a2Hhb7F6eK2A5hN8f9aJy4mtkEikL9Zj4cgB7d1dD/go-ipfs-cmdkit"
|
||||
"gx/ipfs/QmVD1W3MC8Hk1WZgFQPWWmBECJ3X72BgUYf9eCQ4PGzPps/go-ipfs-cmdkit"
|
||||
)
|
||||
|
||||
const (
|
||||
|
||||
@ -3,10 +3,10 @@ package main
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
oldcmds "github.com/ipfs/go-ipfs/commands"
|
||||
commands "github.com/ipfs/go-ipfs/core/commands"
|
||||
|
||||
cmds "gx/ipfs/QmP9vZfc5WSjfGTXmwX2EcicMFzmZ6fXn7HTdKYat6ccmH/go-ipfs-cmds"
|
||||
lgc "github.com/ipfs/go-ipfs/commands/legacy"
|
||||
cmds "gx/ipfs/QmTwKPLyeRKuDawuy6CAn1kRj1FVoqBEM8sviAUWN7NW9K/go-ipfs-cmds"
|
||||
)
|
||||
|
||||
// This is the CLI root, used for executing commands accessible to CLI clients.
|
||||
@ -24,7 +24,7 @@ var commandsClientCmd = commands.CommandsCmd(Root)
|
||||
// They can override subcommands in commands.Root by defining a subcommand with the same name.
|
||||
var localCommands = map[string]*cmds.Command{
|
||||
"daemon": daemonCmd,
|
||||
"init": cmds.NewCommand(initCmd),
|
||||
"init": lgc.NewCommand(initCmd),
|
||||
"commands": commandsClientCmd,
|
||||
}
|
||||
var localMap = make(map[*cmds.Command]bool)
|
||||
@ -33,14 +33,7 @@ func init() {
|
||||
// setting here instead of in literal to prevent initialization loop
|
||||
// (some commands make references to Root)
|
||||
Root.Subcommands = localCommands
|
||||
Root.OldSubcommands = map[string]*oldcmds.Command{}
|
||||
|
||||
// copy all subcommands from commands.Root into this root (if they aren't already present)
|
||||
for k, v := range commands.Root.OldSubcommands {
|
||||
if _, found := Root.OldSubcommands[k]; !found {
|
||||
Root.OldSubcommands[k] = v
|
||||
}
|
||||
}
|
||||
for k, v := range commands.Root.Subcommands {
|
||||
if _, found := Root.Subcommands[k]; !found {
|
||||
Root.Subcommands[k] = v
|
||||
|
||||
137
cmd/ipfs/main.go
137
cmd/ipfs/main.go
@ -18,6 +18,7 @@ import (
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
oldcmds "github.com/ipfs/go-ipfs/commands"
|
||||
core "github.com/ipfs/go-ipfs/core"
|
||||
coreCmds "github.com/ipfs/go-ipfs/core/commands"
|
||||
"github.com/ipfs/go-ipfs/plugin/loader"
|
||||
@ -33,6 +34,10 @@ import (
|
||||
manet "gx/ipfs/QmSGL5Uoa6gKHgBBwQG8u1CWKUC8ZnwaZiLgFVTFBR2bxr/go-multiaddr-net"
|
||||
logging "gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log"
|
||||
loggables "gx/ipfs/QmSvcDkiRwB8LuMhUtnvhum2C851Mproo75ZDD19jx43tD/go-libp2p-loggables"
|
||||
"gx/ipfs/QmTwKPLyeRKuDawuy6CAn1kRj1FVoqBEM8sviAUWN7NW9K/go-ipfs-cmds"
|
||||
"gx/ipfs/QmTwKPLyeRKuDawuy6CAn1kRj1FVoqBEM8sviAUWN7NW9K/go-ipfs-cmds/cli"
|
||||
"gx/ipfs/QmTwKPLyeRKuDawuy6CAn1kRj1FVoqBEM8sviAUWN7NW9K/go-ipfs-cmds/http"
|
||||
"gx/ipfs/QmVD1W3MC8Hk1WZgFQPWWmBECJ3X72BgUYf9eCQ4PGzPps/go-ipfs-cmdkit"
|
||||
ma "gx/ipfs/QmW8s4zTsUoX1Q6CeYxVKPyqSKbF7H1YDUyTostBtZ8DaG/go-multiaddr"
|
||||
osh "gx/ipfs/QmXuBJ7DR6k3rmUEKtvVMhwjmXDuJgXXPUt4LQXKBMsU93/go-os-helper"
|
||||
)
|
||||
@ -49,10 +54,9 @@ const (
|
||||
)
|
||||
|
||||
type cmdInvocation struct {
|
||||
path []string
|
||||
cmd *cmds.Command
|
||||
req cmds.Request
|
||||
req *cmds.Request
|
||||
node *core.IpfsNode
|
||||
ctx *oldcmds.Context
|
||||
}
|
||||
|
||||
type exitErr int
|
||||
@ -100,12 +104,17 @@ func mainRet() int {
|
||||
helpFunc = cli.LongHelp
|
||||
}
|
||||
|
||||
helpFunc("ipfs", Root, invoc.path, w)
|
||||
var p []string
|
||||
if invoc.req != nil {
|
||||
p = invoc.req.Path
|
||||
}
|
||||
|
||||
helpFunc("ipfs", Root, p, w)
|
||||
}
|
||||
|
||||
// this is a message to tell the user how to get the help text
|
||||
printMetaHelp := func(w io.Writer) {
|
||||
cmdPath := strings.Join(invoc.path, " ")
|
||||
cmdPath := strings.Join(invoc.req.Path, " ")
|
||||
fmt.Fprintf(w, "Use 'ipfs %s --help' for information about this command\n", cmdPath)
|
||||
}
|
||||
|
||||
@ -119,6 +128,9 @@ func mainRet() int {
|
||||
}
|
||||
}
|
||||
|
||||
intrh, ctx := invoc.SetupInterruptHandler(ctx)
|
||||
defer intrh.Close()
|
||||
|
||||
// parse the commandline into a command invocation
|
||||
parseErr := invoc.Parse(ctx, os.Args[1:])
|
||||
|
||||
@ -142,7 +154,7 @@ func mainRet() int {
|
||||
printErr(parseErr)
|
||||
|
||||
// this was a user error, print help.
|
||||
if invoc.cmd != nil {
|
||||
if invoc.req != nil && invoc.req.Command != nil {
|
||||
// we need a newline space.
|
||||
fmt.Fprintf(os.Stderr, "\n")
|
||||
printHelp(false, os.Stderr)
|
||||
@ -153,15 +165,12 @@ func mainRet() int {
|
||||
// here we handle the cases where
|
||||
// - commands with no Run func are invoked directly.
|
||||
// - the main command is invoked.
|
||||
if invoc.cmd == nil || invoc.cmd.Run == nil {
|
||||
if invoc.req == nil || invoc.req.Command == nil || invoc.req.Command.Run == nil {
|
||||
printHelp(false, os.Stdout)
|
||||
return 0
|
||||
}
|
||||
|
||||
// ok, finally, run the command invocation.
|
||||
intrh, ctx := invoc.SetupInterruptHandler(ctx)
|
||||
defer intrh.Close()
|
||||
|
||||
err = invoc.Run(ctx)
|
||||
if err != nil {
|
||||
if code, ok := err.(exitErr); ok {
|
||||
@ -184,10 +193,7 @@ func mainRet() int {
|
||||
func (i *cmdInvocation) Run(ctx context.Context) error {
|
||||
|
||||
// check if user wants to debug. option OR env var.
|
||||
debug, _, err := i.req.Option("debug").Bool()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
debug, _ := i.req.Options["debug"].(bool)
|
||||
if debug || os.Getenv("IPFS_LOGGING") == "debug" {
|
||||
u.Debug = true
|
||||
logging.SetDebugLogging()
|
||||
@ -196,8 +202,7 @@ func (i *cmdInvocation) Run(ctx context.Context) error {
|
||||
u.Debug = true
|
||||
}
|
||||
|
||||
err = callCommand(ctx, i.req, Root, i.cmd)
|
||||
return err
|
||||
return callCommand(ctx, i.req, Root, i.ctx)
|
||||
}
|
||||
|
||||
func (i *cmdInvocation) constructNodeFunc(ctx context.Context) func() (*core.IpfsNode, error) {
|
||||
@ -206,12 +211,7 @@ func (i *cmdInvocation) constructNodeFunc(ctx context.Context) func() (*core.Ipf
|
||||
return nil, errors.New("constructing node without a request")
|
||||
}
|
||||
|
||||
cmdctx := i.req.InvocContext()
|
||||
if cmdctx == nil {
|
||||
return nil, errors.New("constructing node without a request context")
|
||||
}
|
||||
|
||||
r, err := fsrepo.Open(i.req.InvocContext().ConfigRoot)
|
||||
r, err := fsrepo.Open(i.ctx.ConfigRoot)
|
||||
if err != nil { // repo is owned by the node
|
||||
return nil, err
|
||||
}
|
||||
@ -219,7 +219,7 @@ func (i *cmdInvocation) constructNodeFunc(ctx context.Context) func() (*core.Ipf
|
||||
// ok everything is good. set it on the invocation (for ownership)
|
||||
// and return it.
|
||||
n, err = core.NewNode(ctx, &core.BuildCfg{
|
||||
Online: cmdctx.Online,
|
||||
Online: i.ctx.Online,
|
||||
Repo: r,
|
||||
})
|
||||
if err != nil {
|
||||
@ -244,11 +244,17 @@ func (i *cmdInvocation) close() {
|
||||
func (i *cmdInvocation) Parse(ctx context.Context, args []string) error {
|
||||
var err error
|
||||
|
||||
i.req, i.cmd, i.path, err = cli.Parse(args, os.Stdin, Root)
|
||||
i.req, err = cli.Parse(args, os.Stdin, Root)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
//TODO remove this
|
||||
//fmt.Printf("%#v\n", i.req)
|
||||
|
||||
// TODO(keks): pass this as arg to cli.Parse()
|
||||
i.req.Context = ctx
|
||||
|
||||
repoPath, err := getRepoPath(i.req)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -256,20 +262,22 @@ func (i *cmdInvocation) Parse(ctx context.Context, args []string) error {
|
||||
log.Debugf("config path is %s", repoPath)
|
||||
|
||||
// this sets up the function that will initialize the config lazily.
|
||||
cmdctx := i.req.InvocContext()
|
||||
cmdctx.ConfigRoot = repoPath
|
||||
cmdctx.LoadConfig = loadConfig
|
||||
if i.ctx == nil {
|
||||
i.ctx = &oldcmds.Context{}
|
||||
}
|
||||
i.ctx.ConfigRoot = repoPath
|
||||
i.ctx.LoadConfig = loadConfig
|
||||
// this sets up the function that will initialize the node
|
||||
// this is so that we can construct the node lazily.
|
||||
cmdctx.ConstructNode = i.constructNodeFunc(ctx)
|
||||
i.ctx.ConstructNode = i.constructNodeFunc(ctx)
|
||||
|
||||
// if no encoding was specified by user, default to plaintext encoding
|
||||
// (if command doesn't support plaintext, use JSON instead)
|
||||
if !i.req.Option("encoding").Found() {
|
||||
if i.req.Command().Encoders != nil && i.req.Command().Encoders[cmds.Text] != nil {
|
||||
i.req.SetOption("encoding", cmds.Text)
|
||||
if enc := i.req.Options[cmds.EncShort]; enc == "" {
|
||||
if i.req.Command.Encoders != nil && i.req.Command.Encoders[cmds.Text] != nil {
|
||||
i.req.SetOption(cmds.EncShort, cmds.Text)
|
||||
} else {
|
||||
i.req.SetOption("encoding", cmds.JSON)
|
||||
i.req.SetOption(cmds.EncShort, cmds.JSON)
|
||||
}
|
||||
}
|
||||
|
||||
@ -277,18 +285,12 @@ func (i *cmdInvocation) Parse(ctx context.Context, args []string) error {
|
||||
}
|
||||
|
||||
func (i *cmdInvocation) requestedHelp() (short bool, long bool, err error) {
|
||||
longHelp, _, err := i.req.Option("help").Bool()
|
||||
if err != nil {
|
||||
return false, false, err
|
||||
}
|
||||
shortHelp, _, err := i.req.Option("h").Bool()
|
||||
if err != nil {
|
||||
return false, false, err
|
||||
}
|
||||
longHelp, _ := i.req.Options["help"].(bool)
|
||||
shortHelp, _ := i.req.Options["h"].(bool)
|
||||
return longHelp, shortHelp, nil
|
||||
}
|
||||
|
||||
func callPreCommandHooks(ctx context.Context, details cmdDetails, req cmds.Request, root *cmds.Command) error {
|
||||
func callPreCommandHooks(ctx context.Context, details cmdDetails, req *cmds.Request, root *cmds.Command) error {
|
||||
|
||||
log.Event(ctx, "callPreCommandHooks", &details)
|
||||
log.Debug("calling pre-command hooks...")
|
||||
@ -296,20 +298,16 @@ func callPreCommandHooks(ctx context.Context, details cmdDetails, req cmds.Reque
|
||||
return nil
|
||||
}
|
||||
|
||||
func callCommand(ctx context.Context, req cmds.Request, root *cmds.Command, cmd *cmds.Command) error {
|
||||
log.Info(config.EnvDir, " ", req.InvocContext().ConfigRoot)
|
||||
func callCommand(ctx context.Context, req *cmds.Request, root *cmds.Command, cctx *oldcmds.Context) error {
|
||||
log.Info(config.EnvDir, " ", cctx.ConfigRoot)
|
||||
cmd := req.Command
|
||||
|
||||
err := req.SetRootContext(ctx)
|
||||
details, err := commandDetails(req.Path, root)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
details, err := commandDetails(req.Path(), root)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
client, err := commandShouldRunOnDaemon(*details, req, root)
|
||||
client, err := commandShouldRunOnDaemon(*details, req, root, cctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -319,11 +317,7 @@ func callCommand(ctx context.Context, req cmds.Request, root *cmds.Command, cmd
|
||||
return err
|
||||
}
|
||||
|
||||
encTypeStr, found, err := req.Option("encoding").String()
|
||||
if !found || err != nil {
|
||||
log.Error("error getting encoding - using JSON. reason: ", err)
|
||||
encTypeStr = "json"
|
||||
}
|
||||
encTypeStr, _ := req.Options[cmds.EncShort].(string)
|
||||
encType := cmds.EncodingType(encTypeStr)
|
||||
|
||||
var (
|
||||
@ -341,7 +335,7 @@ func callCommand(ctx context.Context, req cmds.Request, root *cmds.Command, cmd
|
||||
}
|
||||
|
||||
if cmd.PreRun != nil {
|
||||
err = cmd.PreRun(req)
|
||||
err = cmd.PreRun(req, cctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -375,19 +369,14 @@ func callCommand(ctx context.Context, req cmds.Request, root *cmds.Command, cmd
|
||||
} else {
|
||||
log.Debug("executing command locally")
|
||||
|
||||
pluginpath := filepath.Join(req.InvocContext().ConfigRoot, "plugins")
|
||||
pluginpath := filepath.Join(cctx.ConfigRoot, "plugins")
|
||||
if _, err := loader.LoadPlugins(pluginpath); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err := req.SetRootContext(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Okay!!!!! NOW we can call the command.
|
||||
go func() {
|
||||
err := root.Call(req, re)
|
||||
err := root.Call(req, re, cctx)
|
||||
if err != nil {
|
||||
re.SetError(err, cmdkit.ErrNormal)
|
||||
}
|
||||
@ -428,8 +417,8 @@ func commandDetails(path []string, root *cmds.Command) (*cmdDetails, error) {
|
||||
// It returns a client if the command should be executed on a daemon and nil if
|
||||
// it should be executed on a client. It returns an error if the command must
|
||||
// NOT be executed on either.
|
||||
func commandShouldRunOnDaemon(details cmdDetails, req cmds.Request, root *cmds.Command) (http.Client, error) {
|
||||
path := req.Path()
|
||||
func commandShouldRunOnDaemon(details cmdDetails, req *cmds.Request, root *cmds.Command, cctx *oldcmds.Context) (http.Client, error) {
|
||||
path := req.Path
|
||||
// root command.
|
||||
if len(path) < 1 {
|
||||
return nil, nil
|
||||
@ -447,14 +436,11 @@ func commandShouldRunOnDaemon(details cmdDetails, req cmds.Request, root *cmds.C
|
||||
// to this point so that we dont check unnecessarily
|
||||
|
||||
// did user specify an api to use for this command?
|
||||
apiAddrStr, _, err := req.Option(coreCmds.ApiOption).String()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
apiAddrStr, _ := req.Options[coreCmds.ApiOption].(string)
|
||||
|
||||
client, err := getApiClient(req.InvocContext().ConfigRoot, apiAddrStr)
|
||||
client, err := getApiClient(cctx.ConfigRoot, apiAddrStr)
|
||||
if err == repo.ErrApiNotRunning {
|
||||
if apiAddrStr != "" && req.Command() != daemonCmd {
|
||||
if apiAddrStr != "" && req.Command != daemonCmd {
|
||||
// if user SPECIFIED an api, and this cmd is not daemon
|
||||
// we MUST use it. so error out.
|
||||
return nil, err
|
||||
@ -469,7 +455,7 @@ func commandShouldRunOnDaemon(details cmdDetails, req cmds.Request, root *cmds.C
|
||||
if details.cannotRunOnDaemon {
|
||||
// check if daemon locked. legacy error text, for now.
|
||||
log.Debugf("Command cannot run on daemon. Checking if daemon is locked")
|
||||
if daemonLocked, _ := fsrepo.LockedByOtherProcess(req.InvocContext().ConfigRoot); daemonLocked {
|
||||
if daemonLocked, _ := fsrepo.LockedByOtherProcess(cctx.ConfigRoot); daemonLocked {
|
||||
return nil, cmds.ClientError("ipfs daemon is running. please stop it to run this command")
|
||||
}
|
||||
return nil, nil
|
||||
@ -493,11 +479,8 @@ func isClientError(err error) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func getRepoPath(req cmds.Request) (string, error) {
|
||||
repoOpt, found, err := req.Option("config").String()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
func getRepoPath(req *cmds.Request) (string, error) {
|
||||
repoOpt, found := req.Options["config"].(string)
|
||||
if found && repoOpt != "" {
|
||||
return repoOpt, nil
|
||||
}
|
||||
|
||||
@ -3,7 +3,7 @@ package main
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"gx/ipfs/QmQp2a2Hhb7F6eK2A5hN8f9aJy4mtkEikL9Zj4cgB7d1dD/go-ipfs-cmdkit"
|
||||
"gx/ipfs/QmVD1W3MC8Hk1WZgFQPWWmBECJ3X72BgUYf9eCQ4PGzPps/go-ipfs-cmdkit"
|
||||
)
|
||||
|
||||
func TestIsCientErr(t *testing.T) {
|
||||
|
||||
@ -9,6 +9,7 @@ import (
|
||||
"path/filepath"
|
||||
"syscall"
|
||||
|
||||
commands "github.com/ipfs/go-ipfs/commands"
|
||||
core "github.com/ipfs/go-ipfs/core"
|
||||
corehttp "github.com/ipfs/go-ipfs/core/corehttp"
|
||||
coreunix "github.com/ipfs/go-ipfs/core/coreunix"
|
||||
|
||||
@ -15,8 +15,10 @@ import (
|
||||
"reflect"
|
||||
|
||||
"github.com/ipfs/go-ipfs/path"
|
||||
"gx/ipfs/QmQp2a2Hhb7F6eK2A5hN8f9aJy4mtkEikL9Zj4cgB7d1dD/go-ipfs-cmdkit"
|
||||
|
||||
logging "gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log"
|
||||
cmds "gx/ipfs/QmTwKPLyeRKuDawuy6CAn1kRj1FVoqBEM8sviAUWN7NW9K/go-ipfs-cmds"
|
||||
cmdkit "gx/ipfs/QmVD1W3MC8Hk1WZgFQPWWmBECJ3X72BgUYf9eCQ4PGzPps/go-ipfs-cmdkit"
|
||||
)
|
||||
|
||||
var log = logging.Logger("command")
|
||||
@ -283,9 +285,9 @@ func ClientError(msg string) error {
|
||||
|
||||
// global options, added to every command
|
||||
var globalOptions = []cmdkit.Option{
|
||||
cmdkit.OptionEncodingType,
|
||||
cmdkit.OptionStreamChannels,
|
||||
cmdkit.OptionTimeout,
|
||||
cmds.OptionEncodingType,
|
||||
cmds.OptionStreamChannels,
|
||||
cmds.OptionTimeout,
|
||||
}
|
||||
|
||||
// the above array of Options, wrapped in a Command
|
||||
|
||||
@ -3,7 +3,8 @@ package commands
|
||||
import (
|
||||
"testing"
|
||||
|
||||
cmdkit "gx/ipfs/QmQp2a2Hhb7F6eK2A5hN8f9aJy4mtkEikL9Zj4cgB7d1dD/go-ipfs-cmdkit"
|
||||
cmds "gx/ipfs/QmTwKPLyeRKuDawuy6CAn1kRj1FVoqBEM8sviAUWN7NW9K/go-ipfs-cmds"
|
||||
cmdkit "gx/ipfs/QmVD1W3MC8Hk1WZgFQPWWmBECJ3X72BgUYf9eCQ4PGzPps/go-ipfs-cmdkit"
|
||||
)
|
||||
|
||||
func noop(req Request, res Response) {
|
||||
@ -58,7 +59,7 @@ func TestOptionValidation(t *testing.T) {
|
||||
}
|
||||
|
||||
req, _ = NewRequest(nil, nil, nil, nil, nil, opts)
|
||||
req.SetOption(cmdkit.EncShort, "json")
|
||||
req.SetOption(cmds.EncShort, "json")
|
||||
res = cmd.Call(req)
|
||||
if res.Error() != nil {
|
||||
t.Error("Should have passed")
|
||||
|
||||
70
commands/legacy/command.go
Normal file
70
commands/legacy/command.go
Normal file
@ -0,0 +1,70 @@
|
||||
package legacy
|
||||
|
||||
import (
|
||||
"io"
|
||||
|
||||
"gx/ipfs/QmTwKPLyeRKuDawuy6CAn1kRj1FVoqBEM8sviAUWN7NW9K/go-ipfs-cmds"
|
||||
|
||||
oldcmds "github.com/ipfs/go-ipfs/commands"
|
||||
logging "gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log"
|
||||
)
|
||||
|
||||
var log = logging.Logger("cmds/lgc")
|
||||
|
||||
// NewCommand returns a Command from an oldcmds.Command
|
||||
func NewCommand(oldcmd *oldcmds.Command) *cmds.Command {
|
||||
if oldcmd == nil {
|
||||
return nil
|
||||
}
|
||||
var cmd *cmds.Command
|
||||
|
||||
cmd = &cmds.Command{
|
||||
Options: oldcmd.Options,
|
||||
Arguments: oldcmd.Arguments,
|
||||
Helptext: oldcmd.Helptext,
|
||||
External: oldcmd.External,
|
||||
Type: oldcmd.Type,
|
||||
|
||||
Subcommands: make(map[string]*cmds.Command),
|
||||
}
|
||||
|
||||
if oldcmd.Run != nil {
|
||||
cmd.Run = func(req *cmds.Request, re cmds.ResponseEmitter, env interface{}) {
|
||||
oldReq := &requestWrapper{req, OldContext(env)}
|
||||
res := &fakeResponse{req: oldReq, re: re, wait: make(chan struct{})}
|
||||
|
||||
errCh := make(chan error)
|
||||
go res.Send(errCh)
|
||||
oldcmd.Run(oldReq, res)
|
||||
err := <-errCh
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if oldcmd.PreRun != nil {
|
||||
cmd.PreRun = func(req *cmds.Request, env interface{}) error {
|
||||
oldReq := &requestWrapper{req, OldContext(env)}
|
||||
return oldcmd.PreRun(oldReq)
|
||||
}
|
||||
}
|
||||
|
||||
for name, sub := range oldcmd.Subcommands {
|
||||
cmd.Subcommands[name] = NewCommand(sub)
|
||||
}
|
||||
|
||||
cmd.Encoders = make(cmds.EncoderMap)
|
||||
|
||||
for encType, m := range oldcmd.Marshalers {
|
||||
cmd.Encoders[cmds.EncodingType(encType)] = func(m oldcmds.Marshaler, encType oldcmds.EncodingType) func(req *cmds.Request) func(io.Writer) cmds.Encoder {
|
||||
return func(req *cmds.Request) func(io.Writer) cmds.Encoder {
|
||||
return func(w io.Writer) cmds.Encoder {
|
||||
return NewMarshalerEncoder(req, m, w)
|
||||
}
|
||||
}
|
||||
}(m, encType)
|
||||
}
|
||||
|
||||
return cmd
|
||||
}
|
||||
81
commands/legacy/legacy.go
Normal file
81
commands/legacy/legacy.go
Normal file
@ -0,0 +1,81 @@
|
||||
package legacy
|
||||
|
||||
import (
|
||||
"io"
|
||||
"runtime/debug"
|
||||
|
||||
"gx/ipfs/QmTwKPLyeRKuDawuy6CAn1kRj1FVoqBEM8sviAUWN7NW9K/go-ipfs-cmds"
|
||||
|
||||
oldcmds "github.com/ipfs/go-ipfs/commands"
|
||||
)
|
||||
|
||||
// MarshalerEncoder implements Encoder from a Marshaler
|
||||
type MarshalerEncoder struct {
|
||||
m oldcmds.Marshaler
|
||||
w io.Writer
|
||||
req *cmds.Request
|
||||
}
|
||||
|
||||
// NewMarshalerEncoder returns a new MarshalerEncoder
|
||||
func NewMarshalerEncoder(req *cmds.Request, m oldcmds.Marshaler, w io.Writer) *MarshalerEncoder {
|
||||
me := &MarshalerEncoder{
|
||||
m: m,
|
||||
w: w,
|
||||
req: req,
|
||||
}
|
||||
|
||||
return me
|
||||
}
|
||||
|
||||
// Encode encodes v onto the io.Writer w using Marshaler m, with both m and w passed in NewMarshalerEncoder
|
||||
func (me *MarshalerEncoder) Encode(v interface{}) error {
|
||||
re, res := cmds.NewChanResponsePair(me.req)
|
||||
go re.Emit(v)
|
||||
|
||||
r, err := me.m(&responseWrapper{Response: res})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if r == nil {
|
||||
// behave like empty reader
|
||||
return nil
|
||||
}
|
||||
|
||||
_, err = io.Copy(me.w, r)
|
||||
return err
|
||||
}
|
||||
|
||||
func OldContext(env interface{}) *oldcmds.Context {
|
||||
ctx, ok := env.(*oldcmds.Context)
|
||||
if !ok {
|
||||
log.Errorf("OldContext: env passed is not %T but %T\n%s", ctx, env, debug.Stack())
|
||||
}
|
||||
|
||||
return ctx
|
||||
}
|
||||
|
||||
/*
|
||||
// OldReqLog returns an oldcmds.ReqLog from a ReqLog
|
||||
func OldReqLog(newrl *ReqLog) *oldcmds.ReqLog {
|
||||
if newrl == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
rl := &oldcmds.ReqLog{}
|
||||
|
||||
for _, rle := range newrl.Requests {
|
||||
oldrle := &oldcmds.ReqLogEntry{
|
||||
StartTime: rle.StartTime,
|
||||
EndTime: rle.EndTime,
|
||||
Active: rle.Active,
|
||||
Command: rle.Command,
|
||||
Options: rle.Options,
|
||||
Args: rle.Args,
|
||||
ID: rle.ID,
|
||||
}
|
||||
rl.AddEntry(oldrle)
|
||||
}
|
||||
|
||||
return rl
|
||||
}
|
||||
*/
|
||||
214
commands/legacy/legacy_test.go
Normal file
214
commands/legacy/legacy_test.go
Normal file
@ -0,0 +1,214 @@
|
||||
package legacy
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"io"
|
||||
"testing"
|
||||
|
||||
oldcmds "github.com/ipfs/go-ipfs/commands"
|
||||
cmds "gx/ipfs/QmTwKPLyeRKuDawuy6CAn1kRj1FVoqBEM8sviAUWN7NW9K/go-ipfs-cmds"
|
||||
cmdkit "gx/ipfs/QmVD1W3MC8Hk1WZgFQPWWmBECJ3X72BgUYf9eCQ4PGzPps/go-ipfs-cmdkit"
|
||||
)
|
||||
|
||||
type WriteNopCloser struct {
|
||||
io.Writer
|
||||
}
|
||||
|
||||
func (wc WriteNopCloser) Close() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func TestNewCommand(t *testing.T) {
|
||||
root := &cmds.Command{
|
||||
Subcommands: map[string]*cmds.Command{
|
||||
"test": NewCommand(&oldcmds.Command{
|
||||
Run: func(req oldcmds.Request, res oldcmds.Response) {
|
||||
res.SetOutput("Test.")
|
||||
},
|
||||
Marshalers: map[oldcmds.EncodingType]oldcmds.Marshaler{
|
||||
oldcmds.Text: func(res oldcmds.Response) (io.Reader, error) {
|
||||
ch, ok := res.Output().(<-chan interface{})
|
||||
if !ok {
|
||||
t.Fatalf("output is not <-chan interface{} but %T", ch)
|
||||
}
|
||||
|
||||
v := <-ch
|
||||
str, ok := v.(string)
|
||||
if !ok {
|
||||
t.Fatalf("read value is not string but %T", v)
|
||||
}
|
||||
|
||||
buf := bytes.NewBuffer(nil)
|
||||
_, err := io.WriteString(buf, str)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
return buf, nil
|
||||
},
|
||||
},
|
||||
Subcommands: map[string]*oldcmds.Command{
|
||||
"sub": &oldcmds.Command{
|
||||
Options: []cmdkit.Option{
|
||||
cmdkit.NewOption(cmdkit.String, "test", "t", "some random test flag"),
|
||||
},
|
||||
},
|
||||
},
|
||||
}),
|
||||
},
|
||||
}
|
||||
|
||||
path := []string{"test"}
|
||||
req, err := cmds.NewRequest(context.TODO(), path, nil, nil, nil, root)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
buf := bytes.NewBuffer(nil)
|
||||
|
||||
// test calling "test" command
|
||||
testCmd := root.Subcommand("test")
|
||||
enc := testCmd.Encoders[oldcmds.Text]
|
||||
if enc == nil {
|
||||
t.Fatal("got nil encoder")
|
||||
}
|
||||
|
||||
re := cmds.NewWriterResponseEmitter(WriteNopCloser{buf}, req, enc)
|
||||
|
||||
var env oldcmds.Context
|
||||
|
||||
err = root.Call(req, re, &env)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
expected := "Test."
|
||||
|
||||
if buf.String() != expected {
|
||||
t.Fatalf("expected string %#v but got %#v", expected, buf.String())
|
||||
}
|
||||
|
||||
// test getting subcommand
|
||||
subCmd := testCmd.Subcommand("sub")
|
||||
if subCmd == nil {
|
||||
t.Fatal("got nil subcommand")
|
||||
}
|
||||
|
||||
if nOpts := len(subCmd.Options); nOpts != 1 {
|
||||
t.Fatalf("subcommand has %v options, expected 1", nOpts)
|
||||
}
|
||||
|
||||
opt := subCmd.Options[0]
|
||||
|
||||
if nNames := len(opt.Names()); nNames != 2 {
|
||||
t.Fatalf("option has %v names, expected 2", nNames)
|
||||
}
|
||||
|
||||
names := opt.Names()
|
||||
if names[0] != "test" {
|
||||
t.Fatalf("option has name %q, expected %q", names[0], "test")
|
||||
}
|
||||
|
||||
if names[1] != "t" {
|
||||
t.Fatalf("option has name %q, expected %q", names[1], "t")
|
||||
}
|
||||
}
|
||||
|
||||
func TestPipePair(t *testing.T) {
|
||||
cmd := &cmds.Command{Type: "string"}
|
||||
|
||||
req, err := cmds.NewRequest(context.TODO(), nil, nil, nil, nil, cmd)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
r, w := io.Pipe()
|
||||
re := cmds.NewWriterResponseEmitter(w, req, cmds.Encoders[cmds.JSON])
|
||||
res := cmds.NewReaderResponse(r, cmds.JSON, req)
|
||||
|
||||
wait := make(chan interface{})
|
||||
|
||||
expect := "abc"
|
||||
go func() {
|
||||
err := re.Emit(expect)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
close(wait)
|
||||
}()
|
||||
|
||||
v, err := res.Next()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
str, ok := v.(*string)
|
||||
if !ok {
|
||||
t.Fatalf("expected type %T but got %T", expect, v)
|
||||
}
|
||||
if *str != expect {
|
||||
t.Fatalf("expected value %#v but got %#v", expect, v)
|
||||
}
|
||||
|
||||
<-wait
|
||||
|
||||
}
|
||||
|
||||
func TestTeeEmitter(t *testing.T) {
|
||||
req, err := cmds.NewRequest(nil, nil, nil, nil, nil, nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
buf1 := bytes.NewBuffer(nil)
|
||||
re1 := cmds.NewWriterResponseEmitter(WriteNopCloser{buf1}, req, cmds.Encoders[cmds.Text])
|
||||
|
||||
buf2 := bytes.NewBuffer(nil)
|
||||
re2 := cmds.NewWriterResponseEmitter(WriteNopCloser{buf2}, req, cmds.Encoders[cmds.Text])
|
||||
|
||||
re := cmds.NewTeeEmitter(re1, re2)
|
||||
|
||||
expect := "def"
|
||||
err = re.Emit(expect)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if buf1.String() != expect {
|
||||
t.Fatal("expected %#v, got %#v", expect, buf1.String())
|
||||
}
|
||||
|
||||
if buf2.String() != expect {
|
||||
t.Fatal("expected %#v, got %#v", expect, buf2.String())
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
type teeErrorTestCase struct {
|
||||
err1, err2 error
|
||||
bothNil bool
|
||||
errString string
|
||||
}
|
||||
|
||||
func TestTeeError(t *testing.T) {
|
||||
tcs := []teeErrorTestCase{
|
||||
teeErrorTestCase{nil, nil, true, ""},
|
||||
teeErrorTestCase{fmt.Errorf("error!"), nil, false, "1: error!"},
|
||||
teeErrorTestCase{nil, fmt.Errorf("error!"), false, "2: error!"},
|
||||
teeErrorTestCase{fmt.Errorf("error!"), fmt.Errorf("error!"), false, `1: error!
|
||||
2: error!`},
|
||||
}
|
||||
|
||||
for i, tc := range tcs {
|
||||
teeError := cmds.TeeError{tc.err1, tc.err2}
|
||||
if teeError.BothNil() != tc.bothNil {
|
||||
t.Fatalf("BothNil()/%d: expected %v but got %v", i, tc.bothNil, teeError.BothNil())
|
||||
}
|
||||
|
||||
if teeError.Error() != tc.errString {
|
||||
t.Fatalf("Error()/%d: expected %v but got %v", i, tc.errString, teeError.Error())
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
194
commands/legacy/request.go
Normal file
194
commands/legacy/request.go
Normal file
@ -0,0 +1,194 @@
|
||||
package legacy
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"reflect"
|
||||
|
||||
"gx/ipfs/QmTwKPLyeRKuDawuy6CAn1kRj1FVoqBEM8sviAUWN7NW9K/go-ipfs-cmds"
|
||||
"gx/ipfs/QmVD1W3MC8Hk1WZgFQPWWmBECJ3X72BgUYf9eCQ4PGzPps/go-ipfs-cmdkit"
|
||||
"gx/ipfs/QmVD1W3MC8Hk1WZgFQPWWmBECJ3X72BgUYf9eCQ4PGzPps/go-ipfs-cmdkit/files"
|
||||
|
||||
oldcmds "github.com/ipfs/go-ipfs/commands"
|
||||
)
|
||||
|
||||
// requestWrapper implements a oldcmds.Request from an Request
|
||||
type requestWrapper struct {
|
||||
req *cmds.Request
|
||||
ctx *oldcmds.Context
|
||||
}
|
||||
|
||||
// InvocContext retuns the invocation context of the oldcmds.Request.
|
||||
// It is faked using OldContext().
|
||||
func (r *requestWrapper) InvocContext() *oldcmds.Context {
|
||||
return r.ctx
|
||||
}
|
||||
|
||||
// SetInvocContext sets the invocation context. First the context is converted
|
||||
// to a Context using NewContext().
|
||||
func (r *requestWrapper) SetInvocContext(ctx oldcmds.Context) {
|
||||
r.ctx = &ctx
|
||||
}
|
||||
|
||||
// Command is an empty stub.
|
||||
func (r *requestWrapper) Command() *oldcmds.Command { return nil }
|
||||
|
||||
func (r *requestWrapper) Arguments() []string {
|
||||
return r.req.Arguments
|
||||
}
|
||||
|
||||
func (r *requestWrapper) Context() context.Context {
|
||||
return r.req.Context
|
||||
}
|
||||
|
||||
func (r *requestWrapper) ConvertOptions() error {
|
||||
return convertOptions(r.req)
|
||||
}
|
||||
|
||||
func (r *requestWrapper) Files() files.File {
|
||||
return r.req.Files
|
||||
}
|
||||
|
||||
func (r *requestWrapper) Option(name string) *cmdkit.OptionValue {
|
||||
var option cmdkit.Option
|
||||
|
||||
for _, def := range r.req.Command.Options {
|
||||
for _, optName := range def.Names() {
|
||||
if name == optName {
|
||||
option = def
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
if option == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
// try all the possible names, break if we find a value
|
||||
for _, n := range option.Names() {
|
||||
val, found := r.req.Options[n]
|
||||
if found {
|
||||
return &cmdkit.OptionValue{val, found, option}
|
||||
}
|
||||
}
|
||||
|
||||
return &cmdkit.OptionValue{option.Default(), false, option}
|
||||
}
|
||||
|
||||
func (r *requestWrapper) Options() cmdkit.OptMap {
|
||||
return r.req.Options
|
||||
}
|
||||
|
||||
func (r *requestWrapper) Path() []string {
|
||||
return r.req.Path
|
||||
}
|
||||
|
||||
func (r *requestWrapper) SetArguments(args []string) {
|
||||
r.req.Arguments = args
|
||||
}
|
||||
|
||||
func (r *requestWrapper) SetFiles(f files.File) {
|
||||
r.req.Files = f
|
||||
}
|
||||
|
||||
func (r *requestWrapper) SetOption(name string, v interface{}) {
|
||||
r.req.SetOption(name, v)
|
||||
}
|
||||
|
||||
func (r *requestWrapper) SetOptions(om cmdkit.OptMap) error {
|
||||
r.req.Options = om
|
||||
return convertOptions(r.req)
|
||||
}
|
||||
|
||||
func (r *requestWrapper) SetRootContext(ctx context.Context) error {
|
||||
r.req.Context = ctx
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *requestWrapper) Stdin() io.Reader {
|
||||
return os.Stdin
|
||||
}
|
||||
|
||||
func (r *requestWrapper) StringArguments() []string {
|
||||
return r.req.Arguments
|
||||
}
|
||||
|
||||
func (r *requestWrapper) Values() map[string]interface{} {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *requestWrapper) VarArgs(f func(string) error) error {
|
||||
if len(r.req.Arguments) >= len(r.req.Command.Arguments) {
|
||||
for _, arg := range r.req.Arguments {
|
||||
err := f(arg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
s, err := r.req.BodyArgs()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for s.Scan() {
|
||||
err = f(s.Text())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// copied from go-ipfs-cmds/request.go
|
||||
func convertOptions(req *cmds.Request) error {
|
||||
optDefSlice := req.Command.Options
|
||||
|
||||
optDefs := make(map[string]cmdkit.Option)
|
||||
for _, def := range optDefSlice {
|
||||
for _, name := range def.Names() {
|
||||
optDefs[name] = def
|
||||
}
|
||||
}
|
||||
|
||||
for k, v := range req.Options {
|
||||
opt, ok := optDefs[k]
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
|
||||
kind := reflect.TypeOf(v).Kind()
|
||||
if kind != opt.Type() {
|
||||
if str, ok := v.(string); ok {
|
||||
val, err := opt.Parse(str)
|
||||
if err != nil {
|
||||
value := fmt.Sprintf("value %q", v)
|
||||
if len(str) == 0 {
|
||||
value = "empty value"
|
||||
}
|
||||
return fmt.Errorf("Could not convert %q to type %q (for option %q)",
|
||||
value, opt.Type().String(), "-"+k)
|
||||
}
|
||||
req.Options[k] = val
|
||||
|
||||
} else {
|
||||
return fmt.Errorf("Option %q should be type %q, but got type %q",
|
||||
k, opt.Type().String(), kind.String())
|
||||
}
|
||||
}
|
||||
|
||||
for _, name := range opt.Names() {
|
||||
if _, ok := req.Options[name]; name != k && ok {
|
||||
return fmt.Errorf("Duplicate command options were provided (%q and %q)",
|
||||
k, name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
205
commands/legacy/response.go
Normal file
205
commands/legacy/response.go
Normal file
@ -0,0 +1,205 @@
|
||||
package legacy
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
"os"
|
||||
"reflect"
|
||||
"sync"
|
||||
|
||||
"gx/ipfs/QmTwKPLyeRKuDawuy6CAn1kRj1FVoqBEM8sviAUWN7NW9K/go-ipfs-cmds"
|
||||
"gx/ipfs/QmVD1W3MC8Hk1WZgFQPWWmBECJ3X72BgUYf9eCQ4PGzPps/go-ipfs-cmdkit"
|
||||
|
||||
oldcmds "github.com/ipfs/go-ipfs/commands"
|
||||
)
|
||||
|
||||
// responseWrapper wraps Response and implements olcdms.Response.
|
||||
// It embeds a Response so some methods are taken from that.
|
||||
type responseWrapper struct {
|
||||
cmds.Response
|
||||
|
||||
out interface{}
|
||||
}
|
||||
|
||||
// Request returns a (faked) oldcmds.Request
|
||||
func (rw *responseWrapper) Request() oldcmds.Request {
|
||||
return &requestWrapper{rw.Response.Request(), nil}
|
||||
}
|
||||
|
||||
// Output returns either a <-chan interface{} on which you can receive the
|
||||
// emitted values, or an emitted io.Reader
|
||||
func (rw *responseWrapper) Output() interface{} {
|
||||
//if not called before
|
||||
if rw.out == nil {
|
||||
// get first emitted value
|
||||
x, err := rw.Next()
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
if e, ok := x.(*cmdkit.Error); ok {
|
||||
ch := make(chan interface{})
|
||||
log.Error(e)
|
||||
close(ch)
|
||||
return (<-chan interface{})(ch)
|
||||
}
|
||||
|
||||
switch v := x.(type) {
|
||||
case io.Reader:
|
||||
// if it's a reader, set it
|
||||
rw.out = v
|
||||
default:
|
||||
// if it is something else, create a channel and copy values from next in there
|
||||
ch := make(chan interface{})
|
||||
rw.out = (<-chan interface{})(ch)
|
||||
|
||||
go func() {
|
||||
defer close(ch)
|
||||
ch <- v
|
||||
|
||||
for {
|
||||
v, err := rw.Next()
|
||||
|
||||
if err == io.EOF || err == context.Canceled {
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
return
|
||||
}
|
||||
|
||||
ch <- v
|
||||
}
|
||||
}()
|
||||
}
|
||||
}
|
||||
|
||||
// if we have it already, return existing value
|
||||
return rw.out
|
||||
}
|
||||
|
||||
// SetError is an empty stub
|
||||
func (rw *responseWrapper) SetError(error, cmdkit.ErrorType) {}
|
||||
|
||||
// SetOutput is an empty stub
|
||||
func (rw *responseWrapper) SetOutput(interface{}) {}
|
||||
|
||||
// SetLength is an empty stub
|
||||
func (rw *responseWrapper) SetLength(uint64) {}
|
||||
|
||||
// SetCloser is an empty stub
|
||||
func (rw *responseWrapper) SetCloser(io.Closer) {}
|
||||
|
||||
// Close is an empty stub
|
||||
func (rw *responseWrapper) Close() error { return nil }
|
||||
|
||||
// Marshal is an empty stub
|
||||
func (rw *responseWrapper) Marshal() (io.Reader, error) { return nil, nil }
|
||||
|
||||
// Reader is an empty stub
|
||||
func (rw *responseWrapper) Reader() (io.Reader, error) { return nil, nil }
|
||||
|
||||
// Stdout returns os.Stdout
|
||||
func (rw *responseWrapper) Stdout() io.Writer { return os.Stdout }
|
||||
|
||||
// Stderr returns os.Stderr
|
||||
func (rw *responseWrapper) Stderr() io.Writer { return os.Stderr }
|
||||
|
||||
// fakeResponse implements oldcmds.Response and takes a ResponseEmitter
|
||||
type fakeResponse struct {
|
||||
req oldcmds.Request
|
||||
re cmds.ResponseEmitter
|
||||
out interface{}
|
||||
wait chan struct{}
|
||||
once sync.Once
|
||||
}
|
||||
|
||||
// Send emits the value(s) stored in r.out on the ResponseEmitter
|
||||
func (r *fakeResponse) Send(errCh chan<- error) {
|
||||
defer close(errCh)
|
||||
|
||||
out := r.Output()
|
||||
if out == nil {
|
||||
return
|
||||
}
|
||||
|
||||
if ch, ok := out.(chan interface{}); ok {
|
||||
out = (<-chan interface{})(ch)
|
||||
}
|
||||
|
||||
err := r.re.Emit(out)
|
||||
errCh <- err
|
||||
return
|
||||
}
|
||||
|
||||
// Request returns the oldcmds.Request that belongs to this Response
|
||||
func (r *fakeResponse) Request() oldcmds.Request {
|
||||
return r.req
|
||||
}
|
||||
|
||||
// SetError forwards the call to the underlying ResponseEmitter
|
||||
func (r *fakeResponse) SetError(err error, code cmdkit.ErrorType) {
|
||||
defer r.once.Do(func() { close(r.wait) })
|
||||
r.re.SetError(err, code)
|
||||
}
|
||||
|
||||
// Error is an empty stub
|
||||
func (r *fakeResponse) Error() *cmdkit.Error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetOutput sets the output variable to the passed value
|
||||
func (r *fakeResponse) SetOutput(v interface{}) {
|
||||
t := reflect.TypeOf(v)
|
||||
_, isReader := v.(io.Reader)
|
||||
|
||||
if t != nil && t.Kind() != reflect.Chan && !isReader {
|
||||
v = cmds.Single{v}
|
||||
}
|
||||
|
||||
r.out = v
|
||||
r.once.Do(func() { close(r.wait) })
|
||||
}
|
||||
|
||||
// Output returns the output variable
|
||||
func (r *fakeResponse) Output() interface{} {
|
||||
<-r.wait
|
||||
return r.out
|
||||
}
|
||||
|
||||
// SetLength forwards the call to the underlying ResponseEmitter
|
||||
func (r *fakeResponse) SetLength(l uint64) {
|
||||
r.re.SetLength(l)
|
||||
}
|
||||
|
||||
// Length is an empty stub
|
||||
func (r *fakeResponse) Length() uint64 {
|
||||
return 0
|
||||
}
|
||||
|
||||
// Close forwards the call to the underlying ResponseEmitter
|
||||
func (r *fakeResponse) Close() error {
|
||||
return r.re.Close()
|
||||
}
|
||||
|
||||
// SetCloser is an empty stub
|
||||
func (r *fakeResponse) SetCloser(io.Closer) {}
|
||||
|
||||
// Reader is an empty stub
|
||||
func (r *fakeResponse) Reader() (io.Reader, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// Marshal is an empty stub
|
||||
func (r *fakeResponse) Marshal() (io.Reader, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// Stdout returns os.Stdout
|
||||
func (r *fakeResponse) Stdout() io.Writer {
|
||||
return os.Stdout
|
||||
}
|
||||
|
||||
// Stderr returns os.Stderr
|
||||
func (r *fakeResponse) Stderr() io.Writer {
|
||||
return os.Stderr
|
||||
}
|
||||
55
commands/legacy/responseemitter.go
Normal file
55
commands/legacy/responseemitter.go
Normal file
@ -0,0 +1,55 @@
|
||||
package legacy
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"gx/ipfs/QmVD1W3MC8Hk1WZgFQPWWmBECJ3X72BgUYf9eCQ4PGzPps/go-ipfs-cmdkit"
|
||||
|
||||
oldcmds "github.com/ipfs/go-ipfs/commands"
|
||||
)
|
||||
|
||||
// wrappedResponseEmitter implements a ResponseEmitter by forwarding everything to an oldcmds.Response
|
||||
type wrappedResponseEmitter struct {
|
||||
r oldcmds.Response
|
||||
}
|
||||
|
||||
// SetLength forwards the call to the underlying oldcmds.Response
|
||||
func (re *wrappedResponseEmitter) SetLength(l uint64) {
|
||||
re.r.SetLength(l)
|
||||
}
|
||||
|
||||
// SetError forwards the call to the underlying oldcmds.Response
|
||||
func (re *wrappedResponseEmitter) SetError(err interface{}, code cmdkit.ErrorType) {
|
||||
re.r.SetError(fmt.Errorf("%v", err), code)
|
||||
}
|
||||
|
||||
// Close forwards the call to the underlying oldcmds.Response
|
||||
func (re *wrappedResponseEmitter) Close() error {
|
||||
return re.r.Close()
|
||||
}
|
||||
|
||||
// Emit sends the value to the underlying oldcmds.Response
|
||||
func (re *wrappedResponseEmitter) Emit(v interface{}) error {
|
||||
if re.r.Output() == nil {
|
||||
switch c := v.(type) {
|
||||
case io.Reader:
|
||||
re.r.SetOutput(c)
|
||||
return nil
|
||||
case chan interface{}:
|
||||
re.r.SetOutput(c)
|
||||
return nil
|
||||
case <-chan interface{}:
|
||||
re.r.SetOutput(c)
|
||||
return nil
|
||||
default:
|
||||
re.r.SetOutput(make(chan interface{}))
|
||||
}
|
||||
}
|
||||
|
||||
go func() {
|
||||
re.r.Output().(chan interface{}) <- v
|
||||
}()
|
||||
|
||||
return nil
|
||||
}
|
||||
@ -15,8 +15,8 @@ import (
|
||||
"github.com/ipfs/go-ipfs/repo/config"
|
||||
u "gx/ipfs/QmPsAfmDBnZN3kZGSuNwvCNDZiHneERSKmRcFyG3UkvcT3/go-ipfs-util"
|
||||
|
||||
"gx/ipfs/QmQp2a2Hhb7F6eK2A5hN8f9aJy4mtkEikL9Zj4cgB7d1dD/go-ipfs-cmdkit"
|
||||
"gx/ipfs/QmQp2a2Hhb7F6eK2A5hN8f9aJy4mtkEikL9Zj4cgB7d1dD/go-ipfs-cmdkit/files"
|
||||
"gx/ipfs/QmVD1W3MC8Hk1WZgFQPWWmBECJ3X72BgUYf9eCQ4PGzPps/go-ipfs-cmdkit"
|
||||
"gx/ipfs/QmVD1W3MC8Hk1WZgFQPWWmBECJ3X72BgUYf9eCQ4PGzPps/go-ipfs-cmdkit/files"
|
||||
)
|
||||
|
||||
type Context struct {
|
||||
@ -63,6 +63,17 @@ func (c *Context) NodeWithoutConstructing() *core.IpfsNode {
|
||||
return c.node
|
||||
}
|
||||
|
||||
// RootContext returns the node's context.
|
||||
func (c *Context) RootContext() context.Context {
|
||||
n, err := c.GetNode()
|
||||
if err != nil {
|
||||
log.Debug("error getting node: ", err)
|
||||
return nil
|
||||
}
|
||||
|
||||
return n.Context()
|
||||
}
|
||||
|
||||
// Request represents a call to a command from a consumer
|
||||
type Request interface {
|
||||
Path() []string
|
||||
|
||||
@ -9,7 +9,8 @@ import (
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"gx/ipfs/QmQp2a2Hhb7F6eK2A5hN8f9aJy4mtkEikL9Zj4cgB7d1dD/go-ipfs-cmdkit"
|
||||
cmds "gx/ipfs/QmTwKPLyeRKuDawuy6CAn1kRj1FVoqBEM8sviAUWN7NW9K/go-ipfs-cmds"
|
||||
cmdkit "gx/ipfs/QmVD1W3MC8Hk1WZgFQPWWmBECJ3X72BgUYf9eCQ4PGzPps/go-ipfs-cmdkit"
|
||||
)
|
||||
|
||||
// ErrorType signfies a category of errors
|
||||
@ -148,7 +149,7 @@ func (r *response) Marshal() (io.Reader, error) {
|
||||
return bytes.NewReader([]byte{}), nil
|
||||
}
|
||||
|
||||
enc, found, err := r.req.Option(cmdkit.EncShort).String()
|
||||
enc, found, err := r.req.Option(cmds.EncShort).String()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@ -6,7 +6,8 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
cmdkit "gx/ipfs/QmQp2a2Hhb7F6eK2A5hN8f9aJy4mtkEikL9Zj4cgB7d1dD/go-ipfs-cmdkit"
|
||||
cmds "gx/ipfs/QmTwKPLyeRKuDawuy6CAn1kRj1FVoqBEM8sviAUWN7NW9K/go-ipfs-cmds"
|
||||
cmdkit "gx/ipfs/QmVD1W3MC8Hk1WZgFQPWWmBECJ3X72BgUYf9eCQ4PGzPps/go-ipfs-cmdkit"
|
||||
)
|
||||
|
||||
type TestOutput struct {
|
||||
@ -28,7 +29,7 @@ func TestMarshalling(t *testing.T) {
|
||||
t.Error("Should have failed (no encoding type specified in request)")
|
||||
}
|
||||
|
||||
req.SetOption(cmdkit.EncShort, JSON)
|
||||
req.SetOption(cmds.EncShort, JSON)
|
||||
|
||||
reader, err := res.Marshal()
|
||||
if err != nil {
|
||||
|
||||
@ -11,7 +11,7 @@ import (
|
||||
cmds "github.com/ipfs/go-ipfs/commands"
|
||||
e "github.com/ipfs/go-ipfs/core/commands/e"
|
||||
|
||||
"gx/ipfs/QmQp2a2Hhb7F6eK2A5hN8f9aJy4mtkEikL9Zj4cgB7d1dD/go-ipfs-cmdkit"
|
||||
"gx/ipfs/QmVD1W3MC8Hk1WZgFQPWWmBECJ3X72BgUYf9eCQ4PGzPps/go-ipfs-cmdkit"
|
||||
)
|
||||
|
||||
var ActiveReqsCmd = &cmds.Command{
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
@ -17,9 +18,10 @@ import (
|
||||
mfs "github.com/ipfs/go-ipfs/mfs"
|
||||
ft "github.com/ipfs/go-ipfs/unixfs"
|
||||
|
||||
"gx/ipfs/QmP9vZfc5WSjfGTXmwX2EcicMFzmZ6fXn7HTdKYat6ccmH/go-ipfs-cmds"
|
||||
"gx/ipfs/QmQp2a2Hhb7F6eK2A5hN8f9aJy4mtkEikL9Zj4cgB7d1dD/go-ipfs-cmdkit"
|
||||
"gx/ipfs/QmQp2a2Hhb7F6eK2A5hN8f9aJy4mtkEikL9Zj4cgB7d1dD/go-ipfs-cmdkit/files"
|
||||
"gx/ipfs/QmTwKPLyeRKuDawuy6CAn1kRj1FVoqBEM8sviAUWN7NW9K/go-ipfs-cmds"
|
||||
"gx/ipfs/QmVD1W3MC8Hk1WZgFQPWWmBECJ3X72BgUYf9eCQ4PGzPps/go-ipfs-cmdkit"
|
||||
"gx/ipfs/QmVD1W3MC8Hk1WZgFQPWWmBECJ3X72BgUYf9eCQ4PGzPps/go-ipfs-cmdkit/files"
|
||||
mh "gx/ipfs/QmYeKnKpubCMRiq3PGZcTREErthbb5Q9cXsCoSkD9bjEBd/go-multihash"
|
||||
"gx/ipfs/QmeWjRodbcZFKe5tMN7poEx3izym6osrLSnTLf9UjJZBbs/pb"
|
||||
)
|
||||
@ -103,7 +105,7 @@ You can now check what blocks have been created by:
|
||||
cmdkit.FileArg("path", true, true, "The path to a file to be added to ipfs.").EnableRecursive().EnableStdin(),
|
||||
},
|
||||
Options: []cmdkit.Option{
|
||||
cmdkit.OptionRecursivePath, // a builtin option that allows recursive paths (-r, --recursive)
|
||||
cmds.OptionRecursivePath, // a builtin option that allows recursive paths (-r, --recursive)
|
||||
cmdkit.BoolOption(quietOptionName, "q", "Write minimal output."),
|
||||
cmdkit.BoolOption(quieterOptionName, "Q", "Write only final hash."),
|
||||
cmdkit.BoolOption(silentOptionName, "Write no output."),
|
||||
@ -120,24 +122,24 @@ You can now check what blocks have been created by:
|
||||
cmdkit.IntOption(cidVersionOptionName, "Cid version. Non-zero value will change default of 'raw-leaves' to true. (experimental)").WithDefault(0),
|
||||
cmdkit.StringOption(hashOptionName, "Hash function to use. Will set Cid version to 1 if used. (experimental)").WithDefault("sha2-256"),
|
||||
},
|
||||
PreRun: func(req cmds.Request) error {
|
||||
quiet, _, _ := req.Option(quietOptionName).Bool()
|
||||
quieter, _, _ := req.Option(quieterOptionName).Bool()
|
||||
PreRun: func(req *cmds.Request, env interface{}) error {
|
||||
quiet, _ := req.Options[quietOptionName].(bool)
|
||||
quieter, _ := req.Options[quieterOptionName].(bool)
|
||||
quiet = quiet || quieter
|
||||
|
||||
silent, _, _ := req.Option(silentOptionName).Bool()
|
||||
silent, _ := req.Options[silentOptionName].(bool)
|
||||
|
||||
if quiet || silent {
|
||||
return nil
|
||||
}
|
||||
|
||||
// ipfs cli progress bar defaults to true unless quiet or silent is used
|
||||
_, found, _ := req.Option(progressOptionName).Bool()
|
||||
_, found := req.Options[progressOptionName].(bool)
|
||||
if !found {
|
||||
req.SetOption(progressOptionName, true)
|
||||
req.Options[progressOptionName] = true
|
||||
}
|
||||
|
||||
sizeFile, ok := req.Files().(files.SizeFile)
|
||||
sizeFile, ok := req.Files.(files.SizeFile)
|
||||
if !ok {
|
||||
// we don't need to error, the progress bar just won't know how big the files are
|
||||
log.Warning("cannot determine size of input file")
|
||||
@ -145,7 +147,7 @@ You can now check what blocks have been created by:
|
||||
}
|
||||
|
||||
sizeCh := make(chan int64, 1)
|
||||
req.Values()["size"] = sizeCh
|
||||
req.Context = context.WithValue(req.Context, "size", sizeCh)
|
||||
|
||||
go func() {
|
||||
size, err := sizeFile.Size()
|
||||
@ -160,8 +162,9 @@ You can now check what blocks have been created by:
|
||||
|
||||
return nil
|
||||
},
|
||||
Run: func(req cmds.Request, res cmds.ResponseEmitter) {
|
||||
n, err := req.InvocContext().GetNode()
|
||||
Run: func(req *cmds.Request, res cmds.ResponseEmitter, env interface{}) {
|
||||
fmt.Printf("%#v\n", req)
|
||||
n, err := GetNode(env)
|
||||
if err != nil {
|
||||
res.SetError(err, cmdkit.ErrNormal)
|
||||
return
|
||||
@ -180,19 +183,19 @@ You can now check what blocks have been created by:
|
||||
// return
|
||||
//}
|
||||
|
||||
progress, _, _ := req.Option(progressOptionName).Bool()
|
||||
trickle, _, _ := req.Option(trickleOptionName).Bool()
|
||||
wrap, _, _ := req.Option(wrapOptionName).Bool()
|
||||
hash, _, _ := req.Option(onlyHashOptionName).Bool()
|
||||
hidden, _, _ := req.Option(hiddenOptionName).Bool()
|
||||
silent, _, _ := req.Option(silentOptionName).Bool()
|
||||
chunker, _, _ := req.Option(chunkerOptionName).String()
|
||||
dopin, _, _ := req.Option(pinOptionName).Bool()
|
||||
rawblks, rbset, _ := req.Option(rawLeavesOptionName).Bool()
|
||||
nocopy, _, _ := req.Option(noCopyOptionName).Bool()
|
||||
fscache, _, _ := req.Option(fstoreCacheOptionName).Bool()
|
||||
cidVer, _, _ := req.Option(cidVersionOptionName).Int()
|
||||
hashFunStr, hfset, _ := req.Option(hashOptionName).String()
|
||||
progress, _ := req.Options[progressOptionName].(bool)
|
||||
trickle, _ := req.Options[trickleOptionName].(bool)
|
||||
wrap, _ := req.Options[wrapOptionName].(bool)
|
||||
hash, _ := req.Options[onlyHashOptionName].(bool)
|
||||
hidden, _ := req.Options[hiddenOptionName].(bool)
|
||||
silent, _ := req.Options[silentOptionName].(bool)
|
||||
chunker, _ := req.Options[chunkerOptionName].(string)
|
||||
dopin, _ := req.Options[pinOptionName].(bool)
|
||||
rawblks, rbset := req.Options[rawLeavesOptionName].(bool)
|
||||
nocopy, _ := req.Options[noCopyOptionName].(bool)
|
||||
fscache, _ := req.Options[fstoreCacheOptionName].(bool)
|
||||
cidVer, _ := req.Options[cidVersionOptionName].(int)
|
||||
hashFunStr, hfset := req.Options[hashOptionName].(string)
|
||||
|
||||
if nocopy && !cfg.Experimental.FilestoreEnabled {
|
||||
res.SetError(errors.New("filestore is not enabled, see https://git.io/vy4XN"),
|
||||
@ -209,14 +212,10 @@ You can now check what blocks have been created by:
|
||||
return
|
||||
}
|
||||
|
||||
if hfset && cidVer == 0 {
|
||||
if hfset && hashFunStr != "sha2-256" && cidVer == 0 {
|
||||
cidVer = 1
|
||||
}
|
||||
|
||||
if cidVer >= 1 && !rbset {
|
||||
rawblks = true
|
||||
}
|
||||
|
||||
prefix, err := dag.PrefixForCidVersion(cidVer)
|
||||
if err != nil {
|
||||
res.SetError(err, cmdkit.ErrNormal)
|
||||
@ -251,7 +250,7 @@ You can now check what blocks have been created by:
|
||||
}
|
||||
|
||||
exch := n.Exchange
|
||||
local, _, _ := req.Option("local").Bool()
|
||||
local, _ := req.Options["local"].(bool)
|
||||
if local {
|
||||
exch = offline.Exchange(addblockstore)
|
||||
}
|
||||
@ -261,7 +260,7 @@ You can now check what blocks have been created by:
|
||||
|
||||
outChan := make(chan interface{}, adderOutChanSize)
|
||||
|
||||
fileAdder, err := coreunix.NewAdder(req.Context(), n.Pinning, n.Blockstore, dserv)
|
||||
fileAdder, err := coreunix.NewAdder(req.Context, n.Pinning, n.Blockstore, dserv)
|
||||
if err != nil {
|
||||
res.SetError(err, cmdkit.ErrNormal)
|
||||
return
|
||||
@ -281,7 +280,7 @@ You can now check what blocks have been created by:
|
||||
|
||||
if hash {
|
||||
md := dagtest.Mock()
|
||||
mr, err := mfs.NewRoot(req.Context(), md, ft.EmptyDirNode(), nil)
|
||||
mr, err := mfs.NewRoot(req.Context, md, ft.EmptyDirNode(), nil)
|
||||
if err != nil {
|
||||
res.SetError(err, cmdkit.ErrNormal)
|
||||
return
|
||||
@ -325,7 +324,7 @@ You can now check what blocks have been created by:
|
||||
var err error
|
||||
defer func() { errCh <- err }()
|
||||
defer close(outChan)
|
||||
err = addAllAndPin(req.Files())
|
||||
err = addAllAndPin(req.Files)
|
||||
}()
|
||||
|
||||
defer res.Close()
|
||||
@ -340,21 +339,19 @@ You can now check what blocks have been created by:
|
||||
res.SetError(err, cmdkit.ErrNormal)
|
||||
}
|
||||
},
|
||||
PostRun: map[cmds.EncodingType]func(cmds.Request, cmds.ResponseEmitter) cmds.ResponseEmitter{
|
||||
cmds.CLI: func(req cmds.Request, re cmds.ResponseEmitter) cmds.ResponseEmitter {
|
||||
ctx := req.Context()
|
||||
|
||||
PostRun: cmds.PostRunMap{
|
||||
cmds.CLI: func(req *cmds.Request, re cmds.ResponseEmitter) cmds.ResponseEmitter {
|
||||
reNext, res := cmds.NewChanResponsePair(req)
|
||||
outChan := make(chan interface{})
|
||||
|
||||
progressBar := func(wait chan struct{}) {
|
||||
defer close(wait)
|
||||
|
||||
quiet, _, _ := req.Option(quietOptionName).Bool()
|
||||
quieter, _, _ := req.Option(quieterOptionName).Bool()
|
||||
quiet, _ := req.Options[quietOptionName].(bool)
|
||||
quieter, _ := req.Options[quieterOptionName].(bool)
|
||||
quiet = quiet || quieter
|
||||
|
||||
progress, _, _ := req.Option(progressOptionName).Bool()
|
||||
progress, _ := req.Options[progressOptionName].(bool)
|
||||
|
||||
var bar *pb.ProgressBar
|
||||
if progress {
|
||||
@ -367,10 +364,7 @@ You can now check what blocks have been created by:
|
||||
}
|
||||
|
||||
var sizeChan chan int64
|
||||
s, found := req.Values()["size"]
|
||||
if found {
|
||||
sizeChan = s.(chan int64)
|
||||
}
|
||||
sizeChan, _ = req.Context.Value("size").(chan int64)
|
||||
|
||||
lastFile := ""
|
||||
lastHash := ""
|
||||
@ -431,6 +425,9 @@ You can now check what blocks have been created by:
|
||||
bar.ShowBar = true
|
||||
bar.ShowTimeLeft = true
|
||||
}
|
||||
case <-req.Context.Done():
|
||||
re.SetError(req.Context.Err(), cmdkit.ErrNormal)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -459,8 +456,8 @@ You can now check what blocks have been created by:
|
||||
|
||||
select {
|
||||
case outChan <- v:
|
||||
case <-ctx.Done():
|
||||
re.SetError(ctx.Err(), cmdkit.ErrNormal)
|
||||
case <-req.Context.Done():
|
||||
re.SetError(req.Context.Err(), cmdkit.ErrNormal)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
@ -6,13 +6,15 @@ import (
|
||||
"io"
|
||||
|
||||
oldcmds "github.com/ipfs/go-ipfs/commands"
|
||||
lgc "github.com/ipfs/go-ipfs/commands/legacy"
|
||||
e "github.com/ipfs/go-ipfs/core/commands/e"
|
||||
bitswap "github.com/ipfs/go-ipfs/exchange/bitswap"
|
||||
decision "github.com/ipfs/go-ipfs/exchange/bitswap/decision"
|
||||
|
||||
cmds "gx/ipfs/QmP9vZfc5WSjfGTXmwX2EcicMFzmZ6fXn7HTdKYat6ccmH/go-ipfs-cmds"
|
||||
"gx/ipfs/QmPSBJL4momYnE7DcUyk2DVhD6rH488ZmHBGLbxNdhU44K/go-humanize"
|
||||
cmdkit "gx/ipfs/QmQp2a2Hhb7F6eK2A5hN8f9aJy4mtkEikL9Zj4cgB7d1dD/go-ipfs-cmdkit"
|
||||
cmds "gx/ipfs/QmTwKPLyeRKuDawuy6CAn1kRj1FVoqBEM8sviAUWN7NW9K/go-ipfs-cmds"
|
||||
cmdkit "gx/ipfs/QmVD1W3MC8Hk1WZgFQPWWmBECJ3X72BgUYf9eCQ4PGzPps/go-ipfs-cmdkit"
|
||||
peer "gx/ipfs/QmWNY7dV54ZDYmTA1ykVdwNCqC11mpU4zSUp6XDpLTH9eG/go-libp2p-peer"
|
||||
cid "gx/ipfs/QmeSrf6pzut73u6zLQkRFQ3ygt3k6XFT2kjdYP8Tnkwwyg/go-cid"
|
||||
)
|
||||
@ -24,13 +26,11 @@ var BitswapCmd = &cmds.Command{
|
||||
},
|
||||
|
||||
Subcommands: map[string]*cmds.Command{
|
||||
"stat": bitswapStatCmd,
|
||||
},
|
||||
OldSubcommands: map[string]*oldcmds.Command{
|
||||
"wantlist": showWantlistCmd,
|
||||
"unwant": unwantCmd,
|
||||
"ledger": ledgerCmd,
|
||||
"reprovide": reprovideCmd,
|
||||
"stat": bitswapStatCmd,
|
||||
"wantlist": lgc.NewCommand(showWantlistCmd),
|
||||
"unwant": lgc.NewCommand(unwantCmd),
|
||||
"ledger": lgc.NewCommand(ledgerCmd),
|
||||
"reprovide": lgc.NewCommand(reprovideCmd),
|
||||
},
|
||||
}
|
||||
|
||||
@ -140,8 +140,8 @@ var bitswapStatCmd = &cmds.Command{
|
||||
ShortDescription: ``,
|
||||
},
|
||||
Type: bitswap.Stat{},
|
||||
Run: func(req cmds.Request, res cmds.ResponseEmitter) {
|
||||
nd, err := req.InvocContext().GetNode()
|
||||
Run: func(req *cmds.Request, res cmds.ResponseEmitter, env interface{}) {
|
||||
nd, err := GetNode(env)
|
||||
if err != nil {
|
||||
res.SetError(err, cmdkit.ErrNormal)
|
||||
return
|
||||
@ -167,7 +167,7 @@ var bitswapStatCmd = &cmds.Command{
|
||||
cmds.EmitOnce(res, st)
|
||||
},
|
||||
Encoders: cmds.EncoderMap{
|
||||
cmds.Text: cmds.MakeEncoder(func(req cmds.Request, w io.Writer, v interface{}) error {
|
||||
cmds.Text: cmds.MakeEncoder(func(req *cmds.Request, w io.Writer, v interface{}) error {
|
||||
out, ok := v.(*bitswap.Stat)
|
||||
if !ok {
|
||||
return e.TypeErr(out, v)
|
||||
|
||||
@ -2,6 +2,7 @@ package commands
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
@ -9,9 +10,9 @@ import (
|
||||
|
||||
util "github.com/ipfs/go-ipfs/blocks/blockstore/util"
|
||||
e "github.com/ipfs/go-ipfs/core/commands/e"
|
||||
"gx/ipfs/QmP9vZfc5WSjfGTXmwX2EcicMFzmZ6fXn7HTdKYat6ccmH/go-ipfs-cmds"
|
||||
"gx/ipfs/QmQp2a2Hhb7F6eK2A5hN8f9aJy4mtkEikL9Zj4cgB7d1dD/go-ipfs-cmdkit"
|
||||
|
||||
"gx/ipfs/QmTwKPLyeRKuDawuy6CAn1kRj1FVoqBEM8sviAUWN7NW9K/go-ipfs-cmds"
|
||||
"gx/ipfs/QmVD1W3MC8Hk1WZgFQPWWmBECJ3X72BgUYf9eCQ4PGzPps/go-ipfs-cmdkit"
|
||||
mh "gx/ipfs/QmYeKnKpubCMRiq3PGZcTREErthbb5Q9cXsCoSkD9bjEBd/go-multihash"
|
||||
blocks "gx/ipfs/QmYsEQydGrsxNZfAiskvQ76N2xE9hDQtSAkRSynwMiUK3c/go-block-format"
|
||||
cid "gx/ipfs/QmeSrf6pzut73u6zLQkRFQ3ygt3k6XFT2kjdYP8Tnkwwyg/go-cid"
|
||||
@ -60,8 +61,8 @@ on raw IPFS blocks. It outputs the following to stdout:
|
||||
Arguments: []cmdkit.Argument{
|
||||
cmdkit.StringArg("key", true, false, "The base58 multihash of an existing block to stat.").EnableStdin(),
|
||||
},
|
||||
Run: func(req cmds.Request, res cmds.ResponseEmitter) {
|
||||
b, err := getBlockForKey(req, req.Arguments()[0])
|
||||
Run: func(req *cmds.Request, res cmds.ResponseEmitter, env interface{}) {
|
||||
b, err := getBlockForKey(req.Context, env, req.Arguments[0])
|
||||
if err != nil {
|
||||
res.SetError(err, cmdkit.ErrNormal)
|
||||
return
|
||||
@ -77,7 +78,7 @@ on raw IPFS blocks. It outputs the following to stdout:
|
||||
},
|
||||
Type: BlockStat{},
|
||||
Encoders: cmds.EncoderMap{
|
||||
cmds.Text: cmds.MakeEncoder(func(req cmds.Request, w io.Writer, v interface{}) error {
|
||||
cmds.Text: cmds.MakeEncoder(func(req *cmds.Request, w io.Writer, v interface{}) error {
|
||||
bs, ok := v.(*BlockStat)
|
||||
if !ok {
|
||||
return e.TypeErr(bs, v)
|
||||
@ -100,8 +101,8 @@ It outputs to stdout, and <key> is a base58 encoded multihash.
|
||||
Arguments: []cmdkit.Argument{
|
||||
cmdkit.StringArg("key", true, false, "The base58 multihash of an existing block to get.").EnableStdin(),
|
||||
},
|
||||
Run: func(req cmds.Request, res cmds.ResponseEmitter) {
|
||||
b, err := getBlockForKey(req, req.Arguments()[0])
|
||||
Run: func(req *cmds.Request, res cmds.ResponseEmitter, env interface{}) {
|
||||
b, err := getBlockForKey(req.Context, env, req.Arguments[0])
|
||||
if err != nil {
|
||||
res.SetError(err, cmdkit.ErrNormal)
|
||||
return
|
||||
@ -131,14 +132,14 @@ It reads from stdin, and <key> is a base58 encoded multihash.
|
||||
cmdkit.StringOption("mhtype", "multihash hash function").WithDefault("sha2-256"),
|
||||
cmdkit.IntOption("mhlen", "multihash hash length").WithDefault(-1),
|
||||
},
|
||||
Run: func(req cmds.Request, res cmds.ResponseEmitter) {
|
||||
n, err := req.InvocContext().GetNode()
|
||||
Run: func(req *cmds.Request, res cmds.ResponseEmitter, env interface{}) {
|
||||
n, err := GetNode(env)
|
||||
if err != nil {
|
||||
res.SetError(err, cmdkit.ErrNormal)
|
||||
return
|
||||
}
|
||||
|
||||
file, err := req.Files().NextFile()
|
||||
file, err := req.Files.NextFile()
|
||||
if err != nil {
|
||||
res.SetError(err, cmdkit.ErrNormal)
|
||||
return
|
||||
@ -159,7 +160,7 @@ It reads from stdin, and <key> is a base58 encoded multihash.
|
||||
var pref cid.Prefix
|
||||
pref.Version = 1
|
||||
|
||||
format, _, _ := req.Option("format").String()
|
||||
format, _ := req.Options["format"].(string)
|
||||
formatval, ok := cid.Codecs[format]
|
||||
if !ok {
|
||||
res.SetError(fmt.Errorf("unrecognized format: %s", format), cmdkit.ErrNormal)
|
||||
@ -170,7 +171,7 @@ It reads from stdin, and <key> is a base58 encoded multihash.
|
||||
}
|
||||
pref.Codec = formatval
|
||||
|
||||
mhtype, _, _ := req.Option("mhtype").String()
|
||||
mhtype, _ := req.Options["mhtype"].(string)
|
||||
mhtval, ok := mh.Names[mhtype]
|
||||
if !ok {
|
||||
err := fmt.Errorf("unrecognized multihash function: %s", mhtype)
|
||||
@ -179,9 +180,9 @@ It reads from stdin, and <key> is a base58 encoded multihash.
|
||||
}
|
||||
pref.MhType = mhtval
|
||||
|
||||
mhlen, _, err := req.Option("mhlen").Int()
|
||||
if err != nil {
|
||||
res.SetError(err, cmdkit.ErrNormal)
|
||||
mhlen, ok := req.Options["mhlen"].(int)
|
||||
if !ok {
|
||||
res.SetError("missing option \"mhlen\"", cmdkit.ErrNormal)
|
||||
return
|
||||
}
|
||||
pref.MhLength = mhlen
|
||||
@ -213,7 +214,7 @@ It reads from stdin, and <key> is a base58 encoded multihash.
|
||||
}
|
||||
},
|
||||
Encoders: cmds.EncoderMap{
|
||||
cmds.Text: cmds.MakeEncoder(func(req cmds.Request, w io.Writer, v interface{}) error {
|
||||
cmds.Text: cmds.MakeEncoder(func(req *cmds.Request, w io.Writer, v interface{}) error {
|
||||
bs, ok := v.(*BlockStat)
|
||||
if !ok {
|
||||
return e.TypeErr(bs, v)
|
||||
@ -225,12 +226,12 @@ It reads from stdin, and <key> is a base58 encoded multihash.
|
||||
Type: BlockStat{},
|
||||
}
|
||||
|
||||
func getBlockForKey(req cmds.Request, skey string) (blocks.Block, error) {
|
||||
func getBlockForKey(ctx context.Context, env interface{}, skey string) (blocks.Block, error) {
|
||||
if len(skey) == 0 {
|
||||
return nil, fmt.Errorf("zero length cid invalid")
|
||||
}
|
||||
|
||||
n, err := req.InvocContext().GetNode()
|
||||
n, err := GetNode(env)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -240,7 +241,7 @@ func getBlockForKey(req cmds.Request, skey string) (blocks.Block, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
b, err := n.Blocks.GetBlock(req.Context(), c)
|
||||
b, err := n.Blocks.GetBlock(ctx, c)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -263,15 +264,15 @@ It takes a list of base58 encoded multihashs to remove.
|
||||
cmdkit.BoolOption("force", "f", "Ignore nonexistent blocks."),
|
||||
cmdkit.BoolOption("quiet", "q", "Write minimal output."),
|
||||
},
|
||||
Run: func(req cmds.Request, res cmds.ResponseEmitter) {
|
||||
n, err := req.InvocContext().GetNode()
|
||||
Run: func(req *cmds.Request, res cmds.ResponseEmitter, env interface{}) {
|
||||
n, err := GetNode(env)
|
||||
if err != nil {
|
||||
res.SetError(err, cmdkit.ErrNormal)
|
||||
return
|
||||
}
|
||||
hashes := req.Arguments()
|
||||
force, _, _ := req.Option("force").Bool()
|
||||
quiet, _, _ := req.Option("quiet").Bool()
|
||||
hashes := req.Arguments
|
||||
force, _ := req.Options["force"].(bool)
|
||||
quiet, _ := req.Options["quiet"].(bool)
|
||||
cids := make([]*cid.Cid, 0, len(hashes))
|
||||
for _, hash := range hashes {
|
||||
c, err := cid.Decode(hash)
|
||||
@ -298,8 +299,8 @@ It takes a list of base58 encoded multihashs to remove.
|
||||
log.Error(err)
|
||||
}
|
||||
},
|
||||
PostRun: map[cmds.EncodingType]func(cmds.Request, cmds.ResponseEmitter) cmds.ResponseEmitter{
|
||||
cmds.CLI: func(req cmds.Request, re cmds.ResponseEmitter) cmds.ResponseEmitter {
|
||||
PostRun: map[cmds.EncodingType]func(*cmds.Request, cmds.ResponseEmitter) cmds.ResponseEmitter{
|
||||
cmds.CLI: func(req *cmds.Request, re cmds.ResponseEmitter) cmds.ResponseEmitter {
|
||||
reNext, res := cmds.NewChanResponsePair(req)
|
||||
|
||||
go func() {
|
||||
|
||||
@ -12,7 +12,7 @@ import (
|
||||
config "github.com/ipfs/go-ipfs/repo/config"
|
||||
"github.com/ipfs/go-ipfs/repo/fsrepo"
|
||||
|
||||
"gx/ipfs/QmQp2a2Hhb7F6eK2A5hN8f9aJy4mtkEikL9Zj4cgB7d1dD/go-ipfs-cmdkit"
|
||||
"gx/ipfs/QmVD1W3MC8Hk1WZgFQPWWmBECJ3X72BgUYf9eCQ4PGzPps/go-ipfs-cmdkit"
|
||||
)
|
||||
|
||||
type BootstrapOutput struct {
|
||||
|
||||
@ -9,8 +9,8 @@ import (
|
||||
core "github.com/ipfs/go-ipfs/core"
|
||||
coreunix "github.com/ipfs/go-ipfs/core/coreunix"
|
||||
|
||||
cmds "gx/ipfs/QmP9vZfc5WSjfGTXmwX2EcicMFzmZ6fXn7HTdKYat6ccmH/go-ipfs-cmds"
|
||||
"gx/ipfs/QmQp2a2Hhb7F6eK2A5hN8f9aJy4mtkEikL9Zj4cgB7d1dD/go-ipfs-cmdkit"
|
||||
cmds "gx/ipfs/QmTwKPLyeRKuDawuy6CAn1kRj1FVoqBEM8sviAUWN7NW9K/go-ipfs-cmds"
|
||||
"gx/ipfs/QmVD1W3MC8Hk1WZgFQPWWmBECJ3X72BgUYf9eCQ4PGzPps/go-ipfs-cmdkit"
|
||||
)
|
||||
|
||||
const progressBarMinSize = 1024 * 1024 * 8 // show progress bar for outputs > 8MiB
|
||||
@ -28,8 +28,8 @@ var CatCmd = &cmds.Command{
|
||||
cmdkit.IntOption("offset", "o", "Byte offset to begin reading from."),
|
||||
cmdkit.IntOption("length", "l", "Maximum number of bytes to read."),
|
||||
},
|
||||
Run: func(req cmds.Request, res cmds.ResponseEmitter) {
|
||||
node, err := req.InvocContext().GetNode()
|
||||
Run: func(req *cmds.Request, res cmds.ResponseEmitter, env interface{}) {
|
||||
node, err := GetNode(env)
|
||||
if err != nil {
|
||||
res.SetError(err, cmdkit.ErrNormal)
|
||||
return
|
||||
@ -41,11 +41,8 @@ var CatCmd = &cmds.Command{
|
||||
return
|
||||
}
|
||||
}
|
||||
offset, _, err := req.Option("offset").Int()
|
||||
if err != nil {
|
||||
res.SetError(err, cmdkit.ErrNormal)
|
||||
return
|
||||
}
|
||||
|
||||
offset, _ := req.Options["offset"].(int)
|
||||
if offset < 0 {
|
||||
res.SetError(fmt.Errorf("Cannot specify negative offset."), cmdkit.ErrNormal)
|
||||
return
|
||||
@ -64,6 +61,12 @@ var CatCmd = &cmds.Command{
|
||||
max = -1
|
||||
}
|
||||
|
||||
err = req.ParseBodyArgs()
|
||||
if err != nil && err.Error() != "all arguments covered by positional arguments" {
|
||||
res.SetError(err, cmdkit.ErrNormal)
|
||||
return
|
||||
}
|
||||
|
||||
readers, length, err := cat(req.Context(), node, req.Arguments(), int64(offset), int64(max))
|
||||
if err != nil {
|
||||
res.SetError(err, cmdkit.ErrNormal)
|
||||
@ -71,7 +74,7 @@ var CatCmd = &cmds.Command{
|
||||
}
|
||||
|
||||
/*
|
||||
if err := corerepo.ConditionalGC(req.Context(), node, length); err != nil {
|
||||
if err := corerepo.ConditionalGC(req.Context, node, length); err != nil {
|
||||
re.SetError(err, cmdkit.ErrNormal)
|
||||
return
|
||||
}
|
||||
@ -89,8 +92,8 @@ var CatCmd = &cmds.Command{
|
||||
res.SetError(err, cmdkit.ErrNormal)
|
||||
}
|
||||
},
|
||||
PostRun: map[cmds.EncodingType]func(cmds.Request, cmds.ResponseEmitter) cmds.ResponseEmitter{
|
||||
cmds.CLI: func(req cmds.Request, re cmds.ResponseEmitter) cmds.ResponseEmitter {
|
||||
PostRun: map[cmds.EncodingType]func(*cmds.Request, cmds.ResponseEmitter) cmds.ResponseEmitter{
|
||||
cmds.CLI: func(req *cmds.Request, re cmds.ResponseEmitter) cmds.ResponseEmitter {
|
||||
reNext, res := cmds.NewChanResponsePair(req)
|
||||
|
||||
go func() {
|
||||
|
||||
@ -11,11 +11,11 @@ import (
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
oldcmds "github.com/ipfs/go-ipfs/commands"
|
||||
// oldcmds "github.com/ipfs/go-ipfs/commands"
|
||||
e "github.com/ipfs/go-ipfs/core/commands/e"
|
||||
|
||||
cmds "gx/ipfs/QmP9vZfc5WSjfGTXmwX2EcicMFzmZ6fXn7HTdKYat6ccmH/go-ipfs-cmds"
|
||||
"gx/ipfs/QmQp2a2Hhb7F6eK2A5hN8f9aJy4mtkEikL9Zj4cgB7d1dD/go-ipfs-cmdkit"
|
||||
cmds "gx/ipfs/QmTwKPLyeRKuDawuy6CAn1kRj1FVoqBEM8sviAUWN7NW9K/go-ipfs-cmds"
|
||||
"gx/ipfs/QmVD1W3MC8Hk1WZgFQPWWmBECJ3X72BgUYf9eCQ4PGzPps/go-ipfs-cmdkit"
|
||||
)
|
||||
|
||||
type commandEncoder struct {
|
||||
@ -69,16 +69,16 @@ func CommandsCmd(root *cmds.Command) *cmds.Command {
|
||||
Options: []cmdkit.Option{
|
||||
cmdkit.BoolOption(flagsOptionName, "f", "Show command flags"),
|
||||
},
|
||||
Run: func(req cmds.Request, res cmds.ResponseEmitter) {
|
||||
Run: func(req *cmds.Request, res cmds.ResponseEmitter, env interface{}) {
|
||||
rootCmd := cmd2outputCmd("ipfs", root)
|
||||
rootCmd.showOpts, _, _ = req.Option(flagsOptionName).Bool()
|
||||
rootCmd.showOpts, _ = req.Options[flagsOptionName].(bool)
|
||||
err := res.Emit(&rootCmd)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
}
|
||||
},
|
||||
Encoders: cmds.EncoderMap{
|
||||
cmds.Text: func(req cmds.Request) func(io.Writer) cmds.Encoder {
|
||||
cmds.Text: func(req *cmds.Request) func(io.Writer) cmds.Encoder {
|
||||
return func(w io.Writer) cmds.Encoder { return &commandEncoder{w} }
|
||||
},
|
||||
},
|
||||
@ -94,51 +94,12 @@ func cmd2outputCmd(name string, cmd *cmds.Command) Command {
|
||||
|
||||
output := Command{
|
||||
Name: name,
|
||||
Subcommands: make([]Command, len(cmd.Subcommands)+len(cmd.OldSubcommands)),
|
||||
Subcommands: make([]Command, 0, len(cmd.Subcommands)),
|
||||
Options: opts,
|
||||
}
|
||||
|
||||
// we need to keep track of names because a name *might* be used by both a Subcommand and an OldSubscommand.
|
||||
names := make(map[string]struct{})
|
||||
|
||||
i := 0
|
||||
for name, sub := range cmd.Subcommands {
|
||||
names[name] = struct{}{}
|
||||
output.Subcommands[i] = cmd2outputCmd(name, sub)
|
||||
i++
|
||||
}
|
||||
|
||||
for name, sub := range cmd.OldSubcommands {
|
||||
if _, ok := names[name]; ok {
|
||||
continue
|
||||
}
|
||||
|
||||
names[name] = struct{}{}
|
||||
output.Subcommands[i] = oldCmd2outputCmd(name, sub)
|
||||
i++
|
||||
}
|
||||
|
||||
// trucate to the amount of names we actually have
|
||||
output.Subcommands = output.Subcommands[:len(names)]
|
||||
return output
|
||||
}
|
||||
|
||||
func oldCmd2outputCmd(name string, cmd *oldcmds.Command) Command {
|
||||
opts := make([]Option, len(cmd.Options))
|
||||
for i, opt := range cmd.Options {
|
||||
opts[i] = Option{opt.Names()}
|
||||
}
|
||||
|
||||
output := Command{
|
||||
Name: name,
|
||||
Subcommands: make([]Command, len(cmd.Subcommands)),
|
||||
Options: opts,
|
||||
}
|
||||
|
||||
i := 0
|
||||
for name, sub := range cmd.Subcommands {
|
||||
output.Subcommands[i] = oldCmd2outputCmd(name, sub)
|
||||
i++
|
||||
output.Subcommands = append(output.Subcommands, cmd2outputCmd(name, sub))
|
||||
}
|
||||
|
||||
return output
|
||||
|
||||
@ -17,7 +17,7 @@ import (
|
||||
config "github.com/ipfs/go-ipfs/repo/config"
|
||||
fsrepo "github.com/ipfs/go-ipfs/repo/fsrepo"
|
||||
|
||||
"gx/ipfs/QmQp2a2Hhb7F6eK2A5hN8f9aJy4mtkEikL9Zj4cgB7d1dD/go-ipfs-cmdkit"
|
||||
"gx/ipfs/QmVD1W3MC8Hk1WZgFQPWWmBECJ3X72BgUYf9eCQ4PGzPps/go-ipfs-cmdkit"
|
||||
)
|
||||
|
||||
type ConfigField struct {
|
||||
|
||||
@ -13,8 +13,8 @@ import (
|
||||
path "github.com/ipfs/go-ipfs/path"
|
||||
pin "github.com/ipfs/go-ipfs/pin"
|
||||
|
||||
cmdkit "gx/ipfs/QmQp2a2Hhb7F6eK2A5hN8f9aJy4mtkEikL9Zj4cgB7d1dD/go-ipfs-cmdkit"
|
||||
files "gx/ipfs/QmQp2a2Hhb7F6eK2A5hN8f9aJy4mtkEikL9Zj4cgB7d1dD/go-ipfs-cmdkit/files"
|
||||
cmdkit "gx/ipfs/QmVD1W3MC8Hk1WZgFQPWWmBECJ3X72BgUYf9eCQ4PGzPps/go-ipfs-cmdkit"
|
||||
files "gx/ipfs/QmVD1W3MC8Hk1WZgFQPWWmBECJ3X72BgUYf9eCQ4PGzPps/go-ipfs-cmdkit/files"
|
||||
mh "gx/ipfs/QmYeKnKpubCMRiq3PGZcTREErthbb5Q9cXsCoSkD9bjEBd/go-multihash"
|
||||
cid "gx/ipfs/QmeSrf6pzut73u6zLQkRFQ3ygt3k6XFT2kjdYP8Tnkwwyg/go-cid"
|
||||
)
|
||||
|
||||
@ -15,8 +15,8 @@ import (
|
||||
|
||||
routing "gx/ipfs/QmPCGUjMRuBcPybZFpjhzpifwPP9wPRoiy5geTQKU4vqWA/go-libp2p-routing"
|
||||
notif "gx/ipfs/QmPCGUjMRuBcPybZFpjhzpifwPP9wPRoiy5geTQKU4vqWA/go-libp2p-routing/notifications"
|
||||
"gx/ipfs/QmQp2a2Hhb7F6eK2A5hN8f9aJy4mtkEikL9Zj4cgB7d1dD/go-ipfs-cmdkit"
|
||||
b58 "gx/ipfs/QmT8rehPR3F6bmwL6zjUN8XpiDBFFpMP2myPdC6ApsWfJf/go-base58"
|
||||
"gx/ipfs/QmVD1W3MC8Hk1WZgFQPWWmBECJ3X72BgUYf9eCQ4PGzPps/go-ipfs-cmdkit"
|
||||
peer "gx/ipfs/QmWNY7dV54ZDYmTA1ykVdwNCqC11mpU4zSUp6XDpLTH9eG/go-libp2p-peer"
|
||||
pstore "gx/ipfs/QmYijbtjCxFEjSXaudaQAUz3LN5VKLssm8WCUsRoqzXmQR/go-libp2p-peerstore"
|
||||
cid "gx/ipfs/QmeSrf6pzut73u6zLQkRFQ3ygt3k6XFT2kjdYP8Tnkwwyg/go-cid"
|
||||
|
||||
@ -3,7 +3,7 @@ package commands
|
||||
import (
|
||||
cmds "github.com/ipfs/go-ipfs/commands"
|
||||
|
||||
"gx/ipfs/QmQp2a2Hhb7F6eK2A5hN8f9aJy4mtkEikL9Zj4cgB7d1dD/go-ipfs-cmdkit"
|
||||
"gx/ipfs/QmVD1W3MC8Hk1WZgFQPWWmBECJ3X72BgUYf9eCQ4PGzPps/go-ipfs-cmdkit"
|
||||
)
|
||||
|
||||
var DiagCmd = &cmds.Command{
|
||||
|
||||
@ -8,7 +8,7 @@ import (
|
||||
e "github.com/ipfs/go-ipfs/core/commands/e"
|
||||
namesys "github.com/ipfs/go-ipfs/namesys"
|
||||
|
||||
"gx/ipfs/QmQp2a2Hhb7F6eK2A5hN8f9aJy4mtkEikL9Zj4cgB7d1dD/go-ipfs-cmdkit"
|
||||
"gx/ipfs/QmVD1W3MC8Hk1WZgFQPWWmBECJ3X72BgUYf9eCQ4PGzPps/go-ipfs-cmdkit"
|
||||
)
|
||||
|
||||
var DNSCmd = &cmds.Command{
|
||||
|
||||
27
core/commands/env.go
Normal file
27
core/commands/env.go
Normal file
@ -0,0 +1,27 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/ipfs/go-ipfs/commands"
|
||||
"github.com/ipfs/go-ipfs/core"
|
||||
"github.com/ipfs/go-ipfs/repo/config"
|
||||
)
|
||||
|
||||
func GetNode(env interface{}) (*core.IpfsNode, error) {
|
||||
ctx, ok := env.(*commands.Context)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("expected env to be of type %T, got %T", ctx, env)
|
||||
}
|
||||
|
||||
return ctx.GetNode()
|
||||
}
|
||||
|
||||
func GetConfig(env interface{}) (*config.Config, error) {
|
||||
ctx, ok := env.(*commands.Context)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("expected env to be of type %T, got %T", ctx, env)
|
||||
}
|
||||
|
||||
return ctx.GetConfig()
|
||||
}
|
||||
@ -10,7 +10,7 @@ import (
|
||||
|
||||
cmds "github.com/ipfs/go-ipfs/commands"
|
||||
|
||||
"gx/ipfs/QmQp2a2Hhb7F6eK2A5hN8f9aJy4mtkEikL9Zj4cgB7d1dD/go-ipfs-cmdkit"
|
||||
"gx/ipfs/QmVD1W3MC8Hk1WZgFQPWWmBECJ3X72BgUYf9eCQ4PGzPps/go-ipfs-cmdkit"
|
||||
)
|
||||
|
||||
func ExternalBinary() *cmds.Command {
|
||||
|
||||
@ -18,10 +18,10 @@ import (
|
||||
path "github.com/ipfs/go-ipfs/path"
|
||||
ft "github.com/ipfs/go-ipfs/unixfs"
|
||||
uio "github.com/ipfs/go-ipfs/unixfs/io"
|
||||
cmdkit "gx/ipfs/QmQp2a2Hhb7F6eK2A5hN8f9aJy4mtkEikL9Zj4cgB7d1dD/go-ipfs-cmdkit"
|
||||
|
||||
node "gx/ipfs/QmNwUEK7QbwSqyKBu3mMtToo8SUc6wQJ7gdZq4gGGJqfnf/go-ipld-format"
|
||||
logging "gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log"
|
||||
cmdkit "gx/ipfs/QmVD1W3MC8Hk1WZgFQPWWmBECJ3X72BgUYf9eCQ4PGzPps/go-ipfs-cmdkit"
|
||||
mh "gx/ipfs/QmYeKnKpubCMRiq3PGZcTREErthbb5Q9cXsCoSkD9bjEBd/go-multihash"
|
||||
cid "gx/ipfs/QmeSrf6pzut73u6zLQkRFQ3ygt3k6XFT2kjdYP8Tnkwwyg/go-cid"
|
||||
)
|
||||
|
||||
@ -11,8 +11,9 @@ import (
|
||||
e "github.com/ipfs/go-ipfs/core/commands/e"
|
||||
"github.com/ipfs/go-ipfs/filestore"
|
||||
|
||||
cmds "gx/ipfs/QmP9vZfc5WSjfGTXmwX2EcicMFzmZ6fXn7HTdKYat6ccmH/go-ipfs-cmds"
|
||||
"gx/ipfs/QmQp2a2Hhb7F6eK2A5hN8f9aJy4mtkEikL9Zj4cgB7d1dD/go-ipfs-cmdkit"
|
||||
lgc "github.com/ipfs/go-ipfs/commands/legacy"
|
||||
cmds "gx/ipfs/QmTwKPLyeRKuDawuy6CAn1kRj1FVoqBEM8sviAUWN7NW9K/go-ipfs-cmds"
|
||||
"gx/ipfs/QmVD1W3MC8Hk1WZgFQPWWmBECJ3X72BgUYf9eCQ4PGzPps/go-ipfs-cmdkit"
|
||||
cid "gx/ipfs/QmeSrf6pzut73u6zLQkRFQ3ygt3k6XFT2kjdYP8Tnkwwyg/go-cid"
|
||||
)
|
||||
|
||||
@ -21,11 +22,9 @@ var FileStoreCmd = &cmds.Command{
|
||||
Tagline: "Interact with filestore objects.",
|
||||
},
|
||||
Subcommands: map[string]*cmds.Command{
|
||||
"ls": lsFileStore,
|
||||
},
|
||||
OldSubcommands: map[string]*oldCmds.Command{
|
||||
"verify": verifyFileStore,
|
||||
"dups": dupsFileStore,
|
||||
"ls": lsFileStore,
|
||||
"verify": lgc.NewCommand(verifyFileStore),
|
||||
"dups": lgc.NewCommand(dupsFileStore),
|
||||
},
|
||||
}
|
||||
|
||||
@ -54,15 +53,15 @@ The output is:
|
||||
Options: []cmdkit.Option{
|
||||
cmdkit.BoolOption("file-order", "sort the results based on the path of the backing file"),
|
||||
},
|
||||
Run: func(req cmds.Request, res cmds.ResponseEmitter) {
|
||||
_, fs, err := getFilestore(req.InvocContext())
|
||||
Run: func(req *cmds.Request, res cmds.ResponseEmitter, env interface{}) {
|
||||
_, fs, err := getFilestore(env.(*oldCmds.Context))
|
||||
if err != nil {
|
||||
res.SetError(err, cmdkit.ErrNormal)
|
||||
return
|
||||
}
|
||||
args := req.Arguments()
|
||||
args := req.Arguments
|
||||
if len(args) > 0 {
|
||||
out := perKeyActionToChan(req.Context(), args, func(c *cid.Cid) *filestore.ListRes {
|
||||
out := perKeyActionToChan(req.Context, args, func(c *cid.Cid) *filestore.ListRes {
|
||||
return filestore.List(fs, c)
|
||||
})
|
||||
|
||||
@ -71,14 +70,14 @@ The output is:
|
||||
log.Error(err)
|
||||
}
|
||||
} else {
|
||||
fileOrder, _, _ := req.Option("file-order").Bool()
|
||||
fileOrder, _ := req.Options["file-order"].(bool)
|
||||
next, err := filestore.ListAll(fs, fileOrder)
|
||||
if err != nil {
|
||||
res.SetError(err, cmdkit.ErrNormal)
|
||||
return
|
||||
}
|
||||
|
||||
out := listResToChan(req.Context(), next)
|
||||
out := listResToChan(req.Context, next)
|
||||
err = res.Emit(out)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
@ -86,7 +85,7 @@ The output is:
|
||||
}
|
||||
},
|
||||
PostRun: cmds.PostRunMap{
|
||||
cmds.CLI: func(req cmds.Request, re cmds.ResponseEmitter) cmds.ResponseEmitter {
|
||||
cmds.CLI: func(req *cmds.Request, re cmds.ResponseEmitter) cmds.ResponseEmitter {
|
||||
reNext, res := cmds.NewChanResponsePair(req)
|
||||
|
||||
go func() {
|
||||
@ -236,12 +235,8 @@ var dupsFileStore = &oldCmds.Command{
|
||||
Type: RefWrapper{},
|
||||
}
|
||||
|
||||
type getNoder interface {
|
||||
GetNode() (*core.IpfsNode, error)
|
||||
}
|
||||
|
||||
func getFilestore(g getNoder) (*core.IpfsNode, *filestore.Filestore, error) {
|
||||
n, err := g.GetNode()
|
||||
func getFilestore(env interface{}) (*core.IpfsNode, *filestore.Filestore, error) {
|
||||
n, err := GetNode(env)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
@ -16,8 +16,8 @@ import (
|
||||
tar "github.com/ipfs/go-ipfs/thirdparty/tar"
|
||||
uarchive "github.com/ipfs/go-ipfs/unixfs/archive"
|
||||
|
||||
"gx/ipfs/QmP9vZfc5WSjfGTXmwX2EcicMFzmZ6fXn7HTdKYat6ccmH/go-ipfs-cmds"
|
||||
"gx/ipfs/QmQp2a2Hhb7F6eK2A5hN8f9aJy4mtkEikL9Zj4cgB7d1dD/go-ipfs-cmdkit"
|
||||
"gx/ipfs/QmTwKPLyeRKuDawuy6CAn1kRj1FVoqBEM8sviAUWN7NW9K/go-ipfs-cmds"
|
||||
"gx/ipfs/QmVD1W3MC8Hk1WZgFQPWWmBECJ3X72BgUYf9eCQ4PGzPps/go-ipfs-cmdkit"
|
||||
"gx/ipfs/QmeWjRodbcZFKe5tMN7poEx3izym6osrLSnTLf9UjJZBbs/pb"
|
||||
)
|
||||
|
||||
@ -48,12 +48,12 @@ may also specify the level of compression by specifying '-l=<1-9>'.
|
||||
cmdkit.BoolOption("compress", "C", "Compress the output with GZIP compression."),
|
||||
cmdkit.IntOption("compression-level", "l", "The level of compression (1-9).").WithDefault(-1),
|
||||
},
|
||||
PreRun: func(req cmds.Request) error {
|
||||
PreRun: func(req *cmds.Request, env interface{}) error {
|
||||
_, err := getCompressOptions(req)
|
||||
return err
|
||||
},
|
||||
Run: func(req cmds.Request, res cmds.ResponseEmitter) {
|
||||
if len(req.Arguments()) == 0 {
|
||||
Run: func(req *cmds.Request, res cmds.ResponseEmitter, env interface{}) {
|
||||
if len(req.Arguments) == 0 {
|
||||
res.SetError(errors.New("not enough arugments provided"), cmdkit.ErrClient)
|
||||
return
|
||||
}
|
||||
@ -63,13 +63,13 @@ may also specify the level of compression by specifying '-l=<1-9>'.
|
||||
return
|
||||
}
|
||||
|
||||
node, err := req.InvocContext().GetNode()
|
||||
node, err := GetNode(env)
|
||||
if err != nil {
|
||||
res.SetError(err, cmdkit.ErrNormal)
|
||||
return
|
||||
}
|
||||
p := path.Path(req.Arguments()[0])
|
||||
ctx := req.Context()
|
||||
p := path.Path(req.Arguments[0])
|
||||
ctx := req.Context
|
||||
dn, err := core.Resolve(ctx, node.Namesys, node.Resolver, p)
|
||||
if err != nil {
|
||||
res.SetError(err, cmdkit.ErrNormal)
|
||||
@ -92,7 +92,7 @@ may also specify the level of compression by specifying '-l=<1-9>'.
|
||||
return
|
||||
}
|
||||
|
||||
archive, _, _ := req.Option("archive").Bool()
|
||||
archive, _ := req.Options["archive"].(bool)
|
||||
reader, err := uarchive.DagArchive(ctx, dn, p.String(), node.DAG, archive, cmplvl)
|
||||
if err != nil {
|
||||
res.SetError(err, cmdkit.ErrNormal)
|
||||
@ -101,8 +101,8 @@ may also specify the level of compression by specifying '-l=<1-9>'.
|
||||
|
||||
res.Emit(reader)
|
||||
},
|
||||
PostRun: map[cmds.EncodingType]func(cmds.Request, cmds.ResponseEmitter) cmds.ResponseEmitter{
|
||||
cmds.CLI: func(req cmds.Request, re cmds.ResponseEmitter) cmds.ResponseEmitter {
|
||||
PostRun: map[cmds.EncodingType]func(*cmds.Request, cmds.ResponseEmitter) cmds.ResponseEmitter{
|
||||
cmds.CLI: func(req *cmds.Request, re cmds.ResponseEmitter) cmds.ResponseEmitter {
|
||||
reNext, res := cmds.NewChanResponsePair(req)
|
||||
|
||||
go func() {
|
||||
@ -119,7 +119,11 @@ may also specify the level of compression by specifying '-l=<1-9>'.
|
||||
return
|
||||
}
|
||||
|
||||
outPath := getOutPath(req)
|
||||
outPath, _ := req.Options["output"].(string)
|
||||
if len(outPath) == 0 {
|
||||
_, outPath = gopath.Split(req.Arguments[0])
|
||||
outPath = gopath.Clean(outPath)
|
||||
}
|
||||
|
||||
cmplvl, err := getCompressOptions(req)
|
||||
if err != nil {
|
||||
@ -127,7 +131,7 @@ may also specify the level of compression by specifying '-l=<1-9>'.
|
||||
return
|
||||
}
|
||||
|
||||
archive, _, _ := req.Option("archive").Bool()
|
||||
archive, _ := req.Options["archive"].(bool)
|
||||
|
||||
gw := getWriter{
|
||||
Out: os.Stdout,
|
||||
@ -183,10 +187,10 @@ func makeProgressBar(out io.Writer, l int64) *pb.ProgressBar {
|
||||
return bar
|
||||
}
|
||||
|
||||
func getOutPath(req cmds.Request) string {
|
||||
outPath, _, _ := req.Option("output").String()
|
||||
func getOutPath(req *cmds.Request) string {
|
||||
outPath, _ := req.Options["output"].(string)
|
||||
if outPath == "" {
|
||||
trimmed := strings.TrimRight(req.Arguments()[0], "/")
|
||||
trimmed := strings.TrimRight(req.Arguments[0], "/")
|
||||
_, outPath = gopath.Split(trimmed)
|
||||
outPath = gopath.Clean(outPath)
|
||||
}
|
||||
@ -251,9 +255,9 @@ func (gw *getWriter) writeExtracted(r io.Reader, fpath string) error {
|
||||
return extractor.Extract(r)
|
||||
}
|
||||
|
||||
func getCompressOptions(req cmds.Request) (int, error) {
|
||||
cmprs, _, _ := req.Option("compress").Bool()
|
||||
cmplvl, cmplvlFound, _ := req.Option("compression-level").Int()
|
||||
func getCompressOptions(req *cmds.Request) (int, error) {
|
||||
cmprs, _ := req.Options["compress"].(bool)
|
||||
cmplvl, cmplvlFound := req.Options["compression-level"].(int)
|
||||
switch {
|
||||
case !cmprs:
|
||||
return gzip.NoCompression, nil
|
||||
|
||||
@ -1,10 +1,11 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"gx/ipfs/QmP9vZfc5WSjfGTXmwX2EcicMFzmZ6fXn7HTdKYat6ccmH/go-ipfs-cmds"
|
||||
"gx/ipfs/QmQp2a2Hhb7F6eK2A5hN8f9aJy4mtkEikL9Zj4cgB7d1dD/go-ipfs-cmdkit"
|
||||
cmds "gx/ipfs/QmTwKPLyeRKuDawuy6CAn1kRj1FVoqBEM8sviAUWN7NW9K/go-ipfs-cmds"
|
||||
cmdkit "gx/ipfs/QmVD1W3MC8Hk1WZgFQPWWmBECJ3X72BgUYf9eCQ4PGzPps/go-ipfs-cmdkit"
|
||||
)
|
||||
|
||||
func TestGetOutputPath(t *testing.T) {
|
||||
@ -44,13 +45,15 @@ func TestGetOutputPath(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
defOpts, err := GetCmd.GetOptions([]string{})
|
||||
if err != nil {
|
||||
t.Fatalf("error getting default command options: %v", err)
|
||||
}
|
||||
/*
|
||||
defOpts, err := GetCmd.GetOptions([]string{})
|
||||
if err != nil {
|
||||
t.Fatalf("error getting default command options: %v", err)
|
||||
}
|
||||
*/
|
||||
|
||||
for _, tc := range cases {
|
||||
req, err := cmds.NewRequest([]string{}, tc.opts, tc.args, nil, GetCmd, defOpts)
|
||||
req, err := cmds.NewRequest(context.TODO(), []string{}, tc.opts, tc.args, nil, GetCmd)
|
||||
if err != nil {
|
||||
t.Fatalf("error creating a command request: %v", err)
|
||||
}
|
||||
|
||||
@ -4,7 +4,7 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
cmds "gx/ipfs/QmP9vZfc5WSjfGTXmwX2EcicMFzmZ6fXn7HTdKYat6ccmH/go-ipfs-cmds"
|
||||
cmds "gx/ipfs/QmTwKPLyeRKuDawuy6CAn1kRj1FVoqBEM8sviAUWN7NW9K/go-ipfs-cmds"
|
||||
)
|
||||
|
||||
func checkHelptextRecursive(t *testing.T, name []string, c *cmds.Command) {
|
||||
|
||||
@ -13,9 +13,10 @@ import (
|
||||
e "github.com/ipfs/go-ipfs/core/commands/e"
|
||||
|
||||
kb "gx/ipfs/QmQEo84PQQPJpx9Bf2YxerGVgmgWvQ9iwuZBAJaNJKWREr/go-libp2p-kbucket"
|
||||
"gx/ipfs/QmQp2a2Hhb7F6eK2A5hN8f9aJy4mtkEikL9Zj4cgB7d1dD/go-ipfs-cmdkit"
|
||||
b58 "gx/ipfs/QmT8rehPR3F6bmwL6zjUN8XpiDBFFpMP2myPdC6ApsWfJf/go-base58"
|
||||
"gx/ipfs/QmVD1W3MC8Hk1WZgFQPWWmBECJ3X72BgUYf9eCQ4PGzPps/go-ipfs-cmdkit"
|
||||
"gx/ipfs/QmWNY7dV54ZDYmTA1ykVdwNCqC11mpU4zSUp6XDpLTH9eG/go-libp2p-peer"
|
||||
"gx/ipfs/QmXYjuNuxVzXKJCfWasQk1RqkhVLDM9jtUKhqc2WPQmFSB/go-libp2p-peer"
|
||||
pstore "gx/ipfs/QmYijbtjCxFEjSXaudaQAUz3LN5VKLssm8WCUsRoqzXmQR/go-libp2p-peerstore"
|
||||
identify "gx/ipfs/Qma23bpHwQrQyvKeBemaeJh7sAoRHggPkgnge1B9489ff5/go-libp2p/p2p/protocol/identify"
|
||||
ic "gx/ipfs/QmaPbCnUMBohSGo3KnxEa2bHqyJVVeEEcwtqJAYxerieBo/go-libp2p-crypto"
|
||||
|
||||
@ -10,7 +10,7 @@ import (
|
||||
namesys "github.com/ipfs/go-ipfs/namesys"
|
||||
offline "github.com/ipfs/go-ipfs/routing/offline"
|
||||
|
||||
"gx/ipfs/QmQp2a2Hhb7F6eK2A5hN8f9aJy4mtkEikL9Zj4cgB7d1dD/go-ipfs-cmdkit"
|
||||
"gx/ipfs/QmVD1W3MC8Hk1WZgFQPWWmBECJ3X72BgUYf9eCQ4PGzPps/go-ipfs-cmdkit"
|
||||
)
|
||||
|
||||
var IpnsCmd = &cmds.Command{
|
||||
|
||||
@ -12,7 +12,7 @@ import (
|
||||
cmds "github.com/ipfs/go-ipfs/commands"
|
||||
e "github.com/ipfs/go-ipfs/core/commands/e"
|
||||
|
||||
"gx/ipfs/QmQp2a2Hhb7F6eK2A5hN8f9aJy4mtkEikL9Zj4cgB7d1dD/go-ipfs-cmdkit"
|
||||
"gx/ipfs/QmVD1W3MC8Hk1WZgFQPWWmBECJ3X72BgUYf9eCQ4PGzPps/go-ipfs-cmdkit"
|
||||
peer "gx/ipfs/QmWNY7dV54ZDYmTA1ykVdwNCqC11mpU4zSUp6XDpLTH9eG/go-libp2p-peer"
|
||||
ci "gx/ipfs/QmaPbCnUMBohSGo3KnxEa2bHqyJVVeEEcwtqJAYxerieBo/go-libp2p-crypto"
|
||||
)
|
||||
|
||||
@ -6,8 +6,8 @@ import (
|
||||
|
||||
cmds "github.com/ipfs/go-ipfs/commands"
|
||||
|
||||
"gx/ipfs/QmQp2a2Hhb7F6eK2A5hN8f9aJy4mtkEikL9Zj4cgB7d1dD/go-ipfs-cmdkit"
|
||||
logging "gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log"
|
||||
"gx/ipfs/QmVD1W3MC8Hk1WZgFQPWWmBECJ3X72BgUYf9eCQ4PGzPps/go-ipfs-cmdkit"
|
||||
)
|
||||
|
||||
// Golang os.Args overrides * and replaces the character argument with
|
||||
|
||||
@ -18,7 +18,7 @@ import (
|
||||
unixfspb "github.com/ipfs/go-ipfs/unixfs/pb"
|
||||
|
||||
node "gx/ipfs/QmNwUEK7QbwSqyKBu3mMtToo8SUc6wQJ7gdZq4gGGJqfnf/go-ipld-format"
|
||||
"gx/ipfs/QmQp2a2Hhb7F6eK2A5hN8f9aJy4mtkEikL9Zj4cgB7d1dD/go-ipfs-cmdkit"
|
||||
"gx/ipfs/QmVD1W3MC8Hk1WZgFQPWWmBECJ3X72BgUYf9eCQ4PGzPps/go-ipfs-cmdkit"
|
||||
)
|
||||
|
||||
type LsLink struct {
|
||||
|
||||
@ -6,7 +6,7 @@ package commands
|
||||
import (
|
||||
cmds "github.com/ipfs/go-ipfs/commands"
|
||||
|
||||
"gx/ipfs/QmQp2a2Hhb7F6eK2A5hN8f9aJy4mtkEikL9Zj4cgB7d1dD/go-ipfs-cmdkit"
|
||||
"gx/ipfs/QmVD1W3MC8Hk1WZgFQPWWmBECJ3X72BgUYf9eCQ4PGzPps/go-ipfs-cmdkit"
|
||||
)
|
||||
|
||||
var MountCmd = &cmds.Command{
|
||||
|
||||
@ -13,7 +13,7 @@ import (
|
||||
nodeMount "github.com/ipfs/go-ipfs/fuse/node"
|
||||
config "github.com/ipfs/go-ipfs/repo/config"
|
||||
|
||||
"gx/ipfs/QmQp2a2Hhb7F6eK2A5hN8f9aJy4mtkEikL9Zj4cgB7d1dD/go-ipfs-cmdkit"
|
||||
"gx/ipfs/QmVD1W3MC8Hk1WZgFQPWWmBECJ3X72BgUYf9eCQ4PGzPps/go-ipfs-cmdkit"
|
||||
)
|
||||
|
||||
var MountCmd = &cmds.Command{
|
||||
|
||||
@ -5,7 +5,7 @@ import (
|
||||
|
||||
cmds "github.com/ipfs/go-ipfs/commands"
|
||||
|
||||
cmdkit "gx/ipfs/QmQp2a2Hhb7F6eK2A5hN8f9aJy4mtkEikL9Zj4cgB7d1dD/go-ipfs-cmdkit"
|
||||
cmdkit "gx/ipfs/QmVD1W3MC8Hk1WZgFQPWWmBECJ3X72BgUYf9eCQ4PGzPps/go-ipfs-cmdkit"
|
||||
)
|
||||
|
||||
var MountCmd = &cmds.Command{
|
||||
|
||||
@ -3,7 +3,7 @@ package commands
|
||||
import (
|
||||
cmds "github.com/ipfs/go-ipfs/commands"
|
||||
|
||||
"gx/ipfs/QmQp2a2Hhb7F6eK2A5hN8f9aJy4mtkEikL9Zj4cgB7d1dD/go-ipfs-cmdkit"
|
||||
"gx/ipfs/QmVD1W3MC8Hk1WZgFQPWWmBECJ3X72BgUYf9eCQ4PGzPps/go-ipfs-cmdkit"
|
||||
)
|
||||
|
||||
type IpnsEntry struct {
|
||||
|
||||
@ -10,7 +10,7 @@ import (
|
||||
e "github.com/ipfs/go-ipfs/core/commands/e"
|
||||
dagutils "github.com/ipfs/go-ipfs/merkledag/utils"
|
||||
path "github.com/ipfs/go-ipfs/path"
|
||||
cmdkit "gx/ipfs/QmQp2a2Hhb7F6eK2A5hN8f9aJy4mtkEikL9Zj4cgB7d1dD/go-ipfs-cmdkit"
|
||||
cmdkit "gx/ipfs/QmVD1W3MC8Hk1WZgFQPWWmBECJ3X72BgUYf9eCQ4PGzPps/go-ipfs-cmdkit"
|
||||
)
|
||||
|
||||
type Changes struct {
|
||||
|
||||
@ -21,7 +21,7 @@ import (
|
||||
ft "github.com/ipfs/go-ipfs/unixfs"
|
||||
|
||||
node "gx/ipfs/QmNwUEK7QbwSqyKBu3mMtToo8SUc6wQJ7gdZq4gGGJqfnf/go-ipld-format"
|
||||
cmdkit "gx/ipfs/QmQp2a2Hhb7F6eK2A5hN8f9aJy4mtkEikL9Zj4cgB7d1dD/go-ipfs-cmdkit"
|
||||
cmdkit "gx/ipfs/QmVD1W3MC8Hk1WZgFQPWWmBECJ3X72BgUYf9eCQ4PGzPps/go-ipfs-cmdkit"
|
||||
cid "gx/ipfs/QmeSrf6pzut73u6zLQkRFQ3ygt3k6XFT2kjdYP8Tnkwwyg/go-cid"
|
||||
)
|
||||
|
||||
|
||||
@ -13,7 +13,7 @@ import (
|
||||
path "github.com/ipfs/go-ipfs/path"
|
||||
ft "github.com/ipfs/go-ipfs/unixfs"
|
||||
|
||||
cmdkit "gx/ipfs/QmQp2a2Hhb7F6eK2A5hN8f9aJy4mtkEikL9Zj4cgB7d1dD/go-ipfs-cmdkit"
|
||||
cmdkit "gx/ipfs/QmVD1W3MC8Hk1WZgFQPWWmBECJ3X72BgUYf9eCQ4PGzPps/go-ipfs-cmdkit"
|
||||
)
|
||||
|
||||
var ObjectPatchCmd = &cmds.Command{
|
||||
|
||||
@ -11,7 +11,7 @@ import (
|
||||
cmds "github.com/ipfs/go-ipfs/commands"
|
||||
core "github.com/ipfs/go-ipfs/core"
|
||||
|
||||
"gx/ipfs/QmQp2a2Hhb7F6eK2A5hN8f9aJy4mtkEikL9Zj4cgB7d1dD/go-ipfs-cmdkit"
|
||||
"gx/ipfs/QmVD1W3MC8Hk1WZgFQPWWmBECJ3X72BgUYf9eCQ4PGzPps/go-ipfs-cmdkit"
|
||||
ma "gx/ipfs/QmW8s4zTsUoX1Q6CeYxVKPyqSKbF7H1YDUyTostBtZ8DaG/go-multiaddr"
|
||||
)
|
||||
|
||||
|
||||
@ -16,8 +16,9 @@ import (
|
||||
pin "github.com/ipfs/go-ipfs/pin"
|
||||
uio "github.com/ipfs/go-ipfs/unixfs/io"
|
||||
|
||||
cid "gx/ipfs/QmNp85zy9RLrQ5oQD4hPyS39ezrrXpcaa7R4Y9kxdWQLLQ/go-cid"
|
||||
u "gx/ipfs/QmPsAfmDBnZN3kZGSuNwvCNDZiHneERSKmRcFyG3UkvcT3/go-ipfs-util"
|
||||
"gx/ipfs/QmQp2a2Hhb7F6eK2A5hN8f9aJy4mtkEikL9Zj4cgB7d1dD/go-ipfs-cmdkit"
|
||||
u "gx/ipfs/QmSU6eubNdhXjFBJBSksTp8kv8YRub8mGAPv8tVJHmL2EU/go-ipfs-util"
|
||||
cid "gx/ipfs/QmeSrf6pzut73u6zLQkRFQ3ygt3k6XFT2kjdYP8Tnkwwyg/go-cid"
|
||||
)
|
||||
|
||||
|
||||
@ -13,7 +13,7 @@ import (
|
||||
core "github.com/ipfs/go-ipfs/core"
|
||||
|
||||
u "gx/ipfs/QmPsAfmDBnZN3kZGSuNwvCNDZiHneERSKmRcFyG3UkvcT3/go-ipfs-util"
|
||||
"gx/ipfs/QmQp2a2Hhb7F6eK2A5hN8f9aJy4mtkEikL9Zj4cgB7d1dD/go-ipfs-cmdkit"
|
||||
"gx/ipfs/QmVD1W3MC8Hk1WZgFQPWWmBECJ3X72BgUYf9eCQ4PGzPps/go-ipfs-cmdkit"
|
||||
ma "gx/ipfs/QmW8s4zTsUoX1Q6CeYxVKPyqSKbF7H1YDUyTostBtZ8DaG/go-multiaddr"
|
||||
peer "gx/ipfs/QmWNY7dV54ZDYmTA1ykVdwNCqC11mpU4zSUp6XDpLTH9eG/go-libp2p-peer"
|
||||
pstore "gx/ipfs/QmYijbtjCxFEjSXaudaQAUz3LN5VKLssm8WCUsRoqzXmQR/go-libp2p-peerstore"
|
||||
|
||||
@ -14,7 +14,7 @@ import (
|
||||
keystore "github.com/ipfs/go-ipfs/keystore"
|
||||
path "github.com/ipfs/go-ipfs/path"
|
||||
|
||||
"gx/ipfs/QmQp2a2Hhb7F6eK2A5hN8f9aJy4mtkEikL9Zj4cgB7d1dD/go-ipfs-cmdkit"
|
||||
"gx/ipfs/QmVD1W3MC8Hk1WZgFQPWWmBECJ3X72BgUYf9eCQ4PGzPps/go-ipfs-cmdkit"
|
||||
peer "gx/ipfs/QmWNY7dV54ZDYmTA1ykVdwNCqC11mpU4zSUp6XDpLTH9eG/go-libp2p-peer"
|
||||
crypto "gx/ipfs/QmaPbCnUMBohSGo3KnxEa2bHqyJVVeEEcwtqJAYxerieBo/go-libp2p-crypto"
|
||||
)
|
||||
|
||||
@ -12,8 +12,8 @@ import (
|
||||
core "github.com/ipfs/go-ipfs/core"
|
||||
|
||||
floodsub "gx/ipfs/QmP1T1SGU6276R2MHKP2owbck37Fnzd6ZkpyNJvnG2LoTG/go-libp2p-floodsub"
|
||||
cmds "gx/ipfs/QmP9vZfc5WSjfGTXmwX2EcicMFzmZ6fXn7HTdKYat6ccmH/go-ipfs-cmds"
|
||||
cmdkit "gx/ipfs/QmQp2a2Hhb7F6eK2A5hN8f9aJy4mtkEikL9Zj4cgB7d1dD/go-ipfs-cmdkit"
|
||||
cmds "gx/ipfs/QmTwKPLyeRKuDawuy6CAn1kRj1FVoqBEM8sviAUWN7NW9K/go-ipfs-cmds"
|
||||
cmdkit "gx/ipfs/QmVD1W3MC8Hk1WZgFQPWWmBECJ3X72BgUYf9eCQ4PGzPps/go-ipfs-cmdkit"
|
||||
pstore "gx/ipfs/QmYijbtjCxFEjSXaudaQAUz3LN5VKLssm8WCUsRoqzXmQR/go-libp2p-peerstore"
|
||||
blocks "gx/ipfs/QmYsEQydGrsxNZfAiskvQ76N2xE9hDQtSAkRSynwMiUK3c/go-block-format"
|
||||
cid "gx/ipfs/QmeSrf6pzut73u6zLQkRFQ3ygt3k6XFT2kjdYP8Tnkwwyg/go-cid"
|
||||
@ -70,8 +70,8 @@ This command outputs data in the following encodings:
|
||||
Options: []cmdkit.Option{
|
||||
cmdkit.BoolOption("discover", "try to discover other peers subscribed to the same topic"),
|
||||
},
|
||||
Run: func(req cmds.Request, res cmds.ResponseEmitter) {
|
||||
n, err := req.InvocContext().GetNode()
|
||||
Run: func(req *cmds.Request, res cmds.ResponseEmitter, env interface{}) {
|
||||
n, err := GetNode(env)
|
||||
if err != nil {
|
||||
res.SetError(err, cmdkit.ErrNormal)
|
||||
return
|
||||
@ -88,7 +88,7 @@ This command outputs data in the following encodings:
|
||||
return
|
||||
}
|
||||
|
||||
topic := req.Arguments()[0]
|
||||
topic := req.Arguments[0]
|
||||
sub, err := n.Floodsub.Subscribe(topic)
|
||||
if err != nil {
|
||||
res.SetError(err, cmdkit.ErrNormal)
|
||||
@ -96,7 +96,7 @@ This command outputs data in the following encodings:
|
||||
}
|
||||
defer sub.Cancel()
|
||||
|
||||
discover, _, _ := req.Option("discover").Bool()
|
||||
discover, _ := req.Options["discover"].(bool)
|
||||
if discover {
|
||||
go func() {
|
||||
blk := blocks.NewBlock([]byte("floodsub:" + topic))
|
||||
@ -106,7 +106,7 @@ This command outputs data in the following encodings:
|
||||
return
|
||||
}
|
||||
|
||||
connectToPubSubPeers(req.Context(), n, cid)
|
||||
connectToPubSubPeers(req.Context, n, cid)
|
||||
}()
|
||||
}
|
||||
|
||||
@ -115,7 +115,7 @@ This command outputs data in the following encodings:
|
||||
}
|
||||
|
||||
for {
|
||||
msg, err := sub.Next(req.Context())
|
||||
msg, err := sub.Next(req.Context)
|
||||
if err == io.EOF || err == context.Canceled {
|
||||
return
|
||||
} else if err != nil {
|
||||
@ -127,7 +127,7 @@ This command outputs data in the following encodings:
|
||||
}
|
||||
},
|
||||
Encoders: cmds.EncoderMap{
|
||||
cmds.Text: cmds.MakeEncoder(func(req cmds.Request, w io.Writer, v interface{}) error {
|
||||
cmds.Text: cmds.MakeEncoder(func(req *cmds.Request, w io.Writer, v interface{}) error {
|
||||
m, ok := v.(*floodsub.Message)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type: %T", v)
|
||||
@ -136,7 +136,7 @@ This command outputs data in the following encodings:
|
||||
_, err := w.Write(m.Data)
|
||||
return err
|
||||
}),
|
||||
"ndpayload": cmds.MakeEncoder(func(req cmds.Request, w io.Writer, v interface{}) error {
|
||||
"ndpayload": cmds.MakeEncoder(func(req *cmds.Request, w io.Writer, v interface{}) error {
|
||||
m, ok := v.(*floodsub.Message)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type: %T", v)
|
||||
@ -146,7 +146,7 @@ This command outputs data in the following encodings:
|
||||
_, err := w.Write(m.Data)
|
||||
return err
|
||||
}),
|
||||
"lenpayload": cmds.MakeEncoder(func(req cmds.Request, w io.Writer, v interface{}) error {
|
||||
"lenpayload": cmds.MakeEncoder(func(req *cmds.Request, w io.Writer, v interface{}) error {
|
||||
m, ok := v.(*floodsub.Message)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type: %T", v)
|
||||
@ -203,8 +203,8 @@ To use, the daemon must be run with '--enable-pubsub-experiment'.
|
||||
cmdkit.StringArg("topic", true, false, "Topic to publish to."),
|
||||
cmdkit.StringArg("data", true, true, "Payload of message to publish.").EnableStdin(),
|
||||
},
|
||||
Run: func(req cmds.Request, res cmds.ResponseEmitter) {
|
||||
n, err := req.InvocContext().GetNode()
|
||||
Run: func(req *cmds.Request, res cmds.ResponseEmitter, env interface{}) {
|
||||
n, err := GetNode(env)
|
||||
if err != nil {
|
||||
res.SetError(err, cmdkit.ErrNormal)
|
||||
return
|
||||
@ -221,9 +221,9 @@ To use, the daemon must be run with '--enable-pubsub-experiment'.
|
||||
return
|
||||
}
|
||||
|
||||
topic := req.Arguments()[0]
|
||||
topic := req.Arguments[0]
|
||||
|
||||
for _, data := range req.Arguments()[1:] {
|
||||
for _, data := range req.Arguments[1:] {
|
||||
if err := n.Floodsub.Publish(topic, []byte(data)); err != nil {
|
||||
res.SetError(err, cmdkit.ErrNormal)
|
||||
return
|
||||
@ -244,8 +244,8 @@ to be used in a production environment.
|
||||
To use, the daemon must be run with '--enable-pubsub-experiment'.
|
||||
`,
|
||||
},
|
||||
Run: func(req cmds.Request, res cmds.ResponseEmitter) {
|
||||
n, err := req.InvocContext().GetNode()
|
||||
Run: func(req *cmds.Request, res cmds.ResponseEmitter, env interface{}) {
|
||||
n, err := GetNode(env)
|
||||
if err != nil {
|
||||
res.SetError(err, cmdkit.ErrNormal)
|
||||
return
|
||||
@ -286,8 +286,8 @@ To use, the daemon must be run with '--enable-pubsub-experiment'.
|
||||
Arguments: []cmdkit.Argument{
|
||||
cmdkit.StringArg("topic", false, false, "topic to list connected peers of"),
|
||||
},
|
||||
Run: func(req cmds.Request, res cmds.ResponseEmitter) {
|
||||
n, err := req.InvocContext().GetNode()
|
||||
Run: func(req *cmds.Request, res cmds.ResponseEmitter, env interface{}) {
|
||||
n, err := GetNode(env)
|
||||
if err != nil {
|
||||
res.SetError(err, cmdkit.ErrNormal)
|
||||
return
|
||||
@ -305,8 +305,8 @@ To use, the daemon must be run with '--enable-pubsub-experiment'.
|
||||
}
|
||||
|
||||
var topic string
|
||||
if len(req.Arguments()) == 1 {
|
||||
topic = req.Arguments()[0]
|
||||
if len(req.Arguments) == 1 {
|
||||
topic = req.Arguments[0]
|
||||
}
|
||||
|
||||
for _, peer := range n.Floodsub.ListPeers(topic) {
|
||||
|
||||
@ -14,7 +14,7 @@ import (
|
||||
path "github.com/ipfs/go-ipfs/path"
|
||||
|
||||
node "gx/ipfs/QmNwUEK7QbwSqyKBu3mMtToo8SUc6wQJ7gdZq4gGGJqfnf/go-ipld-format"
|
||||
"gx/ipfs/QmQp2a2Hhb7F6eK2A5hN8f9aJy4mtkEikL9Zj4cgB7d1dD/go-ipfs-cmdkit"
|
||||
"gx/ipfs/QmVD1W3MC8Hk1WZgFQPWWmBECJ3X72BgUYf9eCQ4PGzPps/go-ipfs-cmdkit"
|
||||
cid "gx/ipfs/QmeSrf6pzut73u6zLQkRFQ3ygt3k6XFT2kjdYP8Tnkwwyg/go-cid"
|
||||
)
|
||||
|
||||
|
||||
@ -17,8 +17,9 @@ import (
|
||||
fsrepo "github.com/ipfs/go-ipfs/repo/fsrepo"
|
||||
lockfile "github.com/ipfs/go-ipfs/repo/fsrepo/lock"
|
||||
|
||||
cmds "gx/ipfs/QmP9vZfc5WSjfGTXmwX2EcicMFzmZ6fXn7HTdKYat6ccmH/go-ipfs-cmds"
|
||||
cmdkit "gx/ipfs/QmQp2a2Hhb7F6eK2A5hN8f9aJy4mtkEikL9Zj4cgB7d1dD/go-ipfs-cmdkit"
|
||||
lgc "github.com/ipfs/go-ipfs/commands/legacy"
|
||||
cmds "gx/ipfs/QmTwKPLyeRKuDawuy6CAn1kRj1FVoqBEM8sviAUWN7NW9K/go-ipfs-cmds"
|
||||
cmdkit "gx/ipfs/QmVD1W3MC8Hk1WZgFQPWWmBECJ3X72BgUYf9eCQ4PGzPps/go-ipfs-cmdkit"
|
||||
cid "gx/ipfs/QmeSrf6pzut73u6zLQkRFQ3ygt3k6XFT2kjdYP8Tnkwwyg/go-cid"
|
||||
)
|
||||
|
||||
@ -35,13 +36,11 @@ var RepoCmd = &cmds.Command{
|
||||
},
|
||||
|
||||
Subcommands: map[string]*cmds.Command{
|
||||
"stat": repoStatCmd,
|
||||
},
|
||||
OldSubcommands: map[string]*oldcmds.Command{
|
||||
"gc": repoGcCmd,
|
||||
"fsck": RepoFsckCmd,
|
||||
"version": repoVersionCmd,
|
||||
"verify": repoVerifyCmd,
|
||||
"stat": repoStatCmd,
|
||||
"gc": lgc.NewCommand(repoGcCmd),
|
||||
"fsck": lgc.NewCommand(RepoFsckCmd),
|
||||
"version": lgc.NewCommand(repoVersionCmd),
|
||||
"verify": lgc.NewCommand(repoVerifyCmd),
|
||||
},
|
||||
}
|
||||
|
||||
@ -160,14 +159,14 @@ RepoSize int Size in bytes that the repo is currently taking.
|
||||
Version string The repo version.
|
||||
`,
|
||||
},
|
||||
Run: func(req cmds.Request, res cmds.ResponseEmitter) {
|
||||
n, err := req.InvocContext().GetNode()
|
||||
Run: func(req *cmds.Request, res cmds.ResponseEmitter, env interface{}) {
|
||||
n, err := GetNode(env)
|
||||
if err != nil {
|
||||
res.SetError(err, cmdkit.ErrNormal)
|
||||
return
|
||||
}
|
||||
|
||||
stat, err := corerepo.RepoStat(n, req.Context())
|
||||
stat, err := corerepo.RepoStat(n, req.Context)
|
||||
if err != nil {
|
||||
res.SetError(err, cmdkit.ErrNormal)
|
||||
return
|
||||
@ -180,16 +179,13 @@ Version string The repo version.
|
||||
},
|
||||
Type: corerepo.Stat{},
|
||||
Encoders: cmds.EncoderMap{
|
||||
cmds.Text: cmds.MakeEncoder(func(req cmds.Request, w io.Writer, v interface{}) error {
|
||||
cmds.Text: cmds.MakeEncoder(func(req *cmds.Request, w io.Writer, v interface{}) error {
|
||||
stat, ok := v.(*corerepo.Stat)
|
||||
if !ok {
|
||||
return e.TypeErr(stat, v)
|
||||
}
|
||||
|
||||
human, _, err := req.Option("human").Bool()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
human, _ := req.Options["human"].(bool)
|
||||
|
||||
wtr := tabwriter.NewWriter(w, 0, 0, 1, ' ', 0)
|
||||
|
||||
|
||||
@ -10,7 +10,7 @@ import (
|
||||
ns "github.com/ipfs/go-ipfs/namesys"
|
||||
path "github.com/ipfs/go-ipfs/path"
|
||||
|
||||
"gx/ipfs/QmQp2a2Hhb7F6eK2A5hN8f9aJy4mtkEikL9Zj4cgB7d1dD/go-ipfs-cmdkit"
|
||||
"gx/ipfs/QmVD1W3MC8Hk1WZgFQPWWmBECJ3X72BgUYf9eCQ4PGzPps/go-ipfs-cmdkit"
|
||||
)
|
||||
|
||||
type ResolvedPath struct {
|
||||
|
||||
@ -11,9 +11,10 @@ import (
|
||||
ocmd "github.com/ipfs/go-ipfs/core/commands/object"
|
||||
unixfs "github.com/ipfs/go-ipfs/core/commands/unixfs"
|
||||
|
||||
"gx/ipfs/QmP9vZfc5WSjfGTXmwX2EcicMFzmZ6fXn7HTdKYat6ccmH/go-ipfs-cmds"
|
||||
"gx/ipfs/QmQp2a2Hhb7F6eK2A5hN8f9aJy4mtkEikL9Zj4cgB7d1dD/go-ipfs-cmdkit"
|
||||
lgc "github.com/ipfs/go-ipfs/commands/legacy"
|
||||
logging "gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log"
|
||||
"gx/ipfs/QmTwKPLyeRKuDawuy6CAn1kRj1FVoqBEM8sviAUWN7NW9K/go-ipfs-cmds"
|
||||
"gx/ipfs/QmVD1W3MC8Hk1WZgFQPWWmBECJ3X72BgUYf9eCQ4PGzPps/go-ipfs-cmdkit"
|
||||
)
|
||||
|
||||
var log = logging.Logger("core/commands")
|
||||
@ -91,6 +92,11 @@ The CLI will exit with one of the following values:
|
||||
cmdkit.BoolOption("h", "Show a short version of the command help text."),
|
||||
cmdkit.BoolOption("local", "L", "Run the command locally, instead of using the daemon."),
|
||||
cmdkit.StringOption(ApiOption, "Use a specific API instance (defaults to /ip4/127.0.0.1/tcp/5001)"),
|
||||
|
||||
// global options, added to every command
|
||||
cmds.OptionEncodingType,
|
||||
cmds.OptionStreamChannels,
|
||||
cmds.OptionTimeout,
|
||||
},
|
||||
}
|
||||
|
||||
@ -108,34 +114,31 @@ var rootSubcommands = map[string]*cmds.Command{
|
||||
"pubsub": PubsubCmd,
|
||||
"repo": RepoCmd,
|
||||
"stats": StatsCmd,
|
||||
}
|
||||
|
||||
var rootOldSubcommands = map[string]*oldcmds.Command{
|
||||
"bootstrap": BootstrapCmd,
|
||||
"config": ConfigCmd,
|
||||
"dag": dag.DagCmd,
|
||||
"dht": DhtCmd,
|
||||
"diag": DiagCmd,
|
||||
"dns": DNSCmd,
|
||||
"files": files.FilesCmd,
|
||||
"id": IDCmd,
|
||||
"key": KeyCmd,
|
||||
"log": LogCmd,
|
||||
"ls": LsCmd,
|
||||
"mount": MountCmd,
|
||||
"name": NameCmd,
|
||||
"object": ocmd.ObjectCmd,
|
||||
"pin": PinCmd,
|
||||
"ping": PingCmd,
|
||||
"p2p": P2PCmd,
|
||||
"refs": RefsCmd,
|
||||
"resolve": ResolveCmd,
|
||||
"swarm": SwarmCmd,
|
||||
"tar": TarCmd,
|
||||
"file": unixfs.UnixFSCmd,
|
||||
"update": ExternalBinary(),
|
||||
"version": VersionCmd,
|
||||
"shutdown": daemonShutdownCmd,
|
||||
"bootstrap": lgc.NewCommand(BootstrapCmd),
|
||||
"config": lgc.NewCommand(ConfigCmd),
|
||||
"dag": lgc.NewCommand(dag.DagCmd),
|
||||
"dht": lgc.NewCommand(DhtCmd),
|
||||
"diag": lgc.NewCommand(DiagCmd),
|
||||
"dns": lgc.NewCommand(DNSCmd),
|
||||
"files": lgc.NewCommand(files.FilesCmd),
|
||||
"id": lgc.NewCommand(IDCmd),
|
||||
"key": lgc.NewCommand(KeyCmd),
|
||||
"log": lgc.NewCommand(LogCmd),
|
||||
"ls": lgc.NewCommand(LsCmd),
|
||||
"mount": lgc.NewCommand(MountCmd),
|
||||
"name": lgc.NewCommand(NameCmd),
|
||||
"object": lgc.NewCommand(ocmd.ObjectCmd),
|
||||
"pin": lgc.NewCommand(PinCmd),
|
||||
"ping": lgc.NewCommand(PingCmd),
|
||||
"p2p": lgc.NewCommand(P2PCmd),
|
||||
"refs": lgc.NewCommand(RefsCmd),
|
||||
"resolve": lgc.NewCommand(ResolveCmd),
|
||||
"swarm": lgc.NewCommand(SwarmCmd),
|
||||
"tar": lgc.NewCommand(TarCmd),
|
||||
"file": lgc.NewCommand(unixfs.UnixFSCmd),
|
||||
"update": lgc.NewCommand(ExternalBinary()),
|
||||
"version": lgc.NewCommand(VersionCmd),
|
||||
"shutdown": lgc.NewCommand(daemonShutdownCmd),
|
||||
}
|
||||
|
||||
// RootRO is the readonly version of Root
|
||||
@ -155,33 +158,30 @@ var rootROSubcommands = map[string]*cmds.Command{
|
||||
},
|
||||
},
|
||||
"get": GetCmd,
|
||||
}
|
||||
|
||||
var rootROOldSubcommands = map[string]*oldcmds.Command{
|
||||
"dns": DNSCmd,
|
||||
"ls": LsCmd,
|
||||
"name": &oldcmds.Command{
|
||||
"dns": lgc.NewCommand(DNSCmd),
|
||||
"ls": lgc.NewCommand(LsCmd),
|
||||
"name": lgc.NewCommand(&oldcmds.Command{
|
||||
Subcommands: map[string]*oldcmds.Command{
|
||||
"resolve": IpnsCmd,
|
||||
},
|
||||
},
|
||||
"object": &oldcmds.Command{
|
||||
}),
|
||||
"object": lgc.NewCommand(&oldcmds.Command{
|
||||
Subcommands: map[string]*oldcmds.Command{
|
||||
"data": ocmd.ObjectDataCmd,
|
||||
"links": ocmd.ObjectLinksCmd,
|
||||
"get": ocmd.ObjectGetCmd,
|
||||
"stat": ocmd.ObjectStatCmd,
|
||||
},
|
||||
},
|
||||
"dag": &oldcmds.Command{
|
||||
}),
|
||||
"dag": lgc.NewCommand(&oldcmds.Command{
|
||||
Subcommands: map[string]*oldcmds.Command{
|
||||
"get": dag.DagGetCmd,
|
||||
"resolve": dag.DagResolveCmd,
|
||||
},
|
||||
},
|
||||
"refs": RefsROCmd,
|
||||
"resolve": ResolveCmd,
|
||||
"version": VersionCmd,
|
||||
}),
|
||||
"refs": lgc.NewCommand(RefsROCmd),
|
||||
"resolve": lgc.NewCommand(ResolveCmd),
|
||||
"version": lgc.NewCommand(VersionCmd),
|
||||
}
|
||||
|
||||
func init() {
|
||||
@ -192,10 +192,8 @@ func init() {
|
||||
*RefsROCmd = *RefsCmd
|
||||
RefsROCmd.Subcommands = map[string]*oldcmds.Command{}
|
||||
|
||||
Root.OldSubcommands = rootOldSubcommands
|
||||
Root.Subcommands = rootSubcommands
|
||||
|
||||
RootRO.OldSubcommands = rootROOldSubcommands
|
||||
RootRO.Subcommands = rootROSubcommands
|
||||
}
|
||||
|
||||
|
||||
@ -3,7 +3,7 @@ package commands
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"gx/ipfs/QmQp2a2Hhb7F6eK2A5hN8f9aJy4mtkEikL9Zj4cgB7d1dD/go-ipfs-cmdkit"
|
||||
"gx/ipfs/QmVD1W3MC8Hk1WZgFQPWWmBECJ3X72BgUYf9eCQ4PGzPps/go-ipfs-cmdkit"
|
||||
|
||||
cmds "github.com/ipfs/go-ipfs/commands"
|
||||
)
|
||||
|
||||
@ -9,7 +9,8 @@ import (
|
||||
|
||||
cmds "gx/ipfs/QmP9vZfc5WSjfGTXmwX2EcicMFzmZ6fXn7HTdKYat6ccmH/go-ipfs-cmds"
|
||||
humanize "gx/ipfs/QmPSBJL4momYnE7DcUyk2DVhD6rH488ZmHBGLbxNdhU44K/go-humanize"
|
||||
cmdkit "gx/ipfs/QmQp2a2Hhb7F6eK2A5hN8f9aJy4mtkEikL9Zj4cgB7d1dD/go-ipfs-cmdkit"
|
||||
cmds "gx/ipfs/QmTwKPLyeRKuDawuy6CAn1kRj1FVoqBEM8sviAUWN7NW9K/go-ipfs-cmds"
|
||||
cmdkit "gx/ipfs/QmVD1W3MC8Hk1WZgFQPWWmBECJ3X72BgUYf9eCQ4PGzPps/go-ipfs-cmdkit"
|
||||
peer "gx/ipfs/QmWNY7dV54ZDYmTA1ykVdwNCqC11mpU4zSUp6XDpLTH9eG/go-libp2p-peer"
|
||||
protocol "gx/ipfs/QmZNkThpqfVXs9GNbexPrfBbXSLNYeKrE7jwFM2oqHbyqN/go-libp2p-protocol"
|
||||
metrics "gx/ipfs/QmaL2WYJGbWKqHoLujoi9GQ5jj4JVFrBqHUBWmEYzJPVWT/go-libp2p-metrics"
|
||||
@ -79,8 +80,8 @@ Example:
|
||||
"ns", "us" (or "µs"), "ms", "s", "m", "h".`).WithDefault("1s"),
|
||||
},
|
||||
|
||||
Run: func(req cmds.Request, res cmds.ResponseEmitter) {
|
||||
nd, err := req.InvocContext().GetNode()
|
||||
Run: func(req *cmds.Request, res cmds.ResponseEmitter, env interface{}) {
|
||||
nd, err := GetNode(env)
|
||||
if err != nil {
|
||||
res.SetError(err, cmdkit.ErrNormal)
|
||||
return
|
||||
@ -97,17 +98,8 @@ Example:
|
||||
return
|
||||
}
|
||||
|
||||
pstr, pfound, err := req.Option("peer").String()
|
||||
if err != nil {
|
||||
res.SetError(err, cmdkit.ErrNormal)
|
||||
return
|
||||
}
|
||||
|
||||
tstr, tfound, err := req.Option("proto").String()
|
||||
if err != nil {
|
||||
res.SetError(err, cmdkit.ErrNormal)
|
||||
return
|
||||
}
|
||||
pstr, pfound := req.Options["peer"].(string)
|
||||
tstr, tfound := req.Options["proto"].(string)
|
||||
if pfound && tfound {
|
||||
res.SetError(errors.New("please only specify peer OR protocol"), cmdkit.ErrClient)
|
||||
return
|
||||
@ -123,23 +115,14 @@ Example:
|
||||
pid = checkpid
|
||||
}
|
||||
|
||||
timeS, _, err := req.Option("interval").String()
|
||||
if err != nil {
|
||||
res.SetError(err, cmdkit.ErrNormal)
|
||||
return
|
||||
}
|
||||
timeS, _ := req.Options["interval"].(string)
|
||||
interval, err := time.ParseDuration(timeS)
|
||||
if err != nil {
|
||||
res.SetError(err, cmdkit.ErrNormal)
|
||||
return
|
||||
}
|
||||
|
||||
doPoll, _, err := req.Option("poll").Bool()
|
||||
if err != nil {
|
||||
res.SetError(err, cmdkit.ErrNormal)
|
||||
return
|
||||
}
|
||||
|
||||
doPoll, _ := req.Options["poll"].(bool)
|
||||
for {
|
||||
if pfound {
|
||||
stats := nd.Reporter.GetBandwidthForPeer(pid)
|
||||
@ -157,7 +140,7 @@ Example:
|
||||
}
|
||||
select {
|
||||
case <-time.After(interval):
|
||||
case <-req.Context().Done():
|
||||
case <-req.Context.Done():
|
||||
return
|
||||
}
|
||||
}
|
||||
@ -165,17 +148,13 @@ Example:
|
||||
},
|
||||
Type: metrics.Stats{},
|
||||
PostRun: cmds.PostRunMap{
|
||||
cmds.CLI: func(req cmds.Request, re cmds.ResponseEmitter) cmds.ResponseEmitter {
|
||||
cmds.CLI: func(req *cmds.Request, re cmds.ResponseEmitter) cmds.ResponseEmitter {
|
||||
reNext, res := cmds.NewChanResponsePair(req)
|
||||
|
||||
go func() {
|
||||
defer re.Close()
|
||||
|
||||
polling, _, err := res.Request().Option("poll").Bool()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
polling, _ := res.Request().Options["poll"].(bool)
|
||||
fmt.Fprintln(os.Stdout, "Total Up Total Down Rate Up Rate Down")
|
||||
for {
|
||||
v, err := res.Next()
|
||||
|
||||
@ -15,9 +15,9 @@ import (
|
||||
config "github.com/ipfs/go-ipfs/repo/config"
|
||||
"github.com/ipfs/go-ipfs/repo/fsrepo"
|
||||
|
||||
cmdkit "gx/ipfs/QmQp2a2Hhb7F6eK2A5hN8f9aJy4mtkEikL9Zj4cgB7d1dD/go-ipfs-cmdkit"
|
||||
mafilter "gx/ipfs/QmSMZwvs3n4GBikZ7hKzT17c3bk65FmyZo2JqtJ16swqCv/multiaddr-filter"
|
||||
swarm "gx/ipfs/QmUhvp4VoQ9cKDVLqAxciEKdm8ymBx2Syx4C1Tv6SmSTPa/go-libp2p-swarm"
|
||||
cmdkit "gx/ipfs/QmVD1W3MC8Hk1WZgFQPWWmBECJ3X72BgUYf9eCQ4PGzPps/go-ipfs-cmdkit"
|
||||
ma "gx/ipfs/QmW8s4zTsUoX1Q6CeYxVKPyqSKbF7H1YDUyTostBtZ8DaG/go-multiaddr"
|
||||
pstore "gx/ipfs/QmYijbtjCxFEjSXaudaQAUz3LN5VKLssm8WCUsRoqzXmQR/go-libp2p-peerstore"
|
||||
iaddr "gx/ipfs/QmdMeXVB1V1SAZcFzoCuM3zR9K8PeuzCYg4zXNHcHh6dHU/go-ipfs-addr"
|
||||
|
||||
@ -8,8 +8,8 @@ import (
|
||||
cmds "github.com/ipfs/go-ipfs/commands"
|
||||
config "github.com/ipfs/go-ipfs/repo/config"
|
||||
|
||||
"gx/ipfs/QmQp2a2Hhb7F6eK2A5hN8f9aJy4mtkEikL9Zj4cgB7d1dD/go-ipfs-cmdkit"
|
||||
manet "gx/ipfs/QmSGL5Uoa6gKHgBBwQG8u1CWKUC8ZnwaZiLgFVTFBR2bxr/go-multiaddr-net"
|
||||
"gx/ipfs/QmVD1W3MC8Hk1WZgFQPWWmBECJ3X72BgUYf9eCQ4PGzPps/go-ipfs-cmdkit"
|
||||
sysi "gx/ipfs/QmZRjKbHa6DenStpQJFiaPcEwkZqrx7TH6xTf342LDU3qM/go-sysinfo"
|
||||
)
|
||||
|
||||
|
||||
@ -12,7 +12,7 @@ import (
|
||||
path "github.com/ipfs/go-ipfs/path"
|
||||
tar "github.com/ipfs/go-ipfs/tar"
|
||||
|
||||
"gx/ipfs/QmQp2a2Hhb7F6eK2A5hN8f9aJy4mtkEikL9Zj4cgB7d1dD/go-ipfs-cmdkit"
|
||||
"gx/ipfs/QmVD1W3MC8Hk1WZgFQPWWmBECJ3X72BgUYf9eCQ4PGzPps/go-ipfs-cmdkit"
|
||||
)
|
||||
|
||||
var TarCmd = &cmds.Command{
|
||||
|
||||
@ -15,7 +15,7 @@ import (
|
||||
unixfs "github.com/ipfs/go-ipfs/unixfs"
|
||||
uio "github.com/ipfs/go-ipfs/unixfs/io"
|
||||
unixfspb "github.com/ipfs/go-ipfs/unixfs/pb"
|
||||
cmdkit "gx/ipfs/QmQp2a2Hhb7F6eK2A5hN8f9aJy4mtkEikL9Zj4cgB7d1dD/go-ipfs-cmdkit"
|
||||
cmdkit "gx/ipfs/QmVD1W3MC8Hk1WZgFQPWWmBECJ3X72BgUYf9eCQ4PGzPps/go-ipfs-cmdkit"
|
||||
)
|
||||
|
||||
type LsLink struct {
|
||||
|
||||
@ -4,7 +4,7 @@ import (
|
||||
cmds "github.com/ipfs/go-ipfs/commands"
|
||||
e "github.com/ipfs/go-ipfs/core/commands/e"
|
||||
|
||||
"gx/ipfs/QmQp2a2Hhb7F6eK2A5hN8f9aJy4mtkEikL9Zj4cgB7d1dD/go-ipfs-cmdkit"
|
||||
"gx/ipfs/QmVD1W3MC8Hk1WZgFQPWWmBECJ3X72BgUYf9eCQ4PGzPps/go-ipfs-cmdkit"
|
||||
)
|
||||
|
||||
var UnixFSCmd = &cmds.Command{
|
||||
|
||||
@ -10,7 +10,7 @@ import (
|
||||
e "github.com/ipfs/go-ipfs/core/commands/e"
|
||||
config "github.com/ipfs/go-ipfs/repo/config"
|
||||
fsrepo "github.com/ipfs/go-ipfs/repo/fsrepo"
|
||||
"gx/ipfs/QmQp2a2Hhb7F6eK2A5hN8f9aJy4mtkEikL9Zj4cgB7d1dD/go-ipfs-cmdkit"
|
||||
"gx/ipfs/QmVD1W3MC8Hk1WZgFQPWWmBECJ3X72BgUYf9eCQ4PGzPps/go-ipfs-cmdkit"
|
||||
)
|
||||
|
||||
type VersionOutput struct {
|
||||
|
||||
@ -7,12 +7,13 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
oldcmds "github.com/ipfs/go-ipfs/commands"
|
||||
core "github.com/ipfs/go-ipfs/core"
|
||||
corecommands "github.com/ipfs/go-ipfs/core/commands"
|
||||
config "github.com/ipfs/go-ipfs/repo/config"
|
||||
|
||||
cmds "gx/ipfs/QmP9vZfc5WSjfGTXmwX2EcicMFzmZ6fXn7HTdKYat6ccmH/go-ipfs-cmds"
|
||||
cmdsHttp "gx/ipfs/QmP9vZfc5WSjfGTXmwX2EcicMFzmZ6fXn7HTdKYat6ccmH/go-ipfs-cmds/http"
|
||||
cmds "gx/ipfs/QmTwKPLyeRKuDawuy6CAn1kRj1FVoqBEM8sviAUWN7NW9K/go-ipfs-cmds"
|
||||
cmdsHttp "gx/ipfs/QmTwKPLyeRKuDawuy6CAn1kRj1FVoqBEM8sviAUWN7NW9K/go-ipfs-cmds/http"
|
||||
)
|
||||
|
||||
const originEnvKey = "API_ORIGIN"
|
||||
@ -29,6 +30,8 @@ or
|
||||
ipfs daemon --api-http-header 'Access-Control-Allow-Origin: *'
|
||||
`
|
||||
|
||||
const APIPath = "/api/v0"
|
||||
|
||||
var defaultLocalhostOrigins = []string{
|
||||
"http://127.0.0.1:<port>",
|
||||
"https://127.0.0.1:<port>",
|
||||
@ -100,7 +103,7 @@ func patchCORSVars(c *cmdsHttp.ServerConfig, addr net.Addr) {
|
||||
c.SetAllowedOrigins(origins...)
|
||||
}
|
||||
|
||||
func commandsOption(cctx cmds.Context, command *cmds.Command) ServeOption {
|
||||
func commandsOption(cctx oldcmds.Context, command *cmds.Command) ServeOption {
|
||||
return func(n *core.IpfsNode, l net.Listener, mux *http.ServeMux) (*http.ServeMux, error) {
|
||||
|
||||
cfg := cmdsHttp.NewServerConfig()
|
||||
@ -115,16 +118,16 @@ func commandsOption(cctx cmds.Context, command *cmds.Command) ServeOption {
|
||||
addCORSDefaults(cfg)
|
||||
patchCORSVars(cfg, l.Addr())
|
||||
|
||||
cmdHandler := cmdsHttp.NewHandler(cctx, command, cfg)
|
||||
mux.Handle(cmdsHttp.ApiPath+"/", cmdHandler)
|
||||
cmdHandler := cmdsHttp.NewHandler(&cctx, command, cfg)
|
||||
mux.Handle(APIPath, cmdHandler)
|
||||
return mux, nil
|
||||
}
|
||||
}
|
||||
|
||||
func CommandsOption(cctx cmds.Context) ServeOption {
|
||||
func CommandsOption(cctx oldcmds.Context) ServeOption {
|
||||
return commandsOption(cctx, corecommands.Root)
|
||||
}
|
||||
|
||||
func CommandsROOption(cctx cmds.Context) ServeOption {
|
||||
func CommandsROOption(cctx oldcmds.Context) ServeOption {
|
||||
return commandsOption(cctx, corecommands.RootRO)
|
||||
}
|
||||
|
||||
@ -25,8 +25,8 @@ import (
|
||||
unixfs "github.com/ipfs/go-ipfs/unixfs"
|
||||
|
||||
node "gx/ipfs/QmNwUEK7QbwSqyKBu3mMtToo8SUc6wQJ7gdZq4gGGJqfnf/go-ipld-format"
|
||||
files "gx/ipfs/QmQp2a2Hhb7F6eK2A5hN8f9aJy4mtkEikL9Zj4cgB7d1dD/go-ipfs-cmdkit/files"
|
||||
logging "gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log"
|
||||
files "gx/ipfs/QmVD1W3MC8Hk1WZgFQPWWmBECJ3X72BgUYf9eCQ4PGzPps/go-ipfs-cmdkit/files"
|
||||
ds "gx/ipfs/QmdHG8MAuARdGHxx4rPQASLcvhz24fzjSQq7AJRAQEorq5/go-datastore"
|
||||
syncds "gx/ipfs/QmdHG8MAuARdGHxx4rPQASLcvhz24fzjSQq7AJRAQEorq5/go-datastore/sync"
|
||||
cid "gx/ipfs/QmeSrf6pzut73u6zLQkRFQ3ygt3k6XFT2kjdYP8Tnkwwyg/go-cid"
|
||||
|
||||
@ -19,9 +19,9 @@ import (
|
||||
"github.com/ipfs/go-ipfs/repo/config"
|
||||
ds2 "github.com/ipfs/go-ipfs/thirdparty/datastore2"
|
||||
pi "github.com/ipfs/go-ipfs/thirdparty/posinfo"
|
||||
"gx/ipfs/QmYsEQydGrsxNZfAiskvQ76N2xE9hDQtSAkRSynwMiUK3c/go-block-format"
|
||||
|
||||
"gx/ipfs/QmQp2a2Hhb7F6eK2A5hN8f9aJy4mtkEikL9Zj4cgB7d1dD/go-ipfs-cmdkit/files"
|
||||
"gx/ipfs/QmVD1W3MC8Hk1WZgFQPWWmBECJ3X72BgUYf9eCQ4PGzPps/go-ipfs-cmdkit/files"
|
||||
"gx/ipfs/QmYsEQydGrsxNZfAiskvQ76N2xE9hDQtSAkRSynwMiUK3c/go-block-format"
|
||||
cid "gx/ipfs/QmeSrf6pzut73u6zLQkRFQ3ygt3k6XFT2kjdYP8Tnkwwyg/go-cid"
|
||||
)
|
||||
|
||||
|
||||
@ -9,7 +9,7 @@ import (
|
||||
ft "github.com/ipfs/go-ipfs/unixfs"
|
||||
|
||||
node "gx/ipfs/QmNwUEK7QbwSqyKBu3mMtToo8SUc6wQJ7gdZq4gGGJqfnf/go-ipld-format"
|
||||
files "gx/ipfs/QmQp2a2Hhb7F6eK2A5hN8f9aJy4mtkEikL9Zj4cgB7d1dD/go-ipfs-cmdkit/files"
|
||||
files "gx/ipfs/QmVD1W3MC8Hk1WZgFQPWWmBECJ3X72BgUYf9eCQ4PGzPps/go-ipfs-cmdkit/files"
|
||||
cid "gx/ipfs/QmeSrf6pzut73u6zLQkRFQ3ygt3k6XFT2kjdYP8Tnkwwyg/go-cid"
|
||||
)
|
||||
|
||||
|
||||
@ -11,7 +11,7 @@ import (
|
||||
h "github.com/ipfs/go-ipfs/importer/helpers"
|
||||
trickle "github.com/ipfs/go-ipfs/importer/trickle"
|
||||
dag "github.com/ipfs/go-ipfs/merkledag"
|
||||
"gx/ipfs/QmQp2a2Hhb7F6eK2A5hN8f9aJy4mtkEikL9Zj4cgB7d1dD/go-ipfs-cmdkit/files"
|
||||
"gx/ipfs/QmVD1W3MC8Hk1WZgFQPWWmBECJ3X72BgUYf9eCQ4PGzPps/go-ipfs-cmdkit/files"
|
||||
|
||||
node "gx/ipfs/QmNwUEK7QbwSqyKBu3mMtToo8SUc6wQJ7gdZq4gGGJqfnf/go-ipld-format"
|
||||
)
|
||||
|
||||
@ -414,14 +414,14 @@
|
||||
"version": "2.1.2"
|
||||
},
|
||||
{
|
||||
"hash": "QmP9vZfc5WSjfGTXmwX2EcicMFzmZ6fXn7HTdKYat6ccmH",
|
||||
"hash": "QmTwKPLyeRKuDawuy6CAn1kRj1FVoqBEM8sviAUWN7NW9K",
|
||||
"name": "go-ipfs-cmds",
|
||||
"version": "0.4.15"
|
||||
"version": "0.5.0-dev"
|
||||
},
|
||||
{
|
||||
"hash": "QmQp2a2Hhb7F6eK2A5hN8f9aJy4mtkEikL9Zj4cgB7d1dD",
|
||||
"hash": "QmVD1W3MC8Hk1WZgFQPWWmBECJ3X72BgUYf9eCQ4PGzPps",
|
||||
"name": "go-ipfs-cmdkit",
|
||||
"version": "0.3.6"
|
||||
"version": "1.0.0-dev"
|
||||
},
|
||||
{
|
||||
"author": "whyrusleeping",
|
||||
|
||||
Loading…
Reference in New Issue
Block a user