Skip to content
Merged
Show file tree
Hide file tree
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
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 8 additions & 9 deletions cli/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"path/filepath"
"reflect"
"runtime"
"sort"
"slices"
"strings"

"github.com/ipfs/boxo/files"
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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); {
Expand Down Expand Up @@ -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 {
Expand All @@ -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]
}
Expand Down
3 changes: 2 additions & 1 deletion cli/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ 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 (
github.com/crackcomm/go-gitignore v0.0.0-20241020182519-7843d2ba8fdf // indirect
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
Expand Down
16 changes: 8 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand All @@ -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=
3 changes: 2 additions & 1 deletion http/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -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--
}

Expand Down
21 changes: 11 additions & 10 deletions http/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 12 additions & 16 deletions writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Loading