Skip to content
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

support commands specified as exe/args #483

Merged
merged 2 commits into from
Nov 27, 2024
Merged

Conversation

anuraaga
Copy link
Contributor

closes #480

If an external command (shellcheck, pyflakes) is not found, try to parse it as a exe+args using go-shellwords, which can allow executing without having the binary installed i.e., go run github.com/wasilibs/go-shellcheck/cmd/[email protected], pipx run pyflakes.

@rhysd
Copy link
Owner

rhysd commented Nov 22, 2024

Thank you for the quick PR. I'll check this soon.

@rhysd rhysd self-requested a review November 22, 2024 11:17
process.go Outdated
if exeArgs, _ := shellwords.Parse(exe); len(exeArgs) > 0 {
// We want to return the original error if this command isn't found so
// do not overwrite it.
if p, err2 := execabs.LookPath(exeArgs[0]); err2 == nil {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if p, err2 := execabs.LookPath(exeArgs[0]); err2 == nil {
if p, err := execabs.LookPath(exeArgs[0]); err == nil {

Would you shadow the outer err variable? It is okay because this variable is very short-lived.

process_test.go Outdated
func TestProcessRunWithArgs(t *testing.T) {
var done atomic.Bool
p := newConcurrentProcess(1)
echo := testSkipIfNoCommand(t, p, "echo hello")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test doesn't fail when newCommandRunner fails because it calls t.Skip.

Instead, we need to check if echo exists separately.

if _, err := execabs.LookPath("echo"); err != nil {
    t.Skipf("echo command is necessary to run this test: %s", err)
}

c, err := p.newCommandRunner("echo hello", false)
if err != nil {
    t.Fatalf(`parsing "echo hello" failed: %v`, err)
}

@anuraaga
Copy link
Contributor Author

Thanks @rhysd applied the fixes

Copy link
Owner

@rhysd rhysd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Thank you for the updates.

@rhysd rhysd merged commit 9091329 into rhysd:main Nov 27, 2024
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support commands specified as space-separated exe/args
2 participants