pkgx icon indicating copy to clipboard operation
pkgx copied to clipboard

Unreachable Code Preventing Short Circuit

Open davidtai opened this issue 2 years ago • 6 comments

While helping Montek with an error:

image

I discovered that this error which should be triggering when there's no commands in the README.md is unreachable: https://github.com/davidtai/cli/blob/04a93c00750eb73bb35cd60a220ef42ffdcfe46a/src/app.exec.ts#L117

a check for } else if (args.length == 0) { is nested inside a check for if (env && args.length) { and therefore can never execute. Enabling this error makes Montek's scenario fail gracefully, however it breaks other common scenarios. More research is needed for a fix.

davidtai avatar Nov 06 '22 17:11 davidtai

Here's a somewhat concerning scenario

# Getting Started

# sh

## hello

If you type in tea . then tea tries to execute . because # Getting Started is empty and triggers a os 13 error. If you type in tea sh, it will execute sh as the # sh block has no command.

davidtai avatar Nov 07 '22 15:11 davidtai

yeah tea . is possibly not sensible.

Maybe we need a character to indicate “target” since we are being a little too magical here. In theory there's some badness that can happen because we pass things through to the underlying shell but also interpret commands differently if they happen to be in a README.

It's a shame that tea #foo cannot work.

mxcl avatar Nov 08 '22 12:11 mxcl

I'll intercept tea . and error if no exe/md region is found.

mxcl avatar Nov 08 '22 12:11 mxcl

See referenced commit

mxcl avatar Nov 08 '22 12:11 mxcl

Possibly we should require tea . foo

mxcl avatar Nov 08 '22 15:11 mxcl

That should address this.

On the extended conversation about how this feature should work. I'm not opposed to magic so I think the signature is fine. But I think it might be a good idea to add a simple preview prompt that displays what commands were found by tea and let the user pick what gets executed.

Not all getting starteds will be one liners. For example it is common for node projects to have both npm, npx, and yarn commands:

https://github.com/facebook/create-react-app

davidtai avatar Nov 08 '22 17:11 davidtai

we removed exe/md

mxcl avatar Jan 14 '23 17:01 mxcl