Skip to content

Commit

Permalink
Merge pull request #1574 from rsteube/yarn-error-message
Browse files Browse the repository at this point in the history
yarn: fix error message
  • Loading branch information
rsteube authored Mar 19, 2023
2 parents f2a8b0f + b62fc67 commit d539fd1
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 14 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.19
require (
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510
github.com/pelletier/go-toml v1.9.5
github.com/rsteube/carapace v0.33.6
github.com/rsteube/carapace v0.33.7
github.com/rsteube/carapace-spec v0.6.5
github.com/spf13/cobra v1.6.1
github.com/spf13/pflag v1.0.5
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ github.com/pelletier/go-toml v1.9.5 h1:4yBQzkHv+7BHq2PQUZF3Mx0IYxG7LsP222s7Agd3v
github.com/pelletier/go-toml v1.9.5/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rsteube/carapace v0.33.6 h1:sym/g01y3nAgInNN0pO4o6GLcpOGdG/vJ3eCubMdN5Y=
github.com/rsteube/carapace v0.33.6/go.mod h1:/ALYHicIpak6TjQnKl7HupclqJydy2LQb6CkawYBxDo=
github.com/rsteube/carapace v0.33.7 h1:QRXlIL8vhaoVv0ZA6peIergk0EXD7Lv8QZEL2UFE+g8=
github.com/rsteube/carapace v0.33.7/go.mod h1:/ALYHicIpak6TjQnKl7HupclqJydy2LQb6CkawYBxDo=
github.com/rsteube/carapace-pflag v0.1.0 h1:CPJRlj3jbyOnxuMf5pdrM76hEwdQ0STDDmkAHQcGbhg=
github.com/rsteube/carapace-pflag v0.1.0/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/rsteube/carapace-spec v0.6.5 h1:9u7ZExxPDU7MGTYHncN5ugJWOlVTUmaf4uIjrdGmjwU=
Expand Down
10 changes: 1 addition & 9 deletions pkg/actions/tools/yarn/bin.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package yarn

import (
"encoding/json"
"os/exec"
"strings"

"github.com/rsteube/carapace"
Expand All @@ -13,17 +12,10 @@ import (
// example (/tmp/yarn/example.js)
// another (/tmp/yarn/another.js)
func ActionBins() carapace.Action {
return carapace.ActionExecCommandE("yarn", "bin", "--json")(func(output []byte, err error) carapace.Action {
return actionYarn("bin", "--json")(func(output []byte) carapace.Action {
lines := strings.Split(string(output), "\n")
vals := make([]string, 0)

if err != nil {
if _, ok := err.(*exec.ExitError); ok {
return carapace.ActionMessage(lines[0]) // error is printed to stdout
}
return carapace.ActionMessage(err.Error())
}

for _, line := range lines[:len(lines)-1] {
var bin struct {
Name string
Expand Down
2 changes: 1 addition & 1 deletion pkg/actions/tools/yarn/dependency.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
// project@workspace:.
// yaml@npm:2.2.1
func ActionDependencies() carapace.Action {
return carapace.ActionExecCommand("yarn", "info", "--json")(func(output []byte) carapace.Action {
return actionYarn("info", "--json")(func(output []byte) carapace.Action {
lines := strings.Split(string(output), "\n")
vals := make([]string, 0)

Expand Down
2 changes: 1 addition & 1 deletion pkg/actions/tools/yarn/workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
// example (.)
// another (/tmp)
func ActionWorkspaces() carapace.Action {
return carapace.ActionExecCommand("yarn", "workspaces", "list", "--json")(func(output []byte) carapace.Action {
return actionYarn("workspaces", "list", "--json")(func(output []byte) carapace.Action {
lines := strings.Split(string(output), "\n")
vals := make([]string, 0)

Expand Down
24 changes: 24 additions & 0 deletions pkg/actions/tools/yarn/yarn.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package yarn

import (
"os/exec"
"strings"

"github.com/rsteube/carapace"
)

func actionYarn(args ...string) func(f func(output []byte) carapace.Action) carapace.Action {
return func(f func(output []byte) carapace.Action) carapace.Action {
return carapace.ActionExecCommandE("yarn", args...)(func(output []byte, err error) carapace.Action {
lines := strings.Split(string(output), "\n")
if err != nil {
if _, ok := err.(*exec.ExitError); ok {
return carapace.ActionMessage(lines[0]) // error is printed to stdout
}
return carapace.ActionMessage(err.Error())
}
return f(output)
})
}

}

0 comments on commit d539fd1

Please sign in to comment.