Constructor
# new CliWrapper(basePathopt, crawlLevelsopt)
This class provides a wrapper around Commander.js to handle CLI commands from different Decaf modules. It crawls the filesystem to find CLI modules, loads them, and registers their commands.
Utility class to handle CLI functionality from all Decaf modules
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
basePath |
string
|
<optional> |
The base path to look for modules in. Defaults to |
crawlLevels |
number
|
<optional> |
Number of folder levels to crawl to find modules from the basePath. Defaults to 4 |
Example
// Create a new CLI wrapper and run it with custom options
const cli = new CliWrapper('./src', 2);
cli.run(process.argv).then(() => {
console.log('CLI commands executed successfully');
});
Methods
# async run(argsopt) → {Promise.<void>}
Boots the CLI by loading all modules, then parses and executes the command specified in the arguments
Executes the CLI with the provided arguments
sequenceDiagram
participant Client
participant CliWrapper
participant Command
Client->>CliWrapper: run(args)
CliWrapper->>CliWrapper: boot()
Note over CliWrapper: Loads all modules
CliWrapper->>Command: parseAsync(args)
Command-->>CliWrapper: result
CliWrapper-->>Client: result
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
args |
Array.<string>
|
<optional> |
process.argv | Command line arguments to parse and execute |
A promise that resolves when the command execution is complete
Promise.<void>