Skip to content

Commit

Permalink
Merge pull request #5392 from ipfs/refactor/name-cmd-dir
Browse files Browse the repository at this point in the history
name cmd: move subcommands to subdirectory
  • Loading branch information
Stebalien authored Aug 22, 2018
2 parents 30fe06c + faf7aac commit 4fd8a6e
Show file tree
Hide file tree
Showing 27 changed files with 195 additions and 174 deletions.
3 changes: 2 additions & 1 deletion core/commands/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"strings"

core "github.com/ipfs/go-ipfs/core"
cmdenv "github.com/ipfs/go-ipfs/core/commands/cmdenv"
"github.com/ipfs/go-ipfs/core/coreunix"
filestore "github.com/ipfs/go-ipfs/filestore"
ft "gx/ipfs/QmQjEpRiwVvtowhq69dAtB4jhioPVFXiCcWZm9Sfgn7eqc/go-unixfs"
Expand Down Expand Up @@ -141,7 +142,7 @@ You can now check what blocks have been created by:
return nil
},
Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) {
n, err := GetNode(env)
n, err := cmdenv.GetNode(env)
if err != nil {
res.SetError(err, cmdkit.ErrNormal)
return
Expand Down
13 changes: 7 additions & 6 deletions core/commands/bitswap.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

oldcmds "github.com/ipfs/go-ipfs/commands"
lgc "github.com/ipfs/go-ipfs/commands/legacy"
cmdenv "github.com/ipfs/go-ipfs/core/commands/cmdenv"
e "github.com/ipfs/go-ipfs/core/commands/e"
bitswap "gx/ipfs/QmTtmrK4iiM3MxWNA3pvbM9ekQiGZAiFyo57GP8B9FFgtz/go-bitswap"
decision "gx/ipfs/QmTtmrK4iiM3MxWNA3pvbM9ekQiGZAiFyo57GP8B9FFgtz/go-bitswap/decision"
Expand Down Expand Up @@ -48,7 +49,7 @@ var unwantCmd = &oldcmds.Command{
}

if !nd.OnlineMode() {
res.SetError(errNotOnline, cmdkit.ErrClient)
res.SetError(ErrNotOnline, cmdkit.ErrClient)
return
}

Expand Down Expand Up @@ -97,7 +98,7 @@ Print out all blocks currently on the bitswap wantlist for the local peer.`,
}

if !nd.OnlineMode() {
res.SetError(errNotOnline, cmdkit.ErrClient)
res.SetError(ErrNotOnline, cmdkit.ErrClient)
return
}

Expand Down Expand Up @@ -140,14 +141,14 @@ var bitswapStatCmd = &cmds.Command{
},
Type: bitswap.Stat{},
Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) {
nd, err := GetNode(env)
nd, err := cmdenv.GetNode(env)
if err != nil {
res.SetError(err, cmdkit.ErrNormal)
return
}

if !nd.OnlineMode() {
res.SetError(errNotOnline, cmdkit.ErrClient)
res.SetError(ErrNotOnline, cmdkit.ErrClient)
return
}

Expand Down Expand Up @@ -215,7 +216,7 @@ prints the ledger associated with a given peer.
}

if !nd.OnlineMode() {
res.SetError(errNotOnline, cmdkit.ErrClient)
res.SetError(ErrNotOnline, cmdkit.ErrClient)
return
}

Expand Down Expand Up @@ -272,7 +273,7 @@ Trigger reprovider to announce our data to network.
}

if !nd.OnlineMode() {
res.SetError(errNotOnline, cmdkit.ErrClient)
res.SetError(ErrNotOnline, cmdkit.ErrClient)
return
}

Expand Down
7 changes: 4 additions & 3 deletions core/commands/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"os"

util "github.com/ipfs/go-ipfs/blocks/blockstoreutil"
cmdenv "github.com/ipfs/go-ipfs/core/commands/cmdenv"
e "github.com/ipfs/go-ipfs/core/commands/e"

"gx/ipfs/QmPTfgFTo9PFr1PvPKyKoeMgBvYPh6cX3aDP7DHKVbnCbi/go-ipfs-cmds"
Expand Down Expand Up @@ -137,7 +138,7 @@ than 'sha2-256' or format to anything other than 'v0' will result in CIDv1.
cmdkit.IntOption("mhlen", "multihash hash length").WithDefault(-1),
},
Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) {
n, err := GetNode(env)
n, err := cmdenv.GetNode(env)
if err != nil {
res.SetError(err, cmdkit.ErrNormal)
return
Expand Down Expand Up @@ -248,7 +249,7 @@ func getBlockForKey(ctx context.Context, env cmds.Environment, skey string) (blo
return nil, fmt.Errorf("zero length cid invalid")
}

n, err := GetNode(env)
n, err := cmdenv.GetNode(env)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -282,7 +283,7 @@ It takes a list of base58 encoded multihashes to remove.
cmdkit.BoolOption("quiet", "q", "Write minimal output."),
},
Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) {
n, err := GetNode(env)
n, err := cmdenv.GetNode(env)
if err != nil {
res.SetError(err, cmdkit.ErrNormal)
return
Expand Down
3 changes: 2 additions & 1 deletion core/commands/cat.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"os"

core "github.com/ipfs/go-ipfs/core"
cmdenv "github.com/ipfs/go-ipfs/core/commands/cmdenv"
coreunix "github.com/ipfs/go-ipfs/core/coreunix"

cmds "gx/ipfs/QmPTfgFTo9PFr1PvPKyKoeMgBvYPh6cX3aDP7DHKVbnCbi/go-ipfs-cmds"
Expand All @@ -29,7 +30,7 @@ var CatCmd = &cmds.Command{
cmdkit.IntOption("length", "l", "Maximum number of bytes to read."),
},
Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) {
node, err := GetNode(env)
node, err := cmdenv.GetNode(env)
if err != nil {
res.SetError(err, cmdkit.ErrNormal)
return
Expand Down
2 changes: 1 addition & 1 deletion core/commands/env.go → core/commands/cmdenv/env.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package commands
package cmdenv

import (
"fmt"
Expand Down
10 changes: 5 additions & 5 deletions core/commands/dht.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ var findProvidersDhtCmd = &cmds.Command{
}

if n.Routing == nil {
res.SetError(errNotOnline, cmdkit.ErrNormal)
res.SetError(ErrNotOnline, cmdkit.ErrNormal)
return
}

Expand Down Expand Up @@ -272,7 +272,7 @@ var provideRefDhtCmd = &cmds.Command{
}

if n.Routing == nil {
res.SetError(errNotOnline, cmdkit.ErrNormal)
res.SetError(ErrNotOnline, cmdkit.ErrNormal)
return
}

Expand Down Expand Up @@ -424,7 +424,7 @@ var findPeerDhtCmd = &cmds.Command{
}

if n.Routing == nil {
res.SetError(errNotOnline, cmdkit.ErrNormal)
res.SetError(ErrNotOnline, cmdkit.ErrNormal)
return
}

Expand Down Expand Up @@ -529,7 +529,7 @@ Different key types can specify other 'best' rules.
}

if n.Routing == nil {
res.SetError(errNotOnline, cmdkit.ErrNormal)
res.SetError(ErrNotOnline, cmdkit.ErrNormal)
return
}

Expand Down Expand Up @@ -643,7 +643,7 @@ NOTE: A value may not exceed 2048 bytes.
}

if n.Routing == nil {
res.SetError(errNotOnline, cmdkit.ErrNormal)
res.SetError(ErrNotOnline, cmdkit.ErrNormal)
return
}

Expand Down
7 changes: 4 additions & 3 deletions core/commands/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

cmds "github.com/ipfs/go-ipfs/commands"
e "github.com/ipfs/go-ipfs/core/commands/e"
ncmd "github.com/ipfs/go-ipfs/core/commands/name"
namesys "github.com/ipfs/go-ipfs/namesys"
nsopts "github.com/ipfs/go-ipfs/namesys/opts"

Expand Down Expand Up @@ -72,7 +73,7 @@ The resolver can recursively resolve:
res.SetError(err, cmdkit.ErrNormal)
return
}
res.SetOutput(&ResolvedPath{output})
res.SetOutput(&ncmd.ResolvedPath{Path: output})
},
Marshalers: cmds.MarshalerMap{
cmds.Text: func(res cmds.Response) (io.Reader, error) {
Expand All @@ -81,12 +82,12 @@ The resolver can recursively resolve:
return nil, err
}

output, ok := v.(*ResolvedPath)
output, ok := v.(*ncmd.ResolvedPath)
if !ok {
return nil, e.TypeErr(output, v)
}
return strings.NewReader(output.Path.String() + "\n"), nil
},
},
Type: ResolvedPath{},
Type: ncmd.ResolvedPath{},
}
5 changes: 3 additions & 2 deletions core/commands/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
oldcmds "github.com/ipfs/go-ipfs/commands"
lgc "github.com/ipfs/go-ipfs/commands/legacy"
core "github.com/ipfs/go-ipfs/core"
cmdenv "github.com/ipfs/go-ipfs/core/commands/cmdenv"
e "github.com/ipfs/go-ipfs/core/commands/e"
ft "gx/ipfs/QmQjEpRiwVvtowhq69dAtB4jhioPVFXiCcWZm9Sfgn7eqc/go-unixfs"
uio "gx/ipfs/QmQjEpRiwVvtowhq69dAtB4jhioPVFXiCcWZm9Sfgn7eqc/go-unixfs/io"
Expand Down Expand Up @@ -114,7 +115,7 @@ var filesStatCmd = &cmds.Command{
res.SetError(err, cmdkit.ErrClient)
}

node, err := GetNode(env)
node, err := cmdenv.GetNode(env)
if err != nil {
res.SetError(err, cmdkit.ErrNormal)
return
Expand Down Expand Up @@ -745,7 +746,7 @@ stat' on the file or any of its ancestors.
return
}

nd, err := GetNode(env)
nd, err := cmdenv.GetNode(env)
if err != nil {
re.SetError(err, cmdkit.ErrNormal)
return
Expand Down
3 changes: 2 additions & 1 deletion core/commands/filestore.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
oldCmds "github.com/ipfs/go-ipfs/commands"
lgc "github.com/ipfs/go-ipfs/commands/legacy"
"github.com/ipfs/go-ipfs/core"
cmdenv "github.com/ipfs/go-ipfs/core/commands/cmdenv"
e "github.com/ipfs/go-ipfs/core/commands/e"
"github.com/ipfs/go-ipfs/filestore"

Expand Down Expand Up @@ -231,7 +232,7 @@ var dupsFileStore = &oldCmds.Command{
}

func getFilestore(env interface{}) (*core.IpfsNode, *filestore.Filestore, error) {
n, err := GetNode(env)
n, err := cmdenv.GetNode(env)
if err != nil {
return nil, nil, err
}
Expand Down
9 changes: 5 additions & 4 deletions core/commands/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,16 @@ import (
"strings"

core "github.com/ipfs/go-ipfs/core"
cmdenv "github.com/ipfs/go-ipfs/core/commands/cmdenv"
e "github.com/ipfs/go-ipfs/core/commands/e"
uarchive "gx/ipfs/QmQjEpRiwVvtowhq69dAtB4jhioPVFXiCcWZm9Sfgn7eqc/go-unixfs/archive"
dag "gx/ipfs/QmRiQCJZ91B7VNmLvA6sxzDuBJGSojS3uXHHVuNr3iueNZ/go-merkledag"
path "gx/ipfs/QmdMPBephdLYNESkruDX2hcDTgFYhoCt4LimWhgnomSdV2/go-path"

"gx/ipfs/QmPTfgFTo9PFr1PvPKyKoeMgBvYPh6cX3aDP7DHKVbnCbi/go-ipfs-cmds"
"gx/ipfs/QmPtj12fdwuAqj9sBSTNUxBNu8kCGNp8b3o8yUzMm5GHpq/pb"
tar "gx/ipfs/QmQine7gvHncNevKtG9QXxf3nXcwSj6aDDmMm52mHofEEp/tar-utils"
uarchive "gx/ipfs/QmQjEpRiwVvtowhq69dAtB4jhioPVFXiCcWZm9Sfgn7eqc/go-unixfs/archive"
dag "gx/ipfs/QmRiQCJZ91B7VNmLvA6sxzDuBJGSojS3uXHHVuNr3iueNZ/go-merkledag"
"gx/ipfs/QmSP88ryZkHSRn1fnngAaV2Vcn63WUJzAavnRM9CVdU1Ky/go-ipfs-cmdkit"
path "gx/ipfs/QmdMPBephdLYNESkruDX2hcDTgFYhoCt4LimWhgnomSdV2/go-path"
)

var ErrInvalidCompressionLevel = errors.New("compression level must be between 1 and 9")
Expand Down Expand Up @@ -59,7 +60,7 @@ may also specify the level of compression by specifying '-l=<1-9>'.
return
}

node, err := GetNode(env)
node, err := cmdenv.GetNode(env)
if err != nil {
res.SetError(err, cmdkit.ErrNormal)
return
Expand Down
9 changes: 5 additions & 4 deletions core/commands/keystore.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"io"
"text/tabwriter"

cmdenv "github.com/ipfs/go-ipfs/core/commands/cmdenv"
"github.com/ipfs/go-ipfs/core/commands/e"
"github.com/ipfs/go-ipfs/core/coreapi/interface/options"

Expand Down Expand Up @@ -66,7 +67,7 @@ var keyGenCmd = &cmds.Command{
cmdkit.StringArg("name", true, false, "name of key to create"),
},
Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) {
api, err := GetApi(env)
api, err := cmdenv.GetApi(env)
if err != nil {
res.SetError(err, cmdkit.ErrNormal)
return
Expand Down Expand Up @@ -125,7 +126,7 @@ var keyListCmd = &cmds.Command{
cmdkit.BoolOption("l", "Show extra information about keys."),
},
Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) {
api, err := GetApi(env)
api, err := cmdenv.GetApi(env)
if err != nil {
res.SetError(err, cmdkit.ErrNormal)
return
Expand Down Expand Up @@ -163,7 +164,7 @@ var keyRenameCmd = &cmds.Command{
cmdkit.BoolOption("force", "f", "Allow to overwrite an existing key."),
},
Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) {
api, err := GetApi(env)
api, err := cmdenv.GetApi(env)
if err != nil {
res.SetError(err, cmdkit.ErrNormal)
return
Expand Down Expand Up @@ -215,7 +216,7 @@ var keyRmCmd = &cmds.Command{
cmdkit.BoolOption("l", "Show extra information about keys."),
},
Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) {
api, err := GetApi(env)
api, err := cmdenv.GetApi(env)
if err != nil {
res.SetError(err, cmdkit.ErrNormal)
return
Expand Down
2 changes: 1 addition & 1 deletion core/commands/mount_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ baz

// error if we aren't running node in online mode
if node.LocalMode() {
res.SetError(errNotOnline, cmdkit.ErrClient)
res.SetError(ErrNotOnline, cmdkit.ErrClient)
return
}

Expand Down
Loading

0 comments on commit 4fd8a6e

Please sign in to comment.