dsherret / dax

Cross-platform shell tools for Deno and Node.js inspired by zx.
MIT License
1.05k stars 35 forks source link

feat: support for custom commands #8

Closed pocketken closed 2 years ago

pocketken commented 2 years ago

As mentioned in #7, it'd be nice to extend the shell parser to be able to handle additional commands as though they were built-ins/in the system path. Here's a quick take at implementing support by means of extending the CommandBuilder with a handle() method for registering a custom command handler/callback. This should fit in nicely with the custom builder pattern outlined in the documentation.

PR is not so much WIP as at a point where I could use some feedback:

pocketken commented 2 years ago

@dsherret hmm; I am getting different behavior when I run this locally in Windows. Both the original and modified version pass here, which now that I think about it noThrow() would in fact, not throw...

I need another coffee.

dsherret commented 2 years ago

It's probably finding a cd command on mac (via resolveCommand)

pocketken commented 2 years ago

It's probably finding a cd command on mac (via resolveCommand)

Of course it is! ..fires up mac..

$ which cd
/usr/bin/cd
$ which echo
/bin/echo
$ which export
$

export wins! I'll update.

pocketken commented 2 years ago

👍 no problem, glad to contribute back where I can.

Thanks again for throwing this together!

dsherret commented 2 years ago

Thanks again for this and all your other PRs! I released version 0.8.0.