Skip to content

Commit

Permalink
name cmd: move subcommands to subdirectory
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Łukasz Magiera <[email protected]>
  • Loading branch information
magik6k committed Aug 20, 2018
1 parent afda4ca commit 2a3008b
Show file tree
Hide file tree
Showing 27 changed files with 193 additions and 173 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"
mfs "github.com/ipfs/go-ipfs/mfs"
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/QmQk1Rqy5XSBzXykMSsgiXfnhivCSnFpykx4M2j6DD1nBH/go-bitswap"
decision "gx/ipfs/QmQk1Rqy5XSBzXykMSsgiXfnhivCSnFpykx4M2j6DD1nBH/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/QmPVqQHEfLpqK7JLCsUkyam7rhuV3MAeZ9gueQQCrBwCta/go-ipfs-cmdkit"
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"

"gx/ipfs/QmPVqQHEfLpqK7JLCsUkyam7rhuV3MAeZ9gueQQCrBwCta/go-ipfs-cmdkit"
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{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"
mfs "github.com/ipfs/go-ipfs/mfs"
dag "gx/ipfs/QmQzSpSjkdGHW6WFBhUG6P3t9K8yv7iucucT1cQaqJ6tgd/go-merkledag"
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"
dag "gx/ipfs/QmQzSpSjkdGHW6WFBhUG6P3t9K8yv7iucucT1cQaqJ6tgd/go-merkledag"
path "gx/ipfs/QmWMcvZbNvk5codeqbm7L89C9kqSwka4KaHnDb8HRnxsSL/go-path"
uarchive "gx/ipfs/QmWv8MYwgPK4zXYv1et1snWJ6FWGqaL6xY2y9X1bRSKBxk/go-unixfs/archive"

"gx/ipfs/QmPVqQHEfLpqK7JLCsUkyam7rhuV3MAeZ9gueQQCrBwCta/go-ipfs-cmdkit"
"gx/ipfs/QmPtj12fdwuAqj9sBSTNUxBNu8kCGNp8b3o8yUzMm5GHpq/pb"
tar "gx/ipfs/QmQine7gvHncNevKtG9QXxf3nXcwSj6aDDmMm52mHofEEp/tar-utils"
dag "gx/ipfs/QmQzSpSjkdGHW6WFBhUG6P3t9K8yv7iucucT1cQaqJ6tgd/go-merkledag"
"gx/ipfs/QmUQb3xtNzkQCgTj2NjaqcJZNv2nfSSub2QAdy9DtQMRBT/go-ipfs-cmds"
path "gx/ipfs/QmWMcvZbNvk5codeqbm7L89C9kqSwka4KaHnDb8HRnxsSL/go-path"
uarchive "gx/ipfs/QmWv8MYwgPK4zXYv1et1snWJ6FWGqaL6xY2y9X1bRSKBxk/go-unixfs/archive"
)

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 2a3008b

Please sign in to comment.