From f43abc347167b860cd2606787af6c13b4c336c91 Mon Sep 17 00:00:00 2001 From: gammazero <11790789+gammazero@users.noreply.github.com> Date: Thu, 14 Aug 2025 17:43:54 -1000 Subject: [PATCH 1/2] update dependencies code style: remove else after return sort using slices.SortFunc --- cli/parse.go | 17 ++++++++--------- cli/run.go | 3 ++- go.mod | 8 ++++---- go.sum | 16 ++++++++-------- http/parse.go | 3 ++- http/response.go | 21 +++++++++++---------- writer.go | 28 ++++++++++++---------------- 7 files changed, 47 insertions(+), 49 deletions(-) diff --git a/cli/parse.go b/cli/parse.go index 379d588a..2ef42c31 100644 --- a/cli/parse.go +++ b/cli/parse.go @@ -10,7 +10,7 @@ import ( "path/filepath" "reflect" "runtime" - "sort" + "slices" "strings" "github.com/ipfs/boxo/files" @@ -382,8 +382,8 @@ func parseArgs(req *cmds.Request, root *cmds.Command, stdin *os.File) error { fileArgs = append(fileArgs, files.FileEntry(stdinName(req), fileStdin)) } if len(fileArgs) > 0 { - sort.Slice(fileArgs, func(i, j int) bool { - return fileArgs[i].Name() < fileArgs[j].Name() + slices.SortFunc(fileArgs, func(a, b files.DirEntry) int { + return strings.Compare(a.Name(), b.Name()) }) req.Files = files.NewSliceDirectory(fileArgs) } @@ -419,9 +419,8 @@ func splitkv(opt string) (k, v string, ok bool) { split := strings.SplitN(opt, "=", 2) if len(split) == 2 { return split[0], split[1], true - } else { - return opt, "", false } + return opt, "", false } func parseOpt(opt, value string, opts map[string]cmds.Option) (string, interface{}, error) { @@ -454,7 +453,6 @@ func (st *parseState) parseShortOpts(optDefs map[string]cmds.Option) ([]kv, erro } kvs = append(kvs, kv{Key: k, Value: v}) - } else { LOOP: for j := 0; j < len(k); { @@ -514,7 +512,8 @@ func (st *parseState) parseLongOpt(optDefs map[string]cmds.Option) (string, inte } if optDef.Type() == cmds.Bool { return k, true, nil - } else if st.i < len(st.cmdline)-1 { + } + if st.i < len(st.cmdline)-1 { st.i++ v = st.peek() } else { @@ -530,8 +529,8 @@ func getArgDef(i int, argDefs []cmds.Argument) *cmds.Argument { if i < len(argDefs) { // get the argument definition (usually just argDefs[i]) return &argDefs[i] - - } else if len(argDefs) > 0 { + } + if len(argDefs) > 0 { // but if i > len(argDefs) we use the last argument definition) return &argDefs[len(argDefs)-1] } diff --git a/cli/run.go b/cli/run.go index 7465827d..d0c59cb1 100644 --- a/cli/run.go +++ b/cli/run.go @@ -75,7 +75,8 @@ func Run(ctx context.Context, root *cmds.Command, err := HandleHelp(cmdline[0], req, stdout) if err == nil { return nil - } else if err != ErrNoHelpRequested { + } + if err != ErrNoHelpRequested { return err } // no help requested, continue. diff --git a/go.mod b/go.mod index e1c97117..e788ab97 100644 --- a/go.mod +++ b/go.mod @@ -3,11 +3,11 @@ module github.com/ipfs/go-ipfs-cmds go 1.23.10 require ( - github.com/ipfs/boxo v0.33.0 - github.com/ipfs/go-log/v2 v2.6.0 + github.com/ipfs/boxo v0.33.1 + github.com/ipfs/go-log/v2 v2.8.1 github.com/rs/cors v1.11.1 github.com/texttheater/golang-levenshtein v1.0.1 - golang.org/x/term v0.33.0 + golang.org/x/term v0.34.0 ) require ( @@ -15,7 +15,7 @@ require ( github.com/mattn/go-isatty v0.0.20 // indirect go.uber.org/multierr v1.11.0 // indirect go.uber.org/zap v1.27.0 // indirect - golang.org/x/sys v0.34.0 // indirect + golang.org/x/sys v0.35.0 // indirect ) retract v1.0.22 // old gx tag accidentally pushed as go tag diff --git a/go.sum b/go.sum index 90413531..43dbc8dd 100644 --- a/go.sum +++ b/go.sum @@ -2,10 +2,10 @@ github.com/crackcomm/go-gitignore v0.0.0-20241020182519-7843d2ba8fdf h1:dwGgBWn8 github.com/crackcomm/go-gitignore v0.0.0-20241020182519-7843d2ba8fdf/go.mod h1:p1d6YEZWvFzEh4KLyvBcVSnrfNDDvK2zfK/4x2v/4pE= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/ipfs/boxo v0.33.0 h1:9ow3chwkDzMj0Deq4AWRUEI7WnIIV7SZhPTzzG2mmfw= -github.com/ipfs/boxo v0.33.0/go.mod h1:3IPh7YFcCIcKp6o02mCHovrPntoT5Pctj/7j4syh/RM= -github.com/ipfs/go-log/v2 v2.6.0 h1:2Nu1KKQQ2ayonKp4MPo6pXCjqw1ULc9iohRqWV5EYqg= -github.com/ipfs/go-log/v2 v2.6.0/go.mod h1:p+Efr3qaY5YXpx9TX7MoLCSEZX5boSWj9wh86P5HJa8= +github.com/ipfs/boxo v0.33.1 h1:89m+ksw+cYi0ecTNTJ71IRS5ZrLiovmO6XWHIOGhAEg= +github.com/ipfs/boxo v0.33.1/go.mod h1:KwlJTzv5fb1GLlA9KyMqHQmvP+4mrFuiE3PnjdrPJHs= +github.com/ipfs/go-log/v2 v2.8.1 h1:Y/X36z7ASoLJaYIJAL4xITXgwf7RVeqb1+/25aq/Xk0= +github.com/ipfs/go-log/v2 v2.8.1/go.mod h1:NyhTBcZmh2Y55eWVjOeKf8M7e4pnJYM3yDZNxQBWEEY= github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= @@ -23,9 +23,9 @@ go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN8 go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8= go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.34.0 h1:H5Y5sJ2L2JRdyv7ROF1he/lPdvFsd0mJHFw2ThKHxLA= -golang.org/x/sys v0.34.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= -golang.org/x/term v0.33.0 h1:NuFncQrRcaRvVmgRkvM3j/F00gWIAlcmlB8ACEKmGIg= -golang.org/x/term v0.33.0/go.mod h1:s18+ql9tYWp1IfpV9DmCtQDDSRBUjKaw9M1eAv5UeF0= +golang.org/x/sys v0.35.0 h1:vz1N37gP5bs89s7He8XuIYXpyY0+QlsKmzipCbUtyxI= +golang.org/x/sys v0.35.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= +golang.org/x/term v0.34.0 h1:O/2T7POpk0ZZ7MAzMeWFSg6S5IpWd/RXDlM9hgM3DR4= +golang.org/x/term v0.34.0/go.mod h1:5jC53AEywhIVebHgPVeg0mj8OD3VO9OzclacVrqpaAw= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/http/parse.go b/http/parse.go index 5af80072..b19c3a51 100644 --- a/http/parse.go +++ b/http/parse.go @@ -114,7 +114,8 @@ func parseRequest(r *http.Request, root *cmds.Command) (*cmds.Request, error) { // skip optional argument definitions if there aren't sufficient remaining values if valCount-valIndex <= numRequired && !argDef.Required { continue - } else if argDef.Required { + } + if argDef.Required { numRequired-- } diff --git a/http/response.go b/http/response.go index 1964dfc4..e29287f3 100644 --- a/http/response.go +++ b/http/response.go @@ -127,16 +127,17 @@ func (r *responseReader) Read(b []byte) (int, error) { } n, err := r.resp.Body.Read(b) - - // reading on a closed response body is as good as an io.EOF here - if err != nil && strings.Contains(err.Error(), "read on closed response body") { - err = io.EOF - } - if err == io.EOF { - _ = r.resp.Body.Close() - trailerErr := r.checkError() - if trailerErr != nil { - return n, trailerErr + if err != nil { + // reading on a closed response body is as good as an io.EOF here + if strings.Contains(err.Error(), "read on closed response body") { + err = io.EOF + } + if err == io.EOF { + _ = r.resp.Body.Close() + trailerErr := r.checkError() + if trailerErr != nil { + return n, trailerErr + } } } return n, err diff --git a/writer.go b/writer.go index e214485e..23b24608 100644 --- a/writer.go +++ b/writer.go @@ -194,24 +194,20 @@ func (m *MaybeError) Get() (interface{}, error) { func (m *MaybeError) UnmarshalJSON(data []byte) error { var e Error err := json.Unmarshal(data, &e) - if err == nil { - m.isError = true - m.Error = &e - return nil - } - - if m.Value != nil { - // make sure we are working with a pointer here - v := reflect.ValueOf(m.Value) - if v.Kind() != reflect.Ptr { - m.Value = reflect.New(v.Type()).Interface() + if err != nil { + if m.Value != nil { + // make sure we are working with a pointer here + v := reflect.ValueOf(m.Value) + if v.Kind() != reflect.Ptr { + m.Value = reflect.New(v.Type()).Interface() + } + return json.Unmarshal(data, m.Value) } - - err = json.Unmarshal(data, m.Value) - } else { // let the json decoder decode into whatever it finds appropriate - err = json.Unmarshal(data, &m.Value) + return json.Unmarshal(data, &m.Value) } - return err + m.isError = true + m.Error = &e + return nil } From 9a146cc6b917c27a90e0c3599bffeda18de846b3 Mon Sep 17 00:00:00 2001 From: gammazero <11790789+gammazero@users.noreply.github.com> Date: Thu, 14 Aug 2025 17:51:38 -1000 Subject: [PATCH 2/2] update readme --- README.md | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/README.md b/README.md index cd462ef0..5217b384 100644 --- a/README.md +++ b/README.md @@ -4,15 +4,12 @@ [![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/) [![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs) [![standard-readme compliant](https://img.shields.io/badge/standard--readme-OK-green.svg?style=flat-square)](https://github.com/RichardLitt/standard-readme) +[![GoDoc](https://pkg.go.dev/badge/github.com/ipfs/go-ipfs-cmds)](https://pkg.go.dev/github.com/ipfs/go-ipfs-cmds) > ipfs commands library cmds offers tools for describing and calling commands both locally and remotely, as well as encoding, formatting and transferring the result. It is the successor of go-ipfs/commands and contains a legacy layer such that it can handle previously defined commands. -## Lead Maintainer - -[Steven Allen](https://github.com/Stebalien) - ## Documentation https://pkg.go.dev/github.com/ipfs/go-ipfs-cmds