@cryptotaxi247 / kubo / commits / efa280c53

commands/files: use MakeTypedEncoder

License: MIT Signed-off-by: Overbool <overbool.xu@gmail.com>

Overbool committed Oct 27, 2018 at 10:29 UTC efa280c531511f40b286a70ffee23e069ae0a2ed
1 file changed +7 -13
core/commands/files.go
+7 -13
@@ -12,8 +12,7 @@ import (
12
13 core "github.com/ipfs/go-ipfs/core"
14 cmdenv "github.com/ipfs/go-ipfs/core/commands/cmdenv"
15 - e "github.com/ipfs/go-ipfs/core/commands/e"
16 - "github.com/ipfs/go-ipfs/core/coreapi/interface"
15 + iface "github.com/ipfs/go-ipfs/core/coreapi/interface"
16
17 humanize "gx/ipfs/QmPSBJL4momYnE7DcUyk2DVhD6rH488ZmHBGLbxNdhU44K/go-humanize"
18 cid "gx/ipfs/QmPSQnBKM9g7BaUcZCvswUJVscQ1ipjmwxN5PXCjkp9EQ7/go-cid"
@@ -171,12 +170,7 @@ var filesStatCmd = &cmds.Command{
170 return cmds.EmitOnce(res, o)
171 },
172 Encoders: cmds.EncoderMap{
174 - cmds.Text: cmds.MakeEncoder(func(req *cmds.Request, w io.Writer, v interface{}) error {
175 - out, ok := v.(*statOutput)
176 - if !ok {
177 - return e.TypeErr(out, v)
178 - }
179 -
173 + cmds.Text: cmds.MakeTypedEncoder(func(req *cmds.Request, w io.Writer, out *statOutput) error {
174 s, _ := statGetFormatOptions(req)
175 s = strings.Replace(s, "<hash>", out.Hash, -1)
176 s = strings.Replace(s, "<size>", fmt.Sprintf("%d", out.Size), -1)
@@ -952,11 +946,11 @@ Remove files or directories.
946 cmdkit.StringArg("path", true, true, "File to remove."),
947 },
948 Options: []cmdkit.Option{
955 - cmdkit.BoolOption("recursive", "r", "Recursively remove directories."),
956 - cmdkit.BoolOption("force", "Forcibly remove target at path; implies -r for directories"),
949 + cmdkit.BoolOption(recursiveOptionName, "r", "Recursively remove directories."),
950 + cmdkit.BoolOption(forceOptionName, "Forcibly remove target at path; implies -r for directories"),
951 },
952 Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error {
959 - nd, err :=cmdenv.GetNode(env)
953 + nd, err := cmdenv.GetNode(env)
954 if err != nil {
955 return err
956 }
@@ -988,7 +982,7 @@ Remove files or directories.
982
983 // if '--force' specified, it will remove anything else,
984 // including file, directory, corrupted node, etc
991 - force, _ := req.Options["force"].(bool)
985 + force, _ := req.Options[forceOptionName].(bool)
986 if force {
987 err := pdir.Unlink(name)
988 if err != nil {
@@ -1005,7 +999,7 @@ Remove files or directories.
999 return err
1000 }
1001
1008 - dashr, _ := req.Options["r"].(bool)
1002 + dashr, _ := req.Options[recursiveOptionName].(bool)
1003
1004 switch child.(type) {
1005 case *mfs.Directory: