antfu-collective / ni

💡 Use the right package manager
MIT License
6.42k stars 210 forks source link

feat: expose `getCliCommand` function #164

Closed ghengeveld closed 1 year ago

ghengeveld commented 1 year ago

Description

To enhance the use of ni as part of other CLI packages, this extracts part of the run function into a separate getCliCommand function and exports it. This enables CLI authors such as myself to get a full CLI command, including the agent, without necessarily having to invoke it with execaCommand (which run does`).

await getCliCommand(parseNi, [name]) // e.g. "pnpm add vite"

My use case is that I need to invoke execaCommand myself, because I need to provide it with custom stdio config. I would also be happy with a execaOptions config option to enable this use case, but I imagine extracting getCliCommand enables more use cases / provides more flexibility and is thus more useful. I happen to use execa too, but others might not.

Additional context

I have not added any tests since I don't see any for the other top-level functions. Please advise on how/where to add any, if necessary.