Skip to content

minor cleanup for cli.Run #219

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 4 additions & 19 deletions cli/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -97,13 +92,11 @@ 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
}

cmd := req.Command

env, err := buildEnv(req.Context, req)
if err != nil {
printErr(err)
Expand All @@ -119,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)
Expand Down