4. wrapCLI(fn, meta, aliases)
Wraps a JavaScript function fn as a CLI command.
1import { wrapCLI } from 'hbh-nodes';3function greet(name, options) {4 const prefix = options?.loud ? "HELLO" : "Hello";5 return `${prefix} ${name}!`;6}8const cli = wrapCLI(greet, {9 description: "Greet someone",10 args: [{ name: "name", type: "string", required: true }],11 named: [{ name: "loud", type: "boolean" }]12});14cli(); // Run from Node.js
Features:
- Checks for help flags (
--helpor-h) viaaliases. - Spreads positional arguments to the function.
- Optionally passes named arguments as the last object.
- Handles async functions automatically.
- Catches exceptions and logs errors.