From d37ab817e6cc9f2eada9549de50991f4c63061af Mon Sep 17 00:00:00 2001 From: Dominic Della Valle Date: Mon, 20 Sep 2021 07:52:48 -0400 Subject: [PATCH 1/2] lint: remove unnecessary nil checks for request Request is supplied by `Parse` which states: "This function never returns nil, even on error." making these checks unnecessary. --- cli/run.go | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/cli/run.go b/cli/run.go index 46b68280..19a4f130 100644 --- a/cli/run.go +++ b/cli/run.go @@ -8,7 +8,7 @@ import ( "strings" "time" - "github.com/ipfs/go-ipfs-cmds" + cmds "github.com/ipfs/go-ipfs-cmds" ) // ExitError is the error used when a specific exit code needs to be returned. @@ -59,12 +59,7 @@ func Run(ctx context.Context, root *cmds.Command, helpFunc = LongHelp } - var path []string - if req != nil { - path = req.Path - } - - if err := helpFunc(cmdline[0], root, path, w); err != nil { + if err := helpFunc(cmdline[0], root, req.Path, w); err != nil { // This should not happen panic(err) } @@ -86,7 +81,7 @@ func Run(ctx context.Context, root *cmds.Command, printErr(errParse) // this was a user error, print help - if req != nil && req.Command != nil { + if req.Command != nil { fmt.Fprintln(stderr) // i need some space printHelp(false, stderr) } @@ -97,7 +92,7 @@ func Run(ctx context.Context, root *cmds.Command, // here we handle the cases where // - commands with no Run func are invoked directly. // - the main command is invoked. - if req == nil || req.Command == nil || req.Command.Run == nil { + if req.Command == nil || req.Command.Run == nil { printHelp(false, stdout) return nil } From 7dc37720cf094ca0458a81d9c9d2e616734d0dd0 Mon Sep 17 00:00:00 2001 From: Dominic Della Valle Date: Mon, 20 Sep 2021 08:02:54 -0400 Subject: [PATCH 2/2] lint: remove redundant default encoding assignment `Parse` already does this internally, which is where our `req` is derived from. --- cli/run.go | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/cli/run.go b/cli/run.go index 19a4f130..0317cca1 100644 --- a/cli/run.go +++ b/cli/run.go @@ -97,8 +97,6 @@ func Run(ctx context.Context, root *cmds.Command, return nil } - cmd := req.Command - env, err := buildEnv(req.Context, req) if err != nil { printErr(err) @@ -114,14 +112,6 @@ func Run(ctx context.Context, root *cmds.Command, return err } - encTypeStr, _ := req.Options[cmds.EncLong].(string) - encType := cmds.EncodingType(encTypeStr) - - // use JSON if text was requested but the command doesn't have a text-encoder - if _, ok := cmd.Encoders[encType]; encType == cmds.Text && !ok { - req.Options[cmds.EncLong] = cmds.JSON - } - re, err := NewResponseEmitter(stdout, stderr, req) if err != nil { printErr(err)