1.0.2 • Published 2 years ago
SimplifyPromptJS
Introduction
With this package, you will be able to create prompts to interact with the command line in a simple way.
You can customize your indicator with numerous options and create commands too easy.
new Prompt(PromptConstructorOptions)
With this class, you can create your own prompt.
Check the types part to see more information
<prompt>.addCommands(...commands):this
Add commands to the prompt.
Usage:
const prompt = new Prompt(/*Options*/);
prompt.addCommands(
{
name: 'install',
aliases: ['i'],
description: 'Install a package'
}
);
Reply to a prompt interation.
Param | Description | Default | Type |
---|
args | The args of the prompt | process.argv | string |
Usage:
const prompt = new Prompt(/*Options*/);
let interaction = prompt.reply();
Types
PromptConstructorOptions
CommandsOptions
Property | Description | Type | Default | Required |
---|
name | The name of the command | string | undefined | ✅ |
aliases | The aliases of this command | Array\ | [] | ❌ |
description | The description of this command | string | null | ❌ |
options | The options of this command | Array<CommandOptions> | [] | ❌ |
action | The action of this command. Launched when the command is invoked | CommandFunction() | () => {} | ❌ |
type | The type of the value | "string" | "boolean" | "number" | "any" | "any" | ❌ |
required | If the value of the command is required | boolean | false | ❌ |
CommandOptions
Property | Description | Type | Default | Required |
---|
name | The name of this option | string | undefined | ✅ |
aliases | The aliases of this option | Array\ | [] | ❌ |
description | The description of this option | string | null | ❌ |
type | The type of this option | "string" | "number" | "boolean" | "any" | "any" | ❌ |
action | The action of this option. Launched when the option is invoked | OptionFunction() | () => {} | ❌ |
CommandFunction
CommandFunctionProperties
Property | Description | Type | Default |
---|
args | The arguments of this interaction | Array\ | string, string | number | boolean | Array\<undefined> |
commandValue | The value of this interaction | string | number | boolean | undefined |
OptionFunction
OptionFunctionProperties
Property | Description | Type | Default |
---|
value | The value of this option | string | boolean | number | undefined |
commandValue | The value of the interaction | string | number | boolean | undefined |
PrefixOptions
Property | Description | Type | Default | Required |
---|
large | The large prefix for complete option name | string | -- | ❌ |
sort | The sort prefix for alias option | string | - | ❌ |
PromptOptions
Property | Description | Type | Default | Required |
---|
errorMessages | A object with all error messages | ErrorMessages | {} | ❌ |
ErrorMessages
Property | Description | Type | Default | Required |
---|
COMMAND_DOESNT_EXIST | Invoked when a command doesn't exist | string | "The command does not exist!" | ❌ |
MALFORMED_COMMAND | Invoked when a command have bad sintaxis | string | "The command sintaxis isn't correct!" | ❌ |
WRONG_DATA_TYPE | Invoked when you provide a incorrect data type in a command or option | string | "The option "{name}" wants this type: {type}" | ❌ |
REQUIRED_VALUE | Invoked when the value of the command or options is required and the value is undefined | string | "The command value is required!" | ❌ |
ReplyResponse
Property | Description | Type |
---|
commandName | The name of the launched command | string |
value | The value of the interaction | string | number | boolean |
arguments | The arguments of this interaction | Array\ | [string, string | number | boolean][] |