1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const metadataReading_1 = require("./internal/metadata/metadataReading");
|
4 | const string_1 = require("./internal/util/string");
|
5 | const scan_1 = require("./scan");
|
6 | const constructionUtils_1 = require("./util/constructionUtils");
|
7 | var QuestionStyle;
|
8 | (function (QuestionStyle) {
|
9 | QuestionStyle["Dialog"] = "dialog";
|
10 | QuestionStyle["Threaded"] = "threaded";
|
11 | QuestionStyle["Unthreaded"] = "unthreaded";
|
12 | QuestionStyle["DialogAction"] = "dialog_action";
|
13 | })(QuestionStyle = exports.QuestionStyle || (exports.QuestionStyle = {}));
|
14 |
|
15 |
|
16 |
|
17 |
|
18 | function commandHandlerFrom(h, factory, name = h.name || `Command${string_1.generateHash(h.toString())}`, description = name, intent = [], tags = [], autoSubmit = false, question) {
|
19 | const handler = new FunctionWrappingCommandHandler(name, description, h, factory, tags, intent, autoSubmit, question);
|
20 | scan_1.registerCommand(handler);
|
21 | return handler;
|
22 | }
|
23 | exports.commandHandlerFrom = commandHandlerFrom;
|
24 | class FunctionWrappingCommandHandler {
|
25 | constructor(name, description, h, parametersFactory,
|
26 | // tslint:disable-next-line:variable-name
|
27 | _tags = [],
|
28 | // tslint:disable-next-line:variable-name
|
29 | _intent = [], autoSubmit = false,
|
30 | // tslint:disable-next-line:variable-name
|
31 | _question) {
|
32 | this.name = name;
|
33 | this.description = description;
|
34 | this.h = h;
|
35 | this.parametersFactory = parametersFactory;
|
36 | this._tags = _tags;
|
37 | this._intent = _intent;
|
38 | this.autoSubmit = autoSubmit;
|
39 | this._question = _question;
|
40 | const newParamInstance = this.freshParametersInstance();
|
41 | const md = metadataReading_1.metadataFromInstance(newParamInstance);
|
42 | this.parameters = md.parameters;
|
43 | this.mapped_parameters = md.mapped_parameters;
|
44 | this.values = md.values;
|
45 | this.secrets = md.secrets;
|
46 | this.intent = string_1.toStringArray(_intent);
|
47 | this.tags = string_1.toStringArray(_tags).map(t => ({ name: t, description: t }));
|
48 | this.auto_submit = autoSubmit;
|
49 | this.question = (!!_question ? _question.toString() : undefined);
|
50 | }
|
51 | freshParametersInstance() {
|
52 | return constructionUtils_1.toFactory(this.parametersFactory)();
|
53 | }
|
54 | handle(ctx, params) {
|
55 | return this.h(ctx, params);
|
56 | }
|
57 | }
|
58 |
|
\ | No newline at end of file |