@nan0web/ui-cli 1.0.0 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -11
- package/package.json +17 -7
- package/src/CLI.js +141 -0
- package/src/Command.js +210 -0
- package/src/CommandError.js +35 -0
- package/src/CommandHelp.js +204 -0
- package/src/CommandMessage.js +181 -0
- package/src/CommandParser.js +217 -0
- package/src/InputAdapter.js +78 -149
- package/src/README.md.js +7 -6
- package/src/index.js +36 -14
- package/src/ui/index.js +3 -3
- package/src/ui/input.js +68 -11
- package/src/ui/next.js +30 -26
- package/src/ui/select.js +41 -31
- package/src/utils/parse.js +41 -0
- package/types/CLI.d.ts +44 -0
- package/types/Command.d.ts +72 -0
- package/types/CommandError.d.ts +19 -0
- package/types/CommandHelp.d.ts +85 -0
- package/types/CommandMessage.d.ts +65 -0
- package/types/CommandParser.d.ts +28 -0
- package/types/InputAdapter.d.ts +28 -85
- package/types/index.d.ts +12 -9
- package/types/ui/index.d.ts +2 -3
- package/types/ui/input.d.ts +50 -6
- package/types/ui/next.d.ts +11 -8
- package/types/ui/select.d.ts +50 -20
- package/types/utils/parse.d.ts +13 -0
- package/.editorconfig +0 -20
- package/CONTRIBUTING.md +0 -42
- package/docs/uk/README.md +0 -294
- package/playground/forms/addressForm.js +0 -37
- package/playground/forms/ageForm.js +0 -26
- package/playground/forms/profileForm.js +0 -33
- package/playground/forms/userForm.js +0 -36
- package/playground/main.js +0 -81
- package/playground/vocabs/en.js +0 -25
- package/playground/vocabs/index.js +0 -12
- package/playground/vocabs/uk.js +0 -25
- package/src/InputAdapter.test.js +0 -117
- package/src/ui/input.test.js +0 -27
- package/src/ui/select.test.js +0 -34
- package/system.md +0 -99
- package/tsconfig.json +0 -23
- package/types/test/ReadLine.d.ts +0 -1
- package/types/ui/errors.d.ts +0 -3
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {Object} CommandHelpField MessageBodySchema
|
|
3
|
+
* @property {string} [help] - Human readable description.
|
|
4
|
+
* @property {string} [placeholder] - Placeholder for usage (e.g. "<user>").
|
|
5
|
+
* @property {string} [alias] - Short alias (single‑letter).
|
|
6
|
+
* @property {any} [defaultValue] - Default value.
|
|
7
|
+
* @property {any} [type] - Data type.
|
|
8
|
+
* @property {boolean} [required] - Is field required or not.
|
|
9
|
+
* @property {RegExp} [pattern] - Regular expression pattern for validation.
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* CommandHelp – generates CLI help from a Message body schema.
|
|
13
|
+
* Supports nesting via static `Children`; message‑centric.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* const help = new CommandHelp(AuthMessage)
|
|
17
|
+
* console.log(help.generate()) // → formatted help string
|
|
18
|
+
* help.print() // → logs to console
|
|
19
|
+
*/
|
|
20
|
+
export default class CommandHelp {
|
|
21
|
+
/**
|
|
22
|
+
* @param {typeof Message} MessageClass - Message class with a schema.
|
|
23
|
+
* @param {Logger} [logger=new Logger()] - Optional logger.
|
|
24
|
+
*/
|
|
25
|
+
constructor(MessageClass: typeof Message, logger?: Logger | undefined);
|
|
26
|
+
/** @type {typeof Message} Message class the help is built for */
|
|
27
|
+
MessageClass: typeof Message;
|
|
28
|
+
/** @type {Logger} Logger used for printing */
|
|
29
|
+
logger: Logger;
|
|
30
|
+
/** @type {typeof Message.Body} Body class reference */
|
|
31
|
+
BodyClass: typeof Message.Body;
|
|
32
|
+
/** @returns {typeof Logger} */
|
|
33
|
+
get Logger(): typeof Logger;
|
|
34
|
+
/**
|
|
35
|
+
* Generates the full help text.
|
|
36
|
+
*
|
|
37
|
+
* @returns {string} Formatted help text.
|
|
38
|
+
*/
|
|
39
|
+
generate(): string;
|
|
40
|
+
/**
|
|
41
|
+
* Prints the generated help to the logger.
|
|
42
|
+
*/
|
|
43
|
+
print(): void;
|
|
44
|
+
/**
|
|
45
|
+
* @param {object} body
|
|
46
|
+
* @returns {Map<string, any>} A map of errors, empty map if no errors.
|
|
47
|
+
*/
|
|
48
|
+
validate(body: object): Map<string, any>;
|
|
49
|
+
#private;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* MessageBodySchema
|
|
53
|
+
*/
|
|
54
|
+
export type CommandHelpField = {
|
|
55
|
+
/**
|
|
56
|
+
* - Human readable description.
|
|
57
|
+
*/
|
|
58
|
+
help?: string | undefined;
|
|
59
|
+
/**
|
|
60
|
+
* - Placeholder for usage (e.g. "<user>").
|
|
61
|
+
*/
|
|
62
|
+
placeholder?: string | undefined;
|
|
63
|
+
/**
|
|
64
|
+
* - Short alias (single‑letter).
|
|
65
|
+
*/
|
|
66
|
+
alias?: string | undefined;
|
|
67
|
+
/**
|
|
68
|
+
* - Default value.
|
|
69
|
+
*/
|
|
70
|
+
defaultValue?: any;
|
|
71
|
+
/**
|
|
72
|
+
* - Data type.
|
|
73
|
+
*/
|
|
74
|
+
type?: any;
|
|
75
|
+
/**
|
|
76
|
+
* - Is field required or not.
|
|
77
|
+
*/
|
|
78
|
+
required?: boolean | undefined;
|
|
79
|
+
/**
|
|
80
|
+
* - Regular expression pattern for validation.
|
|
81
|
+
*/
|
|
82
|
+
pattern?: RegExp | undefined;
|
|
83
|
+
};
|
|
84
|
+
import { Message } from "@nan0web/co";
|
|
85
|
+
import Logger from "@nan0web/log";
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @class
|
|
3
|
+
* @extends Message
|
|
4
|
+
*/
|
|
5
|
+
export default class CommandMessage extends Message {
|
|
6
|
+
/**
|
|
7
|
+
* Parse raw CLI input into a {@link CommandMessage}.
|
|
8
|
+
*
|
|
9
|
+
* @param {string|string[]} argv - Input string or token array.
|
|
10
|
+
* @param {typeof Object} [BodyClass] - Optional class to instantiate the body.
|
|
11
|
+
* @returns {CommandMessage}
|
|
12
|
+
* @throws {CommandError} If no input is supplied.
|
|
13
|
+
*/
|
|
14
|
+
static parse(argv: string | string[], BodyClass?: ObjectConstructor | undefined): CommandMessage;
|
|
15
|
+
/**
|
|
16
|
+
* Convert a raw input into a {@link CommandMessage} instance.
|
|
17
|
+
*
|
|
18
|
+
* @param {CommandMessage|Message|Object|string|Array<string>} input
|
|
19
|
+
* @returns {CommandMessage}
|
|
20
|
+
*/
|
|
21
|
+
static from(input: CommandMessage | Message | any | string | Array<string>): CommandMessage;
|
|
22
|
+
/**
|
|
23
|
+
* @param {Object} [input={}]
|
|
24
|
+
* @param {string} [input.name] - Command name.
|
|
25
|
+
* @param {string[]} [input.argv] - Positional arguments.
|
|
26
|
+
* @param {Object} [input.opts] - Options map.
|
|
27
|
+
* @param {Array<CommandMessage>} [input.children] - Nested messages.
|
|
28
|
+
* @param {Object} [input.body] - Message body payload.
|
|
29
|
+
*/
|
|
30
|
+
constructor(input?: {
|
|
31
|
+
name?: string | undefined;
|
|
32
|
+
argv?: string[] | undefined;
|
|
33
|
+
opts?: any;
|
|
34
|
+
children?: CommandMessage[] | undefined;
|
|
35
|
+
body?: any;
|
|
36
|
+
} | undefined);
|
|
37
|
+
/** @param {string} v */
|
|
38
|
+
set name(arg: string);
|
|
39
|
+
/** @returns {string} */
|
|
40
|
+
get name(): string;
|
|
41
|
+
/** @param {string[]} v */
|
|
42
|
+
set argv(arg: string[]);
|
|
43
|
+
/** @returns {string[]} */
|
|
44
|
+
get argv(): string[];
|
|
45
|
+
/** @param {Object} v */
|
|
46
|
+
set opts(arg: any);
|
|
47
|
+
/** @returns {Object} */
|
|
48
|
+
get opts(): any;
|
|
49
|
+
/** @returns {Array<CommandMessage>} */
|
|
50
|
+
get children(): CommandMessage[];
|
|
51
|
+
/** @returns {Array<string>} Full command line (name + args). */
|
|
52
|
+
get args(): string[];
|
|
53
|
+
/** @returns {string} Sub‑command name of the first child, or empty string. */
|
|
54
|
+
get subCommand(): string;
|
|
55
|
+
/** @returns {CommandMessage|null} First child message, or null. */
|
|
56
|
+
get subCommandMessage(): CommandMessage | null;
|
|
57
|
+
/**
|
|
58
|
+
* Append a child {@link CommandMessage}.
|
|
59
|
+
*
|
|
60
|
+
* @param {CommandMessage|Object} msg
|
|
61
|
+
*/
|
|
62
|
+
add(msg: CommandMessage | any): void;
|
|
63
|
+
#private;
|
|
64
|
+
}
|
|
65
|
+
import { Message } from "@nan0web/co";
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @class
|
|
3
|
+
*/
|
|
4
|
+
export default class CommandParser {
|
|
5
|
+
/**
|
|
6
|
+
* @param {Array<Function>} [Messages=[]] - Root message classes.
|
|
7
|
+
*/
|
|
8
|
+
constructor(Messages?: Function[] | undefined);
|
|
9
|
+
/** @type {Array<Function>} */
|
|
10
|
+
Messages: Array<Function>;
|
|
11
|
+
/**
|
|
12
|
+
* Parse the provided input into a message hierarchy.
|
|
13
|
+
*
|
|
14
|
+
* @param {string|string[]} [input=process.argv.slice(2)] - CLI arguments.
|
|
15
|
+
* @returns {Message}
|
|
16
|
+
* @throws {Error} If no command is supplied or unknown root command.
|
|
17
|
+
*/
|
|
18
|
+
parse(input?: string | string[] | undefined): Message;
|
|
19
|
+
/**
|
|
20
|
+
* Generate help text for a given message class.
|
|
21
|
+
*
|
|
22
|
+
* @param {typeof Message} MessageClass
|
|
23
|
+
* @returns {string}
|
|
24
|
+
*/
|
|
25
|
+
generateHelp(MessageClass: typeof Message): string;
|
|
26
|
+
#private;
|
|
27
|
+
}
|
|
28
|
+
import { Message } from "@nan0web/co";
|
package/types/InputAdapter.d.ts
CHANGED
|
@@ -1,106 +1,49 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
2
|
+
* Extends the generic {@link BaseInputAdapter} with CLI‑specific behaviour.
|
|
3
|
+
*
|
|
4
|
+
* @class
|
|
5
|
+
* @extends BaseInputAdapter
|
|
4
6
|
*/
|
|
5
7
|
export default class CLIInputAdapter extends BaseInputAdapter {
|
|
6
8
|
/**
|
|
7
|
-
*
|
|
9
|
+
* Prompt the user for a full form, handling navigation and validation.
|
|
8
10
|
*
|
|
9
|
-
* @param {UIForm} form
|
|
10
|
-
* @param {Object} options
|
|
11
|
-
* @param {boolean} [options.silent=true] Suppress
|
|
12
|
-
* @returns {Promise<
|
|
13
|
-
* otherwise `escaped` = false and the completed form attached as `form`.
|
|
11
|
+
* @param {UIForm} form - Form definition to present.
|
|
12
|
+
* @param {Object} [options={}]
|
|
13
|
+
* @param {boolean} [options.silent=true] - Suppress console output if `true`.
|
|
14
|
+
* @returns {Promise<Object>} Result object containing form data and meta‑information.
|
|
14
15
|
*/
|
|
15
16
|
requestForm(form: UIForm, options?: {
|
|
16
17
|
silent?: boolean | undefined;
|
|
17
|
-
}): Promise<
|
|
18
|
+
} | undefined): Promise<any>;
|
|
18
19
|
/**
|
|
19
|
-
*
|
|
20
|
+
* Prompt the user to select an option from a list.
|
|
20
21
|
*
|
|
21
|
-
* @param {Object} config
|
|
22
|
-
* @
|
|
23
|
-
* @param {string} config.prompt – Prompt text.
|
|
24
|
-
* @param {Array<string>|Map<string,string>|Array<{label:string,value:string}>} config.options – Options to choose from.
|
|
25
|
-
* @param {string} config.id – Identifier for the resulting message.
|
|
26
|
-
* @returns {Promise<BaseInputMessage>} Message containing chosen value and metadata.
|
|
22
|
+
* @param {Object} config - Configuration passed to {@link select}.
|
|
23
|
+
* @returns {Promise<any>} Selected value, or empty string on cancellation.
|
|
27
24
|
*/
|
|
28
|
-
requestSelect(config:
|
|
29
|
-
title: string;
|
|
30
|
-
prompt: string;
|
|
31
|
-
options: Array<string> | Map<string, string> | Array<{
|
|
32
|
-
label: string;
|
|
33
|
-
value: string;
|
|
34
|
-
}>;
|
|
35
|
-
id: string;
|
|
36
|
-
}): Promise<BaseInputMessage>;
|
|
25
|
+
requestSelect(config: any): Promise<any>;
|
|
37
26
|
/**
|
|
38
|
-
*
|
|
27
|
+
* Prompt for a single string input.
|
|
39
28
|
*
|
|
40
|
-
* @param {Object} config
|
|
41
|
-
* @param {string} config.prompt Prompt text.
|
|
42
|
-
* @param {string} config.
|
|
43
|
-
* @param {string} [config.
|
|
44
|
-
* @
|
|
45
|
-
* @returns {Promise<BaseInputMessage>} Message containing the entered text.
|
|
29
|
+
* @param {Object} config - Prompt configuration.
|
|
30
|
+
* @param {string} [config.prompt] - Prompt text.
|
|
31
|
+
* @param {string} [config.label] - Optional label.
|
|
32
|
+
* @param {string} [config.name] - Optional identifier.
|
|
33
|
+
* @returns {Promise<string>} User response string.
|
|
46
34
|
*/
|
|
47
35
|
requestInput(config: {
|
|
48
|
-
prompt
|
|
49
|
-
id: string;
|
|
36
|
+
prompt?: string | undefined;
|
|
50
37
|
label?: string | undefined;
|
|
51
38
|
name?: string | undefined;
|
|
52
|
-
}): Promise<
|
|
39
|
+
}): Promise<string>;
|
|
53
40
|
/** @inheritDoc */
|
|
54
|
-
ask(question: any): Promise<
|
|
41
|
+
ask(question: any): Promise<string>;
|
|
55
42
|
/** @inheritDoc */
|
|
56
|
-
select(
|
|
57
|
-
index: number;
|
|
58
|
-
value:
|
|
43
|
+
select(cfg: any): Promise<{
|
|
44
|
+
index: number;
|
|
45
|
+
value: any;
|
|
59
46
|
}>;
|
|
60
47
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
import { InputAdapter as BaseInputAdapter } from '@nan0web/ui';
|
|
64
|
-
import { UIForm } from '@nan0web/ui';
|
|
65
|
-
/** @typedef {Partial<UIForm>} FormMessageValue */
|
|
66
|
-
/** @typedef {Partial<Message> | null} InputMessageValue */
|
|
67
|
-
/**
|
|
68
|
-
* Extends the generic {@link BaseInputMessage} to carry a {@link UIForm}
|
|
69
|
-
* instance alongside the usual input message payload.
|
|
70
|
-
*
|
|
71
|
-
* The original {@link BaseInputMessage} expects a `value` of type
|
|
72
|
-
* {@link InputMessageValue} (a {@link Message} payload). To remain
|
|
73
|
-
* compatible we keep `value` unchanged and store the form data in a
|
|
74
|
-
* separate `form` property.
|
|
75
|
-
*/
|
|
76
|
-
declare class FormMessage extends BaseInputMessage {
|
|
77
|
-
/**
|
|
78
|
-
* Creates a {@link FormMessage} from an existing instance or plain data.
|
|
79
|
-
*
|
|
80
|
-
* @param {FormMessage|object} input – Existing message or raw data.
|
|
81
|
-
* @returns {FormMessage}
|
|
82
|
-
*/
|
|
83
|
-
static from(input: FormMessage | object): FormMessage;
|
|
84
|
-
/**
|
|
85
|
-
* Creates a new {@link FormMessage}.
|
|
86
|
-
*
|
|
87
|
-
* @param {object} props - Message properties.
|
|
88
|
-
* @param {FormMessageValue} [props.form={}] UIForm instance or data.
|
|
89
|
-
* @param {InputMessageValue} [props.value=null] Retained for compatibility.
|
|
90
|
-
* @param {string[]|string} [props.options=[]] Available options.
|
|
91
|
-
* @param {boolean} [props.waiting=false] Waiting flag.
|
|
92
|
-
* @param {boolean} [props.escaped=false] Escape flag.
|
|
93
|
-
*/
|
|
94
|
-
constructor(props?: {
|
|
95
|
-
form?: Partial<UIForm> | undefined;
|
|
96
|
-
value?: InputMessageValue | undefined;
|
|
97
|
-
options?: string | string[] | undefined;
|
|
98
|
-
waiting?: boolean | undefined;
|
|
99
|
-
escaped?: boolean | undefined;
|
|
100
|
-
});
|
|
101
|
-
/** @type {UIForm} Form data associated with the message */
|
|
102
|
-
form: UIForm;
|
|
103
|
-
}
|
|
104
|
-
import { InputMessage as BaseInputMessage } from '@nan0web/ui';
|
|
105
|
-
import { Message } from '@nan0web/co';
|
|
106
|
-
export {};
|
|
48
|
+
import { InputAdapter as BaseInputAdapter } from "@nan0web/ui";
|
|
49
|
+
import { UIForm } from "@nan0web/ui";
|
package/types/index.d.ts
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
|
+
export { str2argv } from "./utils/parse.js";
|
|
1
2
|
export const renderers: Map<string, (data: any) => string>;
|
|
2
3
|
export default CLIInputAdapter;
|
|
3
|
-
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import {
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
|
|
4
|
+
export type CommandHelpField = import("./CommandHelp.js").CommandHelpField;
|
|
5
|
+
import CLI from "./CLI.js";
|
|
6
|
+
import CLIInputAdapter from "./InputAdapter.js";
|
|
7
|
+
import { CancelError } from "@nan0web/ui/core";
|
|
8
|
+
import Command from "./Command.js";
|
|
9
|
+
import CommandError from "./CommandError.js";
|
|
10
|
+
import CommandMessage from "./CommandMessage.js";
|
|
11
|
+
import CommandParser from "./CommandParser.js";
|
|
12
|
+
import CommandHelp from "./CommandHelp.js";
|
|
13
|
+
export { CLI, CLIInputAdapter, CancelError, Command, CommandError, CommandMessage, CommandParser, CommandHelp };
|
|
14
|
+
export { select, next, pause, createInput, ask, Input } from "./ui/index.js";
|
package/types/ui/index.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export { select } from "./select.js";
|
|
3
|
-
export { Input, ask, createInput } from "./input.js";
|
|
1
|
+
export { Input, createInput, ask } from "./input.js";
|
|
2
|
+
export { select, default as baseSelect } from "./select.js";
|
|
4
3
|
export { next, pause } from "./next.js";
|
package/types/ui/input.d.ts
CHANGED
|
@@ -1,15 +1,59 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
2
|
+
* Prompt a question and return the trimmed answer.
|
|
3
|
+
*
|
|
4
|
+
* @param {string} question - Text displayed as a prompt.
|
|
5
|
+
* @returns {Promise<string>} User answer without surrounding whitespace.
|
|
6
|
+
*/
|
|
7
|
+
export function ask(question: string): Promise<string>;
|
|
8
|
+
/**
|
|
9
|
+
* Factory that creates a reusable async input handler.
|
|
10
|
+
*
|
|
11
|
+
* @param {string[]} [stops=[]] Words that trigger cancellation.
|
|
12
|
+
* @returns {InputFn} Async function that resolves to an {@link Input}.
|
|
13
|
+
*/
|
|
14
|
+
export function createInput(stops?: string[] | undefined): InputFn;
|
|
15
|
+
/**
|
|
16
|
+
* @typedef {Function} InputFn
|
|
17
|
+
* @param {string} question - Prompt displayed to the user.
|
|
18
|
+
* @param {Function|boolean} [loop=false] - Loop control or validator.
|
|
19
|
+
* @param {Function|false} [nextQuestion=false] - Function to compute the next prompt.
|
|
20
|
+
* @returns {Promise<Input>} Resolves with an {@link Input} instance containing the answer.
|
|
21
|
+
*/
|
|
22
|
+
/**
|
|
23
|
+
* Represents a line of user input.
|
|
24
|
+
*
|
|
25
|
+
* @class
|
|
26
|
+
* @property {string} value – The raw answer string.
|
|
27
|
+
* @property {string[]} stops – Words that trigger cancellation.
|
|
28
|
+
* @property {boolean} cancelled – True when the answer matches a stop word.
|
|
4
29
|
*/
|
|
5
|
-
export function ask(question: string): Promise<any>;
|
|
6
|
-
export function createInput(stops?: any[]): (question: string, loop?: boolean | Function | undefined, nextQuestion?: false | Function | undefined) => Promise<Input>;
|
|
7
30
|
export class Input {
|
|
8
|
-
|
|
31
|
+
/**
|
|
32
|
+
* Create a new {@link Input} instance.
|
|
33
|
+
*
|
|
34
|
+
* @param {Object} [input={}] - Optional initial values.
|
|
35
|
+
* @param {string} [input.value] - Initial answer string.
|
|
36
|
+
* @param {boolean} [input.cancelled] - Initial cancel flag.
|
|
37
|
+
* @param {string|string[]} [input.stops] - Words that trigger cancellation.
|
|
38
|
+
*/
|
|
39
|
+
constructor(input?: {
|
|
40
|
+
value?: string | undefined;
|
|
41
|
+
cancelled?: boolean | undefined;
|
|
42
|
+
stops?: string | string[] | undefined;
|
|
43
|
+
} | undefined);
|
|
44
|
+
/** @type {string} */
|
|
9
45
|
value: string;
|
|
10
|
-
|
|
46
|
+
/** @type {string[]} */
|
|
47
|
+
stops: string[];
|
|
48
|
+
/**
|
|
49
|
+
* Returns whether the input has been cancelled either explicitly or via a stop word.
|
|
50
|
+
*
|
|
51
|
+
* @returns {boolean}
|
|
52
|
+
*/
|
|
11
53
|
get cancelled(): boolean;
|
|
54
|
+
/** @returns {string} The raw answer value. */
|
|
12
55
|
toString(): string;
|
|
13
56
|
#private;
|
|
14
57
|
}
|
|
15
58
|
export default createInput;
|
|
59
|
+
export type InputFn = Function;
|
package/types/ui/next.d.ts
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
* @
|
|
2
|
+
* Pause execution for a given amount of milliseconds.
|
|
3
|
+
*
|
|
4
|
+
* @param {number} ms - Delay in milliseconds.
|
|
5
|
+
* @returns {Promise<true>} Resolves with `true` after the timeout.
|
|
5
6
|
*/
|
|
6
|
-
export function
|
|
7
|
+
export function pause(ms: number): Promise<true>;
|
|
7
8
|
/**
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* @
|
|
9
|
+
* Wait for any key press (or a specific sequence).
|
|
10
|
+
*
|
|
11
|
+
* @param {string|string[]|undefined} [conf] - Expected key or sequence.
|
|
12
|
+
* @returns {Promise<string>} The captured key/sequence.
|
|
13
|
+
* @throws {Error} If stdin is already in raw mode.
|
|
11
14
|
*/
|
|
12
|
-
export function
|
|
15
|
+
export function next(conf?: string | string[] | undefined): Promise<string>;
|
package/types/ui/select.d.ts
CHANGED
|
@@ -1,30 +1,60 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* Automatically creates its own input handler.
|
|
2
|
+
* Configuration object for {@link select}.
|
|
4
3
|
*
|
|
5
|
-
* @
|
|
6
|
-
* @
|
|
7
|
-
* @
|
|
8
|
-
* @
|
|
9
|
-
* @
|
|
10
|
-
* @
|
|
11
|
-
* @
|
|
4
|
+
* @typedef {Object} SelectConfig
|
|
5
|
+
* @property {string} title – Title displayed above the options list.
|
|
6
|
+
* @property {string} prompt – Prompt displayed for the answer.
|
|
7
|
+
* @property {Array|Map} options – Collection of selectable items.
|
|
8
|
+
* @property {Object} console – Console‑like object with an `info` method.
|
|
9
|
+
* @property {string[]} [stops=[]] Words that trigger cancellation.
|
|
10
|
+
* @property {import("./input.js").InputFn} [ask] Custom ask function (defaults to {@link createInput}).
|
|
11
|
+
* @property {string} [invalidPrompt="Invalid choice, try again: "] Message shown on invalid input.
|
|
12
12
|
*
|
|
13
|
-
* @returns {Promise<{
|
|
14
|
-
* @throws {CancelError} if the user cancels
|
|
13
|
+
* @returns {Promise<{index:number,value:any}>} Resolves with the selected index and its value.
|
|
15
14
|
*/
|
|
16
|
-
export function select({ title, prompt, invalidPrompt, options, console, ask, }: {
|
|
17
|
-
title:
|
|
18
|
-
prompt:
|
|
15
|
+
export function select({ title, prompt, invalidPrompt, options, console, stops, ask: initAsk, }: {
|
|
16
|
+
title: any;
|
|
17
|
+
prompt: any;
|
|
19
18
|
invalidPrompt?: string | undefined;
|
|
20
|
-
options:
|
|
21
|
-
label: string;
|
|
22
|
-
value: string;
|
|
23
|
-
}>;
|
|
19
|
+
options: any;
|
|
24
20
|
console: any;
|
|
25
|
-
|
|
21
|
+
stops?: any[] | undefined;
|
|
22
|
+
ask: any;
|
|
26
23
|
}): Promise<{
|
|
27
24
|
index: number;
|
|
28
|
-
value:
|
|
25
|
+
value: any;
|
|
29
26
|
}>;
|
|
30
27
|
export default select;
|
|
28
|
+
/**
|
|
29
|
+
* Configuration object for {@link select }.
|
|
30
|
+
*/
|
|
31
|
+
export type SelectConfig = {
|
|
32
|
+
/**
|
|
33
|
+
* – Title displayed above the options list.
|
|
34
|
+
*/
|
|
35
|
+
title: string;
|
|
36
|
+
/**
|
|
37
|
+
* – Prompt displayed for the answer.
|
|
38
|
+
*/
|
|
39
|
+
prompt: string;
|
|
40
|
+
/**
|
|
41
|
+
* – Collection of selectable items.
|
|
42
|
+
*/
|
|
43
|
+
options: any[] | Map<any, any>;
|
|
44
|
+
/**
|
|
45
|
+
* – Console‑like object with an `info` method.
|
|
46
|
+
*/
|
|
47
|
+
console: any;
|
|
48
|
+
/**
|
|
49
|
+
* Words that trigger cancellation.
|
|
50
|
+
*/
|
|
51
|
+
stops?: string[] | undefined;
|
|
52
|
+
/**
|
|
53
|
+
* Custom ask function (defaults to {@link createInput }).
|
|
54
|
+
*/
|
|
55
|
+
ask?: Function | undefined;
|
|
56
|
+
/**
|
|
57
|
+
* Message shown on invalid input.
|
|
58
|
+
*/
|
|
59
|
+
invalidPrompt?: string | undefined;
|
|
60
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility functions for parsing command‑line strings.
|
|
3
|
+
*
|
|
4
|
+
* @module utils/parse
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Parses a string into an argv array (handles quotes).
|
|
8
|
+
*
|
|
9
|
+
* @param {string} str - Raw command line.
|
|
10
|
+
* @returns {string[]} Tokenized arguments.
|
|
11
|
+
* @throws {Error} If a quote is left unmatched.
|
|
12
|
+
*/
|
|
13
|
+
export function str2argv(str: string): string[];
|
package/.editorconfig
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
root = true
|
|
2
|
-
|
|
3
|
-
[*]
|
|
4
|
-
indent_style = tab
|
|
5
|
-
indent_size = 2
|
|
6
|
-
charset = utf-8
|
|
7
|
-
end_of_line = lf
|
|
8
|
-
trim_trailing_whitespace = true
|
|
9
|
-
insert_final_newline = true
|
|
10
|
-
|
|
11
|
-
[*.md]
|
|
12
|
-
trim_trailing_whitespace = false
|
|
13
|
-
|
|
14
|
-
[*.jsx]
|
|
15
|
-
indent_style = tab
|
|
16
|
-
indent_size = 2
|
|
17
|
-
|
|
18
|
-
[*.{md,nano,yaml}]
|
|
19
|
-
indent_style = space
|
|
20
|
-
indent_size = 2
|
package/CONTRIBUTING.md
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
# Contributing
|
|
2
|
-
|
|
3
|
-
## Developer Certificate of Origin and License
|
|
4
|
-
By contributing, You accept and agree to the following terms and conditions for your present and future contributions submitted.
|
|
5
|
-
Except for the license granted herein, You reserve all right, title, and interest in and to your Contributions.
|
|
6
|
-
All contributions are subject to the Developer Certificate of Origin and license as set out in the LICENSE file.
|
|
7
|
-
|
|
8
|
-
## Code of Conduct
|
|
9
|
-
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
|
10
|
-
|
|
11
|
-
We are committed to making participation in this project a harassment-free experience for everyone, regardless of:
|
|
12
|
-
- Level of experience,
|
|
13
|
-
- Gender,
|
|
14
|
-
- Gender identity and expression,
|
|
15
|
-
- Sexual orientation,
|
|
16
|
-
- Disability,
|
|
17
|
-
- Personal appearance,
|
|
18
|
-
- Body size,
|
|
19
|
-
- Race,
|
|
20
|
-
- Ethnicity,
|
|
21
|
-
- Age,
|
|
22
|
-
- Religion.
|
|
23
|
-
|
|
24
|
-
> We recognize all people as the foundation of humanity, and our actions contribute to the continued existence and growth of our shared humanity.
|
|
25
|
-
|
|
26
|
-
### Release versioning
|
|
27
|
-
- Keep releases close to the minor versions and publish patches only if required.
|
|
28
|
-
|
|
29
|
-
### Examples of unacceptable behavior by participants:
|
|
30
|
-
- Use of sexual language or imagery.
|
|
31
|
-
- Derogatory comments or personal attacks.
|
|
32
|
-
- Trolling, public or private harassment.
|
|
33
|
-
- Insults or other unprofessional conduct.
|
|
34
|
-
|
|
35
|
-
### Enforcement
|
|
36
|
-
Project maintainers have the right and responsibility to:
|
|
37
|
-
- Remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions not aligned with this Code of Conduct.
|
|
38
|
-
- Remove maintainers who violate this Code of Conduct.
|
|
39
|
-
|
|
40
|
-
Instances of unacceptable behavior can be reported by contacting the project team.
|
|
41
|
-
|
|
42
|
-
This Code of Conduct is adapted from the [Contributor Covenant, version 1.1.0](https://contributor-covenant.org/version/1/1/0/).
|