pkgx
pkgx copied to clipboard
Unreachable Code Preventing Short Circuit
While helping Montek with an error:
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.
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.
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.
I'll intercept tea .
and error if no exe/md region is found.
See referenced commit
Possibly we should require tea . foo
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
we removed exe/md