@intecoag/inteco-cli 1.11.6 → 1.12.0-beta.1
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 +12 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +158 -0
- package/dist/index.js.map +1 -0
- package/dist/modules/adbBridge.d.ts +2 -0
- package/dist/modules/adbBridge.d.ts.map +1 -0
- package/dist/modules/adbBridge.js +40 -0
- package/dist/modules/adbBridge.js.map +1 -0
- package/dist/modules/adbIntentSender.d.ts +2 -0
- package/dist/modules/adbIntentSender.d.ts.map +1 -0
- package/dist/modules/adbIntentSender.js +67 -0
- package/dist/modules/adbIntentSender.js.map +1 -0
- package/dist/modules/azureSync.d.ts +4 -0
- package/dist/modules/azureSync.d.ts.map +1 -0
- package/{src → dist}/modules/azureSync.js +50 -131
- package/dist/modules/azureSync.js.map +1 -0
- package/dist/modules/bundleProduct.d.ts +2 -0
- package/dist/modules/bundleProduct.d.ts.map +1 -0
- package/{src → dist}/modules/bundleProduct.js +41 -80
- package/dist/modules/bundleProduct.js.map +1 -0
- package/dist/modules/changelog.d.ts +3 -0
- package/dist/modules/changelog.d.ts.map +1 -0
- package/dist/modules/changelog.js +45 -0
- package/dist/modules/changelog.js.map +1 -0
- package/dist/modules/configMutation.d.ts +2 -0
- package/dist/modules/configMutation.d.ts.map +1 -0
- package/{src → dist}/modules/configMutation.js +54 -101
- package/dist/modules/configMutation.js.map +1 -0
- package/dist/modules/csvMerger.d.ts +2 -0
- package/dist/modules/csvMerger.d.ts.map +1 -0
- package/dist/modules/csvMerger.js +104 -0
- package/dist/modules/csvMerger.js.map +1 -0
- package/dist/modules/deleteDB.d.ts +2 -0
- package/dist/modules/deleteDB.d.ts.map +1 -0
- package/dist/modules/deleteDB.js +75 -0
- package/dist/modules/deleteDB.js.map +1 -0
- package/dist/modules/dumpDB.d.ts +3 -0
- package/dist/modules/dumpDB.d.ts.map +1 -0
- package/{src → dist}/modules/dumpDB.js +64 -89
- package/dist/modules/dumpDB.js.map +1 -0
- package/dist/modules/dumpTableToCSV.d.ts +2 -0
- package/dist/modules/dumpTableToCSV.d.ts.map +1 -0
- package/dist/modules/dumpTableToCSV.js +128 -0
- package/dist/modules/dumpTableToCSV.js.map +1 -0
- package/dist/modules/extdSearch.d.ts +2 -0
- package/dist/modules/extdSearch.d.ts.map +1 -0
- package/{src → dist}/modules/extdSearch.js +60 -60
- package/dist/modules/extdSearch.js.map +1 -0
- package/dist/modules/githubDeploymentKey.d.ts +3 -0
- package/dist/modules/githubDeploymentKey.d.ts.map +1 -0
- package/dist/modules/githubDeploymentKey.js +241 -0
- package/dist/modules/githubDeploymentKey.js.map +1 -0
- package/dist/modules/githubDeploymentKeysList.d.ts +6 -0
- package/dist/modules/githubDeploymentKeysList.d.ts.map +1 -0
- package/dist/modules/githubDeploymentKeysList.js +185 -0
- package/dist/modules/githubDeploymentKeysList.js.map +1 -0
- package/dist/modules/githubSecurityAdvisories.d.ts +3 -0
- package/dist/modules/githubSecurityAdvisories.d.ts.map +1 -0
- package/dist/modules/githubSecurityAdvisories.js +145 -0
- package/dist/modules/githubSecurityAdvisories.js.map +1 -0
- package/dist/modules/graphqlSchemaExport.d.ts +2 -0
- package/dist/modules/graphqlSchemaExport.d.ts.map +1 -0
- package/dist/modules/graphqlSchemaExport.js +59 -0
- package/dist/modules/graphqlSchemaExport.js.map +1 -0
- package/dist/modules/importDB.d.ts +2 -0
- package/dist/modules/importDB.d.ts.map +1 -0
- package/{src → dist}/modules/importDB.js +48 -66
- package/dist/modules/importDB.js.map +1 -0
- package/dist/modules/rewriteConfig.d.ts +3 -0
- package/dist/modules/rewriteConfig.d.ts.map +1 -0
- package/dist/modules/rewriteConfig.js +75 -0
- package/dist/modules/rewriteConfig.js.map +1 -0
- package/dist/modules/setCLIConfig.d.ts +2 -0
- package/dist/modules/setCLIConfig.d.ts.map +1 -0
- package/dist/modules/setCLIConfig.js +29 -0
- package/dist/modules/setCLIConfig.js.map +1 -0
- package/dist/modules/syncConfig.d.ts +2 -0
- package/dist/modules/syncConfig.d.ts.map +1 -0
- package/{src → dist}/modules/syncConfig.js +74 -127
- package/dist/modules/syncConfig.js.map +1 -0
- package/dist/modules/t003Rewrite.d.ts +2 -0
- package/dist/modules/t003Rewrite.d.ts.map +1 -0
- package/dist/modules/t003Rewrite.js +53 -0
- package/dist/modules/t003Rewrite.js.map +1 -0
- package/dist/modules/t009Search.d.ts +2 -0
- package/dist/modules/t009Search.d.ts.map +1 -0
- package/dist/modules/t009Search.js +30 -0
- package/dist/modules/t009Search.js.map +1 -0
- package/{src → dist}/ressources/cmds.json +3 -0
- package/dist/utils/azure/azure.d.ts +24 -0
- package/dist/utils/azure/azure.d.ts.map +1 -0
- package/{src → dist}/utils/azure/azure.js +14 -21
- package/dist/utils/azure/azure.js.map +1 -0
- package/dist/utils/config/config.d.ts +27 -0
- package/dist/utils/config/config.d.ts.map +1 -0
- package/dist/utils/config/config.js +74 -0
- package/dist/utils/config/config.js.map +1 -0
- package/dist/utils/db/DB.d.ts +14 -0
- package/dist/utils/db/DB.d.ts.map +1 -0
- package/dist/utils/db/DB.js +61 -0
- package/dist/utils/db/DB.js.map +1 -0
- package/dist/utils/fs/FS.d.ts +15 -0
- package/dist/utils/fs/FS.d.ts.map +1 -0
- package/{src → dist}/utils/fs/FS.js +31 -45
- package/dist/utils/fs/FS.js.map +1 -0
- package/dist/utils/github/github.d.ts +29 -0
- package/dist/utils/github/github.d.ts.map +1 -0
- package/dist/utils/github/github.js +96 -0
- package/dist/utils/github/github.js.map +1 -0
- package/dist/utils/shell/DatabaseShell.d.ts +77 -0
- package/dist/utils/shell/DatabaseShell.d.ts.map +1 -0
- package/{src → dist}/utils/shell/DatabaseShell.js +73 -87
- package/dist/utils/shell/DatabaseShell.js.map +1 -0
- package/dist/utils/shell/DatabaseShellBuilder.d.ts +67 -0
- package/dist/utils/shell/DatabaseShellBuilder.d.ts.map +1 -0
- package/{src → dist}/utils/shell/DatabaseShellBuilder.js +50 -59
- package/dist/utils/shell/DatabaseShellBuilder.js.map +1 -0
- package/dist/utils/shell/Shell.d.ts +30 -0
- package/dist/utils/shell/Shell.d.ts.map +1 -0
- package/{src → dist}/utils/shell/Shell.js +14 -19
- package/dist/utils/shell/Shell.js.map +1 -0
- package/dist/utils/shell/ShellBuilder.d.ts +60 -0
- package/dist/utils/shell/ShellBuilder.d.ts.map +1 -0
- package/{src → dist}/utils/shell/ShellBuilder.js +23 -44
- package/dist/utils/shell/ShellBuilder.js.map +1 -0
- package/package.json +31 -8
- package/.github/dependabot.yml +0 -28
- package/.github/workflows/publish.yml +0 -31
- package/.husky/commit-msg +0 -1
- package/.vscode/settings.json +0 -6
- package/commitlint.config.mjs +0 -4
- package/src/index.js +0 -130
- package/src/modules/adbBridge.js +0 -52
- package/src/modules/adbIntentSender.js +0 -82
- package/src/modules/changelog.js +0 -60
- package/src/modules/csvMerger.js +0 -118
- package/src/modules/deleteDB.js +0 -84
- package/src/modules/dumpTableToCSV.js +0 -154
- package/src/modules/githubDeploymentKey.js +0 -265
- package/src/modules/githubDeploymentKeysList.js +0 -199
- package/src/modules/githubSecurityAdvisories.js +0 -162
- package/src/modules/graphqlSchemaExport.js +0 -61
- package/src/modules/rewriteConfig.js +0 -93
- package/src/modules/setCLIConfig.js +0 -33
- package/src/modules/t003Rewrite.js +0 -64
- package/src/modules/t009Search.js +0 -34
- package/src/utils/config/config.js +0 -70
- package/src/utils/db/DB.js +0 -54
- package/src/utils/github/github.js +0 -102
- /package/{src → dist}/ressources/wegas_p.ico +0 -0
- /package/{src → dist}/utils/config/default.json +0 -0
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import chalk from "chalk";
|
|
2
|
-
import {
|
|
3
|
-
import { ShellBuilder } from "./ShellBuilder.js"
|
|
2
|
+
import { ShellBuilder } from "./ShellBuilder.js";
|
|
4
3
|
import { DatabaseShell } from "./DatabaseShell.js";
|
|
5
|
-
|
|
6
4
|
export class DatabaseShellBuilder {
|
|
7
|
-
|
|
5
|
+
configs;
|
|
6
|
+
tables;
|
|
7
|
+
editTools;
|
|
8
8
|
constructor() {
|
|
9
9
|
/**
|
|
10
10
|
* The available configs for the shell
|
|
@@ -12,17 +12,14 @@ export class DatabaseShellBuilder {
|
|
|
12
12
|
* @private
|
|
13
13
|
*/
|
|
14
14
|
this.configs = [];
|
|
15
|
-
|
|
16
15
|
/**
|
|
17
16
|
* The available tables for the shell
|
|
18
17
|
* @type {object[]}
|
|
19
18
|
* @private
|
|
20
19
|
*/
|
|
21
20
|
this.tables = [];
|
|
22
|
-
|
|
23
21
|
this.editTools = null;
|
|
24
22
|
}
|
|
25
|
-
|
|
26
23
|
/**
|
|
27
24
|
* Adds a table config to the shell
|
|
28
25
|
* @param {TableConfig} tableConfig The config to add
|
|
@@ -32,7 +29,6 @@ export class DatabaseShellBuilder {
|
|
|
32
29
|
this.configs.push(tableConfig);
|
|
33
30
|
return this;
|
|
34
31
|
}
|
|
35
|
-
|
|
36
32
|
/**
|
|
37
33
|
* Adds a source table to the shell
|
|
38
34
|
* @param {string} name The name displayed in the selection
|
|
@@ -43,7 +39,6 @@ export class DatabaseShellBuilder {
|
|
|
43
39
|
this.tables.push({ name: name, tables: tables });
|
|
44
40
|
return this;
|
|
45
41
|
}
|
|
46
|
-
|
|
47
42
|
/**
|
|
48
43
|
* Enables edit tools with the specified selectors and values
|
|
49
44
|
* @param {{title: string, column: string, default: string}[]} columns The colums that are used in the editor
|
|
@@ -59,76 +54,77 @@ export class DatabaseShellBuilder {
|
|
|
59
54
|
requiredValues: requiredValues,
|
|
60
55
|
optionalValues: optionalValues
|
|
61
56
|
};
|
|
62
|
-
|
|
63
57
|
return this;
|
|
64
58
|
}
|
|
65
|
-
|
|
66
59
|
/**
|
|
67
60
|
* Builds the Shell
|
|
68
61
|
* @returns {DatabaseShell}
|
|
69
62
|
*/
|
|
70
63
|
build() {
|
|
71
64
|
const databaseShell = new DatabaseShell();
|
|
72
|
-
|
|
73
65
|
const builder = new ShellBuilder();
|
|
74
66
|
builder.withBuiltInHandler()
|
|
75
67
|
.withBuiltInCommands()
|
|
76
68
|
.withCommandHandler((_, input) => { databaseShell.executeSearch(input); return true; })
|
|
77
69
|
.withCommand(":cfg", "Reconfigure the Database and Search Type", async () => await databaseShell.configure());
|
|
78
|
-
|
|
79
|
-
this.configs.forEach(config => {
|
|
70
|
+
this.configs.forEach((config) => {
|
|
80
71
|
builder.withCommand(config.cmdShortcut, `Switch to ${config.name}`, () => {
|
|
81
72
|
databaseShell.currentConfig = config;
|
|
82
73
|
console.log(`Switched to ${chalk.yellow(config.name)}.`);
|
|
83
74
|
});
|
|
84
75
|
});
|
|
85
|
-
|
|
86
|
-
if(
|
|
87
|
-
builder.withCommand(":del", "Delete a row", async (
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
.withCommand(":dup", "Duplicate a row", async (
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
.withCommand(":mod", "Modify an existing row", async (
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
76
|
+
const editTools = this.editTools;
|
|
77
|
+
if (editTools !== null) {
|
|
78
|
+
builder.withCommand(":del", "Delete a row", async () => {
|
|
79
|
+
console.log(chalk.yellow("Select the row to delete: "));
|
|
80
|
+
const rowData = await databaseShell.selectRow(editTools.columns, editTools.requiredSelectors);
|
|
81
|
+
if (!rowData)
|
|
82
|
+
return;
|
|
83
|
+
await databaseShell.deleteRow(rowData);
|
|
84
|
+
console.log(chalk.red("Row deleted"));
|
|
85
|
+
})
|
|
86
|
+
.withCommand(":dup", "Duplicate a row", async () => {
|
|
87
|
+
console.log(chalk.yellow("Select the row to duplicate: "));
|
|
88
|
+
const rowData = await databaseShell.selectRow(editTools.columns, editTools.requiredSelectors);
|
|
89
|
+
if (!rowData)
|
|
90
|
+
return;
|
|
91
|
+
console.log(chalk.yellow("Enter the updated row data: "));
|
|
92
|
+
const editedData = await databaseShell.editRow(rowData, editTools.columns, editTools.requiredValues, editTools.optionalValues);
|
|
93
|
+
if (!editedData)
|
|
94
|
+
return;
|
|
95
|
+
await databaseShell.insertRow(editedData);
|
|
96
|
+
console.log(chalk.green("Row duplicated"));
|
|
97
|
+
})
|
|
98
|
+
.withCommand(":mod", "Modify an existing row", async () => {
|
|
99
|
+
console.log(chalk.yellow("Select the row to edit: "));
|
|
100
|
+
const rowData = await databaseShell.selectRow(editTools.columns, editTools.requiredSelectors);
|
|
101
|
+
if (rowData === null)
|
|
102
|
+
return;
|
|
103
|
+
console.log(chalk.yellow("Enter the updated row data: "));
|
|
104
|
+
const editedData = await databaseShell.editRow(rowData, editTools.columns, editTools.requiredValues, editTools.optionalValues);
|
|
105
|
+
if (!editedData)
|
|
106
|
+
return;
|
|
107
|
+
await databaseShell.updateRow(editedData, rowData);
|
|
108
|
+
console.log(chalk.yellow("Row updated"));
|
|
109
|
+
});
|
|
119
110
|
}
|
|
120
|
-
|
|
121
111
|
const shell = builder.build();
|
|
122
|
-
|
|
112
|
+
if (this.configs.length === 0) {
|
|
113
|
+
throw new Error("No table configuration provided for DatabaseShellBuilder");
|
|
114
|
+
}
|
|
123
115
|
databaseShell.shell = shell;
|
|
124
116
|
databaseShell.currentConfig = this.configs[0];
|
|
125
117
|
databaseShell.tables = this.tables;
|
|
126
|
-
|
|
127
118
|
return databaseShell;
|
|
128
119
|
}
|
|
129
120
|
}
|
|
130
|
-
|
|
131
121
|
export class TableConfig {
|
|
122
|
+
name;
|
|
123
|
+
cmdShortcut;
|
|
124
|
+
searchKeys;
|
|
125
|
+
threshold;
|
|
126
|
+
tableHeader;
|
|
127
|
+
tableFormatter;
|
|
132
128
|
constructor() {
|
|
133
129
|
this.name = "";
|
|
134
130
|
this.cmdShortcut = "";
|
|
@@ -137,34 +133,29 @@ export class TableConfig {
|
|
|
137
133
|
this.tableHeader = [];
|
|
138
134
|
this.tableFormatter = () => [];
|
|
139
135
|
}
|
|
140
|
-
|
|
141
136
|
withName(name) {
|
|
142
137
|
this.name = name;
|
|
143
138
|
return this;
|
|
144
139
|
}
|
|
145
|
-
|
|
146
140
|
withShortcut(shortcut) {
|
|
147
141
|
this.cmdShortcut = shortcut;
|
|
148
142
|
return this;
|
|
149
143
|
}
|
|
150
|
-
|
|
151
144
|
withSearchKeys(keys) {
|
|
152
145
|
this.searchKeys = keys;
|
|
153
146
|
return this;
|
|
154
147
|
}
|
|
155
|
-
|
|
156
148
|
withThreshold(threshold) {
|
|
157
149
|
this.threshold = threshold;
|
|
158
150
|
return this;
|
|
159
151
|
}
|
|
160
|
-
|
|
161
152
|
withHeader(tableHeader) {
|
|
162
153
|
this.tableHeader = tableHeader;
|
|
163
154
|
return this;
|
|
164
155
|
}
|
|
165
|
-
|
|
166
156
|
withFormatter(formatter) {
|
|
167
157
|
this.tableFormatter = formatter;
|
|
168
158
|
return this;
|
|
169
159
|
}
|
|
170
|
-
}
|
|
160
|
+
}
|
|
161
|
+
//# sourceMappingURL=DatabaseShellBuilder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DatabaseShellBuilder.js","sourceRoot":"","sources":["../../../src/utils/shell/DatabaseShellBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAChD,OAAO,EAAE,aAAa,EAAiB,MAAM,oBAAoB,CAAC;AAsBlE,MAAM,OAAO,oBAAoB;IAC7B,OAAO,CAAgB;IACvB,MAAM,CAAgB;IACtB,SAAS,CAAmB;IAE5B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;IAED,aAAa,CAAC,SAA0F;QACpG,IAAI,CAAC,cAAc,GAAG,SAAS,CAAC;QAChC,OAAO,IAAI,CAAC;IAChB,CAAC;CACJ"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export type ShellCommand = {
|
|
2
|
+
name: string;
|
|
3
|
+
helpText: string;
|
|
4
|
+
handler: (shell: Shell, input: string, ...args: string[]) => Promise<unknown> | unknown;
|
|
5
|
+
};
|
|
6
|
+
export type ShellCommandHandler = (shell: Shell, input: string) => Promise<boolean> | boolean;
|
|
7
|
+
export declare class Shell {
|
|
8
|
+
commands: ShellCommand[];
|
|
9
|
+
commandHandlers: ShellCommandHandler[];
|
|
10
|
+
name: string;
|
|
11
|
+
prompt: string;
|
|
12
|
+
autocomplete: string[];
|
|
13
|
+
exitRequested: boolean;
|
|
14
|
+
constructor();
|
|
15
|
+
/**
|
|
16
|
+
* Starts the shell in a loop and continues until exit() is called.
|
|
17
|
+
*/
|
|
18
|
+
run(): Promise<void>;
|
|
19
|
+
/**
|
|
20
|
+
* Requests the shell to exit
|
|
21
|
+
*/
|
|
22
|
+
exit(): void;
|
|
23
|
+
/**
|
|
24
|
+
* Executes a single command in the shell
|
|
25
|
+
* @param {String} input The command to execute
|
|
26
|
+
* @returns {Promise<boolean>}
|
|
27
|
+
*/
|
|
28
|
+
handleCommand(input: string): Promise<boolean>;
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=Shell.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Shell.d.ts","sourceRoot":"","sources":["../../../src/utils/shell/Shell.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,YAAY,GAAG;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,MAAM,EAAE,KAAK,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC;CAC3F,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC;AAO9F,qBAAa,KAAK;IACd,QAAQ,EAAE,YAAY,EAAE,CAAC;IACzB,eAAe,EAAE,mBAAmB,EAAE,CAAC;IACvC,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,aAAa,EAAE,OAAO,CAAC;;IAYvB;;OAEG;IACG,GAAG;IA2CT;;OAEG;IACH,IAAI;IAIJ;;;;OAIG;IACG,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;CASvD"}
|
|
@@ -1,32 +1,32 @@
|
|
|
1
1
|
import chalk from "chalk";
|
|
2
2
|
import prompts from "prompts";
|
|
3
|
-
|
|
4
3
|
export class Shell {
|
|
5
|
-
|
|
4
|
+
commands;
|
|
5
|
+
commandHandlers;
|
|
6
|
+
name;
|
|
7
|
+
prompt;
|
|
8
|
+
autocomplete;
|
|
9
|
+
exitRequested;
|
|
6
10
|
constructor() {
|
|
7
11
|
this.commands = [];
|
|
8
12
|
this.commandHandlers = [];
|
|
9
13
|
this.name = "";
|
|
10
14
|
this.prompt = "";
|
|
11
15
|
this.autocomplete = [];
|
|
12
|
-
|
|
13
16
|
this.exitRequested = false;
|
|
14
17
|
}
|
|
15
|
-
|
|
16
18
|
/**
|
|
17
19
|
* Starts the shell in a loop and continues until exit() is called.
|
|
18
20
|
*/
|
|
19
21
|
async run() {
|
|
20
22
|
this.exitRequested = false;
|
|
21
|
-
|
|
22
23
|
console.log(chalk.green(`${this.name} Started.`));
|
|
23
|
-
|
|
24
24
|
while (!this.exitRequested) {
|
|
25
25
|
const response = await prompts({
|
|
26
26
|
type: "autocomplete",
|
|
27
27
|
name: "input",
|
|
28
28
|
message: this.prompt,
|
|
29
|
-
choices: this.autocomplete.map(ac => ({
|
|
29
|
+
choices: this.autocomplete.map((ac) => ({
|
|
30
30
|
title: ac,
|
|
31
31
|
value: ac
|
|
32
32
|
})),
|
|
@@ -34,49 +34,44 @@ export class Shell {
|
|
|
34
34
|
suggest: async (input, choices) => {
|
|
35
35
|
const text = input ?? "";
|
|
36
36
|
const q = text.trim().toLowerCase();
|
|
37
|
-
|
|
38
37
|
const matches = q.length === 0
|
|
39
38
|
? choices
|
|
40
|
-
: choices.filter(choice => choice.title.toLowerCase().startsWith(q));
|
|
41
|
-
|
|
39
|
+
: choices.filter((choice) => choice.title.toLowerCase().startsWith(q));
|
|
42
40
|
return [
|
|
43
41
|
{
|
|
44
42
|
title: text.length > 0 ? text : " ",
|
|
45
43
|
value: text
|
|
46
44
|
},
|
|
47
|
-
...matches.filter(choice => choice.value !== text)
|
|
45
|
+
...matches.filter((choice) => (choice.value ?? choice.title) !== text)
|
|
48
46
|
];
|
|
49
47
|
}
|
|
50
48
|
});
|
|
51
|
-
|
|
52
49
|
const input = (response?.input ?? "").trim();
|
|
53
|
-
|
|
54
50
|
if (!await this.handleCommand(input)) {
|
|
55
51
|
console.log(chalk.red(`Unknown command '${input}'`));
|
|
56
52
|
}
|
|
57
53
|
}
|
|
58
|
-
|
|
59
54
|
console.log(chalk.yellow(`\n\n${this.name} Ended.`));
|
|
60
55
|
}
|
|
61
|
-
|
|
62
56
|
/**
|
|
63
57
|
* Requests the shell to exit
|
|
64
58
|
*/
|
|
65
59
|
exit() {
|
|
66
60
|
this.exitRequested = true;
|
|
67
61
|
}
|
|
68
|
-
|
|
69
62
|
/**
|
|
70
63
|
* Executes a single command in the shell
|
|
71
64
|
* @param {String} input The command to execute
|
|
72
65
|
* @returns {Promise<boolean>}
|
|
73
66
|
*/
|
|
74
67
|
async handleCommand(input) {
|
|
75
|
-
for(let i = 0; i < this.commandHandlers.length; i++) {
|
|
68
|
+
for (let i = 0; i < this.commandHandlers.length; i++) {
|
|
76
69
|
const handler = this.commandHandlers[i];
|
|
77
|
-
if(await handler(this, input))
|
|
70
|
+
if (await handler(this, input)) {
|
|
78
71
|
return true;
|
|
72
|
+
}
|
|
79
73
|
}
|
|
80
74
|
return false;
|
|
81
75
|
}
|
|
82
|
-
}
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=Shell.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Shell.js","sourceRoot":"","sources":["../../../src/utils/shell/Shell.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,OAAO,MAAM,SAAS,CAAC;AAe9B,MAAM,OAAO,KAAK;IACd,QAAQ,CAAiB;IACzB,eAAe,CAAwB;IACvC,IAAI,CAAS;IACb,MAAM,CAAS;IACf,YAAY,CAAW;IACvB,aAAa,CAAU;IAEvB;QACI,IAAI,CAAC,QAAQ,GAAG,EAAE,CAAC;QACnB,IAAI,CAAC,eAAe,GAAG,EAAE,CAAC;QAC1B,IAAI,CAAC,IAAI,GAAG,EAAE,CAAC;QACf,IAAI,CAAC,MAAM,GAAG,EAAE,CAAC;QACjB,IAAI,CAAC,YAAY,GAAG,EAAE,CAAC;QAEvB,IAAI,CAAC,aAAa,GAAG,KAAK,CAAC;IAC/B,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,GAAG;QACL,IAAI,CAAC,aAAa,GAAG,KAAK,CAAC;QAE3B,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,IAAI,WAAW,CAAC,CAAC,CAAC;QAElD,OAAO,CAAC,IAAI,CAAC,aAAa,EAAE,CAAC;YACzB,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC;gBAC3B,IAAI,EAAE,cAAc;gBACpB,IAAI,EAAE,OAAO;gBACb,OAAO,EAAE,IAAI,CAAC,MAAM;gBACpB,OAAO,EAAE,IAAI,CAAC,YAAY,CAAC,GAAG,CA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AC,IAAI,SAAS,CAAC,CAAC,CAAC;IACzD,CAAC;IAED;;OAEG;IACH,IAAI;QACA,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC;IAC9B,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,aAAa,CAAC,KAAa;QAC7B,KAAI,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,eAAe,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YAClD,MAAM,OAAO,GAAG,IAAI,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC;YACxC,IAAG,MAAM,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,EAAE,CAAC;gBAC5B,OAAO,IAAI,CAAC;YAChB,CAAC;QACL,CAAC;QACD,OAAO,KAAK,CAAC;IACjB,CAAC;CACJ"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { Shell, type ShellCommand, type ShellCommandHandler } from "./Shell.js";
|
|
2
|
+
export declare class ShellBuilder {
|
|
3
|
+
commands: ShellCommand[];
|
|
4
|
+
commandHandlers: ShellCommandHandler[];
|
|
5
|
+
name: string;
|
|
6
|
+
prompt: string;
|
|
7
|
+
useBuiltInHandler: boolean;
|
|
8
|
+
constructor();
|
|
9
|
+
/**
|
|
10
|
+
* Adds the built-in command handler
|
|
11
|
+
* @returns {ShellBuilder}
|
|
12
|
+
*/
|
|
13
|
+
withBuiltInHandler(): this;
|
|
14
|
+
/**
|
|
15
|
+
* Adds the built-in commands (:q and :?), requires a supported handler to work
|
|
16
|
+
* @returns {ShellBuilder}
|
|
17
|
+
*/
|
|
18
|
+
withBuiltInCommands(): this;
|
|
19
|
+
/**
|
|
20
|
+
* Add a command to be executed by the built in command handler
|
|
21
|
+
* @param {String} commandName The command name to be entered in the command line
|
|
22
|
+
* @param {String} helpText The text displayed in the help
|
|
23
|
+
* @param {(shell: Shell, input: String, ...args: String[]) => void} handler The handler to be executed with the executing shell passed as an arugment
|
|
24
|
+
* @returns {ShellBuilder}
|
|
25
|
+
*/
|
|
26
|
+
withCommand(commandName: string, helpText: string, handler: (shell: Shell, input: string, ...args: string[]) => Promise<unknown> | unknown): ShellBuilder;
|
|
27
|
+
/**
|
|
28
|
+
* Change the name of the shell
|
|
29
|
+
* @param {String} name The name of the shell used in some texts
|
|
30
|
+
* @returns {ShellBuilder}
|
|
31
|
+
*/
|
|
32
|
+
withName(name: string): ShellBuilder;
|
|
33
|
+
/**
|
|
34
|
+
* Change the prompt displayed when entering text
|
|
35
|
+
* @param {String} prompt The text to be displayed in the prompt
|
|
36
|
+
* @returns {ShellBuilder}
|
|
37
|
+
*/
|
|
38
|
+
withPrompt(prompt: string): ShellBuilder;
|
|
39
|
+
/**
|
|
40
|
+
* Add a command handler to be executed if the inputted command doesn't correspond to a built in handler
|
|
41
|
+
* @param {(shell: Shell, input: String) => boolean} handler The handler to be executed with the inputted text and shell passed as arguments.
|
|
42
|
+
* Return true to signal that the handler was successful and shouldn't continue with another handler.
|
|
43
|
+
*
|
|
44
|
+
* @returns {ShellBuilder}
|
|
45
|
+
*/
|
|
46
|
+
withCommandHandler(handler: ShellCommandHandler): ShellBuilder;
|
|
47
|
+
/**
|
|
48
|
+
* Creates a usable shell with the built-in and custom functions.
|
|
49
|
+
* @returns {Shell}
|
|
50
|
+
*/
|
|
51
|
+
build(): Shell;
|
|
52
|
+
/**
|
|
53
|
+
* Splits a command into args with support for spaces and and escape sequences
|
|
54
|
+
* @private
|
|
55
|
+
* @param {String} input The unformatted command
|
|
56
|
+
* @returns {String[]}
|
|
57
|
+
*/
|
|
58
|
+
parseArgs(input: string): string[];
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=ShellBuilder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ShellBuilder.d.ts","sourceRoot":"","sources":["../../../src/utils/shell/ShellBuilder.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,KAAK,YAAY,EAAE,KAAK,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAEhF,qBAAa,YAAY;IACrB,QAAQ,EAAE,YAAY,EAAE,CAAC;IACzB,eAAe,EAAE,mBAAmB,EAAE,CAAC;IACvC,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,iBAAiB,EAAE,OAAO,CAAC;;IAU3B;;;OAGG;IACH,kBAAkB;IAyBlB;;;OAGG;IACH,mBAAmB;IAenB;;;;;;OAMG;IACH,WAAW,CAAC,WAAW,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,MAAM,EAAE,KAAK,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,GAAG,YAAY;IASzJ;;;;OAIG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY;IAKpC;;;;OAIG;IACH,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY;IAKxC;;;;;;OAMG;IACH,kBAAkB,CAAC,OAAO,EAAE,mBAAmB,GAAG,YAAY;IAK9D;;;OAGG;IACH,KAAK,IAAI,KAAK;IAWd;;;;;OAKG;IACH,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE;CA8CrC"}
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import chalk from "chalk";
|
|
2
|
-
import { Shell } from "./
|
|
3
|
-
|
|
2
|
+
import { Shell } from "./Shell.js";
|
|
4
3
|
export class ShellBuilder {
|
|
5
|
-
|
|
4
|
+
commands;
|
|
5
|
+
commandHandlers;
|
|
6
|
+
name;
|
|
7
|
+
prompt;
|
|
8
|
+
useBuiltInHandler;
|
|
6
9
|
constructor() {
|
|
7
10
|
this.commands = [];
|
|
8
11
|
this.commandHandlers = [];
|
|
@@ -10,7 +13,6 @@ export class ShellBuilder {
|
|
|
10
13
|
this.prompt = "Interactive Shell (show help with :?)";
|
|
11
14
|
this.useBuiltInHandler = false;
|
|
12
15
|
}
|
|
13
|
-
|
|
14
16
|
/**
|
|
15
17
|
* Adds the built-in command handler
|
|
16
18
|
* @returns {ShellBuilder}
|
|
@@ -18,47 +20,38 @@ export class ShellBuilder {
|
|
|
18
20
|
withBuiltInHandler() {
|
|
19
21
|
this.withCommandHandler(async (shell, input) => {
|
|
20
22
|
const parts = this.parseArgs(input);
|
|
21
|
-
if(parts.length == 0)
|
|
22
|
-
|
|
23
|
+
if (parts.length == 0)
|
|
24
|
+
return false;
|
|
23
25
|
const commandName = parts[0];
|
|
24
26
|
const args = parts.slice(1);
|
|
25
|
-
|
|
26
|
-
for(let i = 0; i < shell.commands.length; i++) {
|
|
27
|
+
for (let i = 0; i < shell.commands.length; i++) {
|
|
27
28
|
const command = shell.commands[i];
|
|
28
|
-
|
|
29
|
-
if(command.name == commandName) {
|
|
29
|
+
if (command.name == commandName) {
|
|
30
30
|
await command.handler(shell, input, ...args);
|
|
31
31
|
return true;
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
|
-
|
|
35
34
|
return false;
|
|
36
35
|
});
|
|
37
|
-
|
|
38
36
|
this.useBuiltInHandler = true;
|
|
39
|
-
|
|
40
37
|
return this;
|
|
41
38
|
}
|
|
42
|
-
|
|
43
39
|
/**
|
|
44
40
|
* Adds the built-in commands (:q and :?), requires a supported handler to work
|
|
45
41
|
* @returns {ShellBuilder}
|
|
46
42
|
*/
|
|
47
43
|
withBuiltInCommands() {
|
|
48
44
|
this.withCommand(":q", "Exit the shell", shell => {
|
|
49
|
-
|
|
50
|
-
|
|
45
|
+
shell.exit();
|
|
46
|
+
})
|
|
51
47
|
.withCommand(":?", "Shows this help", shell => {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
console.log(`${chalk.yellow(command.name)} - ${command.helpText}`);
|
|
56
|
-
});
|
|
48
|
+
console.log("\n" + chalk.cyan("Available Commands:"));
|
|
49
|
+
shell.commands.forEach(command => {
|
|
50
|
+
console.log(`${chalk.yellow(command.name)} - ${command.helpText}`);
|
|
57
51
|
});
|
|
58
|
-
|
|
52
|
+
});
|
|
59
53
|
return this;
|
|
60
54
|
}
|
|
61
|
-
|
|
62
55
|
/**
|
|
63
56
|
* Add a command to be executed by the built in command handler
|
|
64
57
|
* @param {String} commandName The command name to be entered in the command line
|
|
@@ -74,7 +67,6 @@ export class ShellBuilder {
|
|
|
74
67
|
});
|
|
75
68
|
return this;
|
|
76
69
|
}
|
|
77
|
-
|
|
78
70
|
/**
|
|
79
71
|
* Change the name of the shell
|
|
80
72
|
* @param {String} name The name of the shell used in some texts
|
|
@@ -84,7 +76,6 @@ export class ShellBuilder {
|
|
|
84
76
|
this.name = name;
|
|
85
77
|
return this;
|
|
86
78
|
}
|
|
87
|
-
|
|
88
79
|
/**
|
|
89
80
|
* Change the prompt displayed when entering text
|
|
90
81
|
* @param {String} prompt The text to be displayed in the prompt
|
|
@@ -94,34 +85,30 @@ export class ShellBuilder {
|
|
|
94
85
|
this.prompt = prompt;
|
|
95
86
|
return this;
|
|
96
87
|
}
|
|
97
|
-
|
|
98
88
|
/**
|
|
99
89
|
* Add a command handler to be executed if the inputted command doesn't correspond to a built in handler
|
|
100
90
|
* @param {(shell: Shell, input: String) => boolean} handler The handler to be executed with the inputted text and shell passed as arguments.
|
|
101
91
|
* Return true to signal that the handler was successful and shouldn't continue with another handler.
|
|
102
|
-
*
|
|
92
|
+
*
|
|
103
93
|
* @returns {ShellBuilder}
|
|
104
94
|
*/
|
|
105
95
|
withCommandHandler(handler) {
|
|
106
96
|
this.commandHandlers.push(handler);
|
|
107
97
|
return this;
|
|
108
98
|
}
|
|
109
|
-
|
|
110
99
|
/**
|
|
111
100
|
* Creates a usable shell with the built-in and custom functions.
|
|
112
101
|
* @returns {Shell}
|
|
113
102
|
*/
|
|
114
103
|
build() {
|
|
115
|
-
|
|
104
|
+
const shell = new Shell();
|
|
116
105
|
shell.commands = this.commands;
|
|
117
106
|
shell.name = this.name;
|
|
118
107
|
shell.prompt = this.prompt;
|
|
119
108
|
shell.commandHandlers = this.commandHandlers;
|
|
120
|
-
shell.autocomplete = shell.commands.map(c => c.name);
|
|
121
|
-
|
|
109
|
+
shell.autocomplete = shell.commands.map((c) => c.name);
|
|
122
110
|
return shell;
|
|
123
111
|
}
|
|
124
|
-
|
|
125
112
|
/**
|
|
126
113
|
* Splits a command into args with support for spaces and and escape sequences
|
|
127
114
|
* @private
|
|
@@ -133,45 +120,37 @@ export class ShellBuilder {
|
|
|
133
120
|
let current = "";
|
|
134
121
|
let inQuotes = false;
|
|
135
122
|
let escaping = false;
|
|
136
|
-
|
|
137
123
|
for (let i = 0; i < input.length; i++) {
|
|
138
124
|
const char = input[i];
|
|
139
|
-
|
|
140
125
|
if (escaping) {
|
|
141
126
|
current += char;
|
|
142
127
|
escaping = false;
|
|
143
128
|
continue;
|
|
144
129
|
}
|
|
145
|
-
|
|
146
130
|
if (char === "\\") {
|
|
147
131
|
escaping = true;
|
|
148
132
|
continue;
|
|
149
133
|
}
|
|
150
|
-
|
|
151
134
|
if (char === '"') {
|
|
152
135
|
inQuotes = !inQuotes;
|
|
153
136
|
continue;
|
|
154
137
|
}
|
|
155
|
-
|
|
156
138
|
if (char === " " && !inQuotes) {
|
|
157
139
|
if (current.length > 0) {
|
|
158
|
-
|
|
159
|
-
|
|
140
|
+
result.push(current);
|
|
141
|
+
current = "";
|
|
160
142
|
}
|
|
161
143
|
continue;
|
|
162
144
|
}
|
|
163
|
-
|
|
164
145
|
current += char;
|
|
165
146
|
}
|
|
166
|
-
|
|
167
147
|
if (escaping) {
|
|
168
148
|
current += "\\";
|
|
169
149
|
}
|
|
170
|
-
|
|
171
150
|
if (current.length > 0) {
|
|
172
151
|
result.push(current);
|
|
173
152
|
}
|
|
174
|
-
|
|
175
153
|
return result;
|
|
176
154
|
}
|
|
177
|
-
}
|
|
155
|
+
}
|
|
156
|
+
//# sourceMappingURL=ShellBuilder.js.map
|
|
@@ -0,0 +1 @@
|
|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