AgentEnder / cli-forge

Powerful, Composable CLI Tools
http://craigory.dev/cli-forge/
ISC License
4 stars 0 forks source link

suggestion: make the `.demandCommand()` as default behavior and add error handling #3

Closed tsanyqudsi closed 2 months ago

tsanyqudsi commented 2 months ago

As for now when I run it without .demandCommand() it will treat as if the main command is valid and will throw an error if I give no actions there.

when I run the default example in the readme and run it without giving any parameter (node ./dist/cli.js instead node ./dist/cli.js hello --name "World"), it gave me this :

Error: my-cli is not implemented.
at InternalCLI.runCommand (**cli-forge/src/lib/cli-forge.ts:375:15)
    at InternalCLI.forge (**/cli-forge/src/lib/cli-forge.ts:414:16)
    at <anonymous> (**/src/main.ts:15:4)
    at Object.<anonymous> **/src/main.ts:15:10)
    at Module._compile (node:internal/modules/cjs/loader:1469:14)
    at Object.transformer (/**/.npm/_npx/fd45a72a545557e9/node_modules/tsx/dist/register-C1urN2EO.cjs:2:1122)
    at Module.load (node:internal/modules/cjs/loader:1288:32)
    at Module._load (node:internal/modules/cjs/loader:1104:12)
    at cjsLoader (node:internal/modules/esm/translators:346:17)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:286:7)

It's not pretty.

So I suggest that it should automatically think that it needs a command if there's no implementation for the cli.

As for the error handling Maybe I want to make it something like my-cli needs a freakin command, bro!! instead of writing the detail of the error. I propose to make .errorMessage((error) => string) to make it better. So I can give the user something like

.errorMessage((error:Error) => `my-cli needs a freakin command, bro!! This is your error ${error}`)

or instead of making .errorMessage() you can include it inCLICommandOptions type

AgentEnder commented 2 months ago

This was included in 170335113c1b8e43b6741f1c5d500f4fb976a3fa

AgentEnder commented 2 months ago

RE: Error handling, not that part - will keep it in mind. For now my guidance would be custom validators, but those will not work for the requires command portion.