Application
The Application
class serves as the main entry point for the command-line application. It provides static methods and properties to create and manage commands, options, arguments, and help documentation.
Example
// Initialize the application
Application.init();
// Create a new command
const myCommand = Application.createCommand('myCommand');
myCommand.description('This is my custom command');
// Add an option to the command
const myOption = Application.createOption('-f, --flag', 'A custom flag');
myCommand.addOption(myOption);
// Add an argument to the command
const myArgument = Application.createArgument('<arg>', 'A custom argument');
myCommand.addArgument(myArgument);
// Add the command to the program
Application.program.addCommand(myCommand);
// Parse the command-line arguments
Application.program.parse(process.argv);
Constructors
new Application()
new Application(): Application
Returns
Properties
Property | Modifier | Type | Description |
---|---|---|---|
|
| Constructor for the | |
|
| Constructor for the | |
|
| ‐ | |
| ( | Creates a new | |
| ( | Creates a new | |
| () => | Creates a new | |
| ( | Creates a new | |
| ‐ | ||
|
| Constructor for the | |
|
| Input handler for the application. | |
|
| Indicates whether the application has been initialized. | |
|
| ‐ | |
|
| ‐ | |
|
| Constructor for the | |
|
| Output handler for the application. | |
| ‐ | ||
| The main command program. | ||
| ‐ |
Methods
error()
static error(error, exit?): typeof Application
Parameters
Parameter | Type |
---|---|
|
|
|
|
Returns
typeof Application
exit()
static exit(exitCode): never
Parameters
Parameter | Type | Default value |
---|---|---|
|
|
|
Returns
never
init()
static init(): typeof Application
Initializes the application. This method should be called before using any other methods.
Returns
typeof Application
The Application
class.
start()
static start<T>(args): Promise<T>
Type Parameters
Type Parameter |
---|
|
Parameters
Parameter | Type |
---|---|
|
|
Returns
Promise
<T
>
testRun()
static testRun(target, fn): boolean
Starts the application with the specified arguments. This method should be called after initializing the application. If an error occurs during execution, the error will be logged and the application will exit with an error code.
Parameters
Parameter | Type | Description |
---|---|---|
|
| The target path or object. |
| ( | The function to run. |
Returns
boolean
Example
// With string param
Application.testRun('data', (paths) => {
console.log(paths.data);
});
With object param
Application.testRun(Application.paths, (paths) => {
console.log(paths.data);
});