Skip to content

Commit e24117a

Browse files
authored
update dependencies (#296)
* update dependencies code style: remove else after return sort using slices.SortFunc * update readme
1 parent 9c5e138 commit e24117a

File tree

8 files changed

+48
-53
lines changed

8 files changed

+48
-53
lines changed

README.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,12 @@
44
[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)
55
[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)
66
[![standard-readme compliant](https://img.shields.io/badge/standard--readme-OK-green.svg?style=flat-square)](https://github.com/RichardLitt/standard-readme)
7+
[![GoDoc](https://pkg.go.dev/badge/github.com/ipfs/go-ipfs-cmds)](https://pkg.go.dev/github.com/ipfs/go-ipfs-cmds)
78

89
> ipfs commands library
910
1011
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.
1112

12-
## Lead Maintainer
13-
14-
[Steven Allen](https://github.com/Stebalien)
15-
1613
## Documentation
1714

1815
https://pkg.go.dev/github.com/ipfs/go-ipfs-cmds

cli/parse.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"path/filepath"
1111
"reflect"
1212
"runtime"
13-
"sort"
13+
"slices"
1414
"strings"
1515

1616
"github.com/ipfs/boxo/files"
@@ -382,8 +382,8 @@ func parseArgs(req *cmds.Request, root *cmds.Command, stdin *os.File) error {
382382
fileArgs = append(fileArgs, files.FileEntry(stdinName(req), fileStdin))
383383
}
384384
if len(fileArgs) > 0 {
385-
sort.Slice(fileArgs, func(i, j int) bool {
386-
return fileArgs[i].Name() < fileArgs[j].Name()
385+
slices.SortFunc(fileArgs, func(a, b files.DirEntry) int {
386+
return strings.Compare(a.Name(), b.Name())
387387
})
388388
req.Files = files.NewSliceDirectory(fileArgs)
389389
}
@@ -419,9 +419,8 @@ func splitkv(opt string) (k, v string, ok bool) {
419419
split := strings.SplitN(opt, "=", 2)
420420
if len(split) == 2 {
421421
return split[0], split[1], true
422-
} else {
423-
return opt, "", false
424422
}
423+
return opt, "", false
425424
}
426425

427426
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
454453
}
455454

456455
kvs = append(kvs, kv{Key: k, Value: v})
457-
458456
} else {
459457
LOOP:
460458
for j := 0; j < len(k); {
@@ -514,7 +512,8 @@ func (st *parseState) parseLongOpt(optDefs map[string]cmds.Option) (string, inte
514512
}
515513
if optDef.Type() == cmds.Bool {
516514
return k, true, nil
517-
} else if st.i < len(st.cmdline)-1 {
515+
}
516+
if st.i < len(st.cmdline)-1 {
518517
st.i++
519518
v = st.peek()
520519
} else {
@@ -530,8 +529,8 @@ func getArgDef(i int, argDefs []cmds.Argument) *cmds.Argument {
530529
if i < len(argDefs) {
531530
// get the argument definition (usually just argDefs[i])
532531
return &argDefs[i]
533-
534-
} else if len(argDefs) > 0 {
532+
}
533+
if len(argDefs) > 0 {
535534
// but if i > len(argDefs) we use the last argument definition)
536535
return &argDefs[len(argDefs)-1]
537536
}

cli/run.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ func Run(ctx context.Context, root *cmds.Command,
7575
err := HandleHelp(cmdline[0], req, stdout)
7676
if err == nil {
7777
return nil
78-
} else if err != ErrNoHelpRequested {
78+
}
79+
if err != ErrNoHelpRequested {
7980
return err
8081
}
8182
// no help requested, continue.

go.mod

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@ module github.com/ipfs/go-ipfs-cmds
33
go 1.23.10
44

55
require (
6-
github.com/ipfs/boxo v0.33.0
7-
github.com/ipfs/go-log/v2 v2.6.0
6+
github.com/ipfs/boxo v0.33.1
7+
github.com/ipfs/go-log/v2 v2.8.1
88
github.com/rs/cors v1.11.1
99
github.com/texttheater/golang-levenshtein v1.0.1
10-
golang.org/x/term v0.33.0
10+
golang.org/x/term v0.34.0
1111
)
1212

1313
require (
1414
github.com/crackcomm/go-gitignore v0.0.0-20241020182519-7843d2ba8fdf // indirect
1515
github.com/mattn/go-isatty v0.0.20 // indirect
1616
go.uber.org/multierr v1.11.0 // indirect
1717
go.uber.org/zap v1.27.0 // indirect
18-
golang.org/x/sys v0.34.0 // indirect
18+
golang.org/x/sys v0.35.0 // indirect
1919
)
2020

2121
retract v1.0.22 // old gx tag accidentally pushed as go tag

go.sum

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ github.com/crackcomm/go-gitignore v0.0.0-20241020182519-7843d2ba8fdf h1:dwGgBWn8
22
github.com/crackcomm/go-gitignore v0.0.0-20241020182519-7843d2ba8fdf/go.mod h1:p1d6YEZWvFzEh4KLyvBcVSnrfNDDvK2zfK/4x2v/4pE=
33
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
44
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
5-
github.com/ipfs/boxo v0.33.0 h1:9ow3chwkDzMj0Deq4AWRUEI7WnIIV7SZhPTzzG2mmfw=
6-
github.com/ipfs/boxo v0.33.0/go.mod h1:3IPh7YFcCIcKp6o02mCHovrPntoT5Pctj/7j4syh/RM=
7-
github.com/ipfs/go-log/v2 v2.6.0 h1:2Nu1KKQQ2ayonKp4MPo6pXCjqw1ULc9iohRqWV5EYqg=
8-
github.com/ipfs/go-log/v2 v2.6.0/go.mod h1:p+Efr3qaY5YXpx9TX7MoLCSEZX5boSWj9wh86P5HJa8=
5+
github.com/ipfs/boxo v0.33.1 h1:89m+ksw+cYi0ecTNTJ71IRS5ZrLiovmO6XWHIOGhAEg=
6+
github.com/ipfs/boxo v0.33.1/go.mod h1:KwlJTzv5fb1GLlA9KyMqHQmvP+4mrFuiE3PnjdrPJHs=
7+
github.com/ipfs/go-log/v2 v2.8.1 h1:Y/X36z7ASoLJaYIJAL4xITXgwf7RVeqb1+/25aq/Xk0=
8+
github.com/ipfs/go-log/v2 v2.8.1/go.mod h1:NyhTBcZmh2Y55eWVjOeKf8M7e4pnJYM3yDZNxQBWEEY=
99
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
1010
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
1111
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
2323
go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8=
2424
go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E=
2525
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
26-
golang.org/x/sys v0.34.0 h1:H5Y5sJ2L2JRdyv7ROF1he/lPdvFsd0mJHFw2ThKHxLA=
27-
golang.org/x/sys v0.34.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
28-
golang.org/x/term v0.33.0 h1:NuFncQrRcaRvVmgRkvM3j/F00gWIAlcmlB8ACEKmGIg=
29-
golang.org/x/term v0.33.0/go.mod h1:s18+ql9tYWp1IfpV9DmCtQDDSRBUjKaw9M1eAv5UeF0=
26+
golang.org/x/sys v0.35.0 h1:vz1N37gP5bs89s7He8XuIYXpyY0+QlsKmzipCbUtyxI=
27+
golang.org/x/sys v0.35.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
28+
golang.org/x/term v0.34.0 h1:O/2T7POpk0ZZ7MAzMeWFSg6S5IpWd/RXDlM9hgM3DR4=
29+
golang.org/x/term v0.34.0/go.mod h1:5jC53AEywhIVebHgPVeg0mj8OD3VO9OzclacVrqpaAw=
3030
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
3131
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

http/parse.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ func parseRequest(r *http.Request, root *cmds.Command) (*cmds.Request, error) {
114114
// skip optional argument definitions if there aren't sufficient remaining values
115115
if valCount-valIndex <= numRequired && !argDef.Required {
116116
continue
117-
} else if argDef.Required {
117+
}
118+
if argDef.Required {
118119
numRequired--
119120
}
120121

http/response.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -127,16 +127,17 @@ func (r *responseReader) Read(b []byte) (int, error) {
127127
}
128128

129129
n, err := r.resp.Body.Read(b)
130-
131-
// reading on a closed response body is as good as an io.EOF here
132-
if err != nil && strings.Contains(err.Error(), "read on closed response body") {
133-
err = io.EOF
134-
}
135-
if err == io.EOF {
136-
_ = r.resp.Body.Close()
137-
trailerErr := r.checkError()
138-
if trailerErr != nil {
139-
return n, trailerErr
130+
if err != nil {
131+
// reading on a closed response body is as good as an io.EOF here
132+
if strings.Contains(err.Error(), "read on closed response body") {
133+
err = io.EOF
134+
}
135+
if err == io.EOF {
136+
_ = r.resp.Body.Close()
137+
trailerErr := r.checkError()
138+
if trailerErr != nil {
139+
return n, trailerErr
140+
}
140141
}
141142
}
142143
return n, err

writer.go

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -194,24 +194,20 @@ func (m *MaybeError) Get() (interface{}, error) {
194194
func (m *MaybeError) UnmarshalJSON(data []byte) error {
195195
var e Error
196196
err := json.Unmarshal(data, &e)
197-
if err == nil {
198-
m.isError = true
199-
m.Error = &e
200-
return nil
201-
}
202-
203-
if m.Value != nil {
204-
// make sure we are working with a pointer here
205-
v := reflect.ValueOf(m.Value)
206-
if v.Kind() != reflect.Ptr {
207-
m.Value = reflect.New(v.Type()).Interface()
197+
if err != nil {
198+
if m.Value != nil {
199+
// make sure we are working with a pointer here
200+
v := reflect.ValueOf(m.Value)
201+
if v.Kind() != reflect.Ptr {
202+
m.Value = reflect.New(v.Type()).Interface()
203+
}
204+
return json.Unmarshal(data, m.Value)
208205
}
209-
210-
err = json.Unmarshal(data, m.Value)
211-
} else {
212206
// let the json decoder decode into whatever it finds appropriate
213-
err = json.Unmarshal(data, &m.Value)
207+
return json.Unmarshal(data, &m.Value)
214208
}
215209

216-
return err
210+
m.isError = true
211+
m.Error = &e
212+
return nil
217213
}

0 commit comments

Comments
 (0)