secrez 1.1.1 → 1.1.3
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 +503 -444
- package/bin/secrez.js +50 -47
- package/coverage.report +91 -85
- package/package.json +10 -12
- package/src/Command.js +78 -57
- package/src/PreCommand.js +75 -70
- package/src/Welcome.js +144 -134
- package/src/cliConfig.js +14 -14
- package/src/commands/Alias.js +123 -100
- package/src/commands/Bash.js +10 -12
- package/src/commands/Cat.js +117 -107
- package/src/commands/Cd.js +39 -42
- package/src/commands/Chat.js +75 -63
- package/src/commands/Conf.js +123 -99
- package/src/commands/Contacts.js +189 -171
- package/src/commands/Copy.js +132 -113
- package/src/commands/Courier.js +123 -105
- package/src/commands/Ds.js +88 -76
- package/src/commands/Edit.js +122 -103
- package/src/commands/Export.js +201 -116
- package/src/commands/Find.js +115 -110
- package/src/commands/Help.js +20 -23
- package/src/commands/Import.js +296 -225
- package/src/commands/Lcat.js +36 -39
- package/src/commands/Lcd.js +38 -39
- package/src/commands/Lls.js +58 -55
- package/src/commands/Lpwd.js +20 -24
- package/src/commands/Ls.js +107 -97
- package/src/commands/Mkdir.js +35 -38
- package/src/commands/Mv.js +147 -114
- package/src/commands/Paste.js +68 -65
- package/src/commands/Pwd.js +18 -23
- package/src/commands/Quit.js +22 -24
- package/src/commands/Rm.js +78 -70
- package/src/commands/Shell.js +31 -32
- package/src/commands/Ssh.js +77 -63
- package/src/commands/Tag.js +133 -112
- package/src/commands/Totp.js +166 -136
- package/src/commands/Touch.js +169 -56
- package/src/commands/Use.js +44 -41
- package/src/commands/Ver.js +16 -18
- package/src/commands/Whoami.js +34 -37
- package/src/commands/chat/Contacts.js +41 -44
- package/src/commands/chat/Help.js +20 -23
- package/src/commands/chat/Join.js +59 -55
- package/src/commands/chat/Leave.js +16 -22
- package/src/commands/chat/Quit.js +19 -24
- package/src/commands/chat/Send.js +58 -57
- package/src/commands/chat/Show.js +60 -51
- package/src/commands/chat/Whoami.js +18 -22
- package/src/commands/index.js +20 -22
- package/src/index.js +3 -3
- package/src/prompts/ChatPrompt.js +87 -82
- package/src/prompts/ChatPromptMock.js +11 -17
- package/src/prompts/CommandPrompt.js +146 -138
- package/src/prompts/Completion.js +64 -69
- package/src/prompts/MainPrompt.js +84 -77
- package/src/prompts/MainPromptMock.js +19 -30
- package/src/prompts/MultiEditorPrompt.js +21 -22
- package/src/prompts/SigintManager.js +21 -24
- package/src/utils/AliasManager.js +16 -18
- package/src/utils/ContactManager.js +15 -17
- package/src/utils/Fido2Client.js +59 -49
- package/src/utils/HelpProto.js +130 -117
- package/src/utils/Logger.js +48 -50
- package/.eslintignore +0 -0
- package/.eslintrc +0 -33
- package/.jshintrc +0 -3
@@ -1,184 +1,192 @@
|
|
1
|
-
const chalk = require(
|
2
|
-
const _ = require(
|
3
|
-
const fs = require(
|
4
|
-
const inquirer = require(
|
1
|
+
const chalk = require("chalk");
|
2
|
+
const _ = require("lodash");
|
3
|
+
const fs = require("fs-extra");
|
4
|
+
const inquirer = require("inquirer");
|
5
5
|
|
6
6
|
// eslint-disable-next-line node/no-unpublished-require
|
7
7
|
// const inquirerCommandPrompt = require('../../../../../inquirer-command-prompt')
|
8
|
-
const inquirerCommandPrompt = require(
|
9
|
-
const multiEditorPrompt = require(
|
10
|
-
inquirer.registerPrompt(
|
11
|
-
inquirer.registerPrompt(
|
8
|
+
const inquirerCommandPrompt = require("inquirer-command-prompt");
|
9
|
+
const multiEditorPrompt = require("./MultiEditorPrompt");
|
10
|
+
inquirer.registerPrompt("command", inquirerCommandPrompt);
|
11
|
+
inquirer.registerPrompt("multiEditor", multiEditorPrompt);
|
12
12
|
|
13
|
-
const {sleep, getKeyValue} = require(
|
14
|
-
const Completion = require(
|
15
|
-
const {FsUtils} = require(
|
16
|
-
const Logger = require(
|
17
|
-
const cliConfig = require(
|
18
|
-
const sigintManager = require(
|
13
|
+
const { sleep, getKeyValue } = require("@secrez/utils");
|
14
|
+
const Completion = require("./Completion");
|
15
|
+
const { FsUtils } = require("@secrez/fs");
|
16
|
+
const Logger = require("../utils/Logger");
|
17
|
+
const cliConfig = require("../cliConfig");
|
18
|
+
const sigintManager = require("./SigintManager");
|
19
19
|
|
20
|
-
let thiz
|
20
|
+
let thiz;
|
21
21
|
|
22
22
|
class CommandPrompt {
|
23
|
-
|
24
23
|
async getReady(options) {
|
25
|
-
thiz = this
|
26
|
-
this.inquirer = inquirer
|
27
|
-
this.commandPrompt = inquirerCommandPrompt
|
28
|
-
this.historyPath = options.historyPath
|
24
|
+
thiz = this;
|
25
|
+
this.inquirer = inquirer;
|
26
|
+
this.commandPrompt = inquirerCommandPrompt;
|
27
|
+
this.historyPath = options.historyPath;
|
29
28
|
inquirerCommandPrompt.setConfig({
|
30
29
|
history: {
|
31
30
|
save: false,
|
32
|
-
limit: 100
|
31
|
+
limit: 100,
|
33
32
|
},
|
34
|
-
onCtrlEnd: thiz.reorderCommandLineWithDefaultAtEnd
|
35
|
-
})
|
36
|
-
this.completion = cliConfig[options.completion]
|
37
|
-
this.commands = options.commands
|
38
|
-
this.environment = options.environment
|
39
|
-
this.context = options.context || 0
|
40
|
-
await this.setSigintPosition()
|
33
|
+
onCtrlEnd: thiz.reorderCommandLineWithDefaultAtEnd,
|
34
|
+
});
|
35
|
+
this.completion = cliConfig[options.completion];
|
36
|
+
this.commands = options.commands;
|
37
|
+
this.environment = options.environment;
|
38
|
+
this.context = options.context || 0;
|
39
|
+
await this.setSigintPosition();
|
41
40
|
}
|
42
41
|
|
43
42
|
async setSigintPosition() {
|
44
|
-
const {position, runNow} = await sigintManager.setPosition(this)
|
45
|
-
this.sigintPosition = position
|
43
|
+
const { position, runNow } = await sigintManager.setPosition(this);
|
44
|
+
this.sigintPosition = position;
|
46
45
|
if (runNow) {
|
47
|
-
await this.run()
|
46
|
+
await this.run();
|
48
47
|
}
|
49
48
|
}
|
50
49
|
|
51
50
|
startSigintManager() {
|
52
|
-
sigintManager.start()
|
51
|
+
sigintManager.start();
|
53
52
|
}
|
54
53
|
|
55
54
|
async firstRun() {
|
56
55
|
if (!this.getCommands) {
|
57
|
-
this.getCommands = Completion(this.completion)
|
58
|
-
this.basicCommands = await this.getCommands()
|
59
|
-
this.getCommands.bind(this)
|
56
|
+
this.getCommands = Completion(this.completion);
|
57
|
+
this.basicCommands = await this.getCommands();
|
58
|
+
this.getCommands.bind(this);
|
60
59
|
}
|
61
60
|
}
|
62
61
|
|
63
62
|
reorderCommandLineWithDefaultAtEnd(line) {
|
64
63
|
// reorder the line to put autocompletable words at the end of the line
|
65
|
-
let previousLine = line
|
66
|
-
line = _.trim(line).split(
|
67
|
-
let cmd = line[0]
|
64
|
+
let previousLine = line;
|
65
|
+
line = _.trim(line).split(" ");
|
66
|
+
let cmd = line[0];
|
68
67
|
if (cmd && thiz.commands[cmd]) {
|
69
|
-
let definitions = thiz.commands[cmd].optionDefinitions
|
70
|
-
let def = {}
|
71
|
-
let selfCompletables = 0
|
68
|
+
let definitions = thiz.commands[cmd].optionDefinitions;
|
69
|
+
let def = {};
|
70
|
+
let selfCompletables = 0;
|
72
71
|
for (let d of definitions) {
|
73
|
-
def[d.name] = d
|
74
|
-
if (d.defaultOption || d.isCompletable) selfCompletables
|
72
|
+
def[d.name] = d;
|
73
|
+
if (d.defaultOption || d.isCompletable) selfCompletables++;
|
75
74
|
}
|
76
|
-
let params = FsUtils.parseCommandLine(
|
77
|
-
|
75
|
+
let params = FsUtils.parseCommandLine(
|
76
|
+
definitions,
|
77
|
+
line.slice(1).join(" ")
|
78
|
+
);
|
79
|
+
let result = [];
|
78
80
|
for (let key in params) {
|
79
|
-
if (key !==
|
80
|
-
result.push(getKeyValue(params, key))
|
81
|
+
if (key !== "_unknown") {
|
82
|
+
result.push(getKeyValue(params, key));
|
81
83
|
}
|
82
84
|
}
|
83
85
|
result.sort((a, b) => {
|
84
|
-
let A = def[a.key]
|
85
|
-
let B = def[b.key]
|
86
|
-
return
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
86
|
+
let A = def[a.key];
|
87
|
+
let B = def[b.key];
|
88
|
+
return A.defaultOption
|
89
|
+
? 1
|
90
|
+
: B.defaultOption
|
91
|
+
? -1
|
92
|
+
: A.isCompletable
|
93
|
+
? 1
|
94
|
+
: B.isCompletable
|
95
|
+
? -1
|
96
|
+
: 0;
|
97
|
+
});
|
98
|
+
let ret = [cmd];
|
95
99
|
for (let c of result) {
|
96
100
|
if (!def[c.key].defaultOption) {
|
97
101
|
if (ret.length && /^-/.test(ret[ret.length - 1])) {
|
98
|
-
ret[ret.length - 1] += def[c.key].alias
|
102
|
+
ret[ret.length - 1] += def[c.key].alias;
|
99
103
|
} else {
|
100
|
-
ret.push(
|
104
|
+
ret.push("-" + def[c.key].alias);
|
101
105
|
}
|
102
106
|
}
|
103
107
|
if (def[c.key].type !== Boolean) {
|
104
|
-
ret.push(c.value)
|
108
|
+
ret.push(c.value);
|
105
109
|
}
|
106
110
|
}
|
107
|
-
if (selfCompletables === 2 && previousLine === ret.join(
|
108
|
-
let len = ret.length
|
111
|
+
if (selfCompletables === 2 && previousLine === ret.join(" ")) {
|
112
|
+
let len = ret.length;
|
109
113
|
if (len > 3) {
|
110
|
-
ret = ret
|
111
|
-
|
112
|
-
|
114
|
+
ret = ret
|
115
|
+
.slice(0, len - 3)
|
116
|
+
.concat(ret.slice(len - 1, len))
|
117
|
+
.concat(ret.slice(len - 3, len - 1));
|
113
118
|
}
|
114
119
|
}
|
115
|
-
return ret.join(
|
120
|
+
return ret.join(" ");
|
116
121
|
} else {
|
117
|
-
return
|
122
|
+
return "";
|
118
123
|
}
|
119
124
|
}
|
120
125
|
|
121
126
|
async saveHistory() {
|
122
|
-
let histories = JSON.stringify(inquirerCommandPrompt.getHistories(true))
|
123
|
-
let encryptedHistory = this.secrez.encryptData(histories)
|
124
|
-
await fs.writeFile(this.historyPath, encryptedHistory)
|
127
|
+
let histories = JSON.stringify(inquirerCommandPrompt.getHistories(true));
|
128
|
+
let encryptedHistory = this.secrez.encryptData(histories);
|
129
|
+
await fs.writeFile(this.historyPath, encryptedHistory);
|
125
130
|
}
|
126
131
|
|
127
132
|
async loadSavedHistory() {
|
128
|
-
let previousHistories
|
133
|
+
let previousHistories;
|
129
134
|
if (await fs.pathExists(this.historyPath)) {
|
130
|
-
let encryptedHistory = await fs.readFile(this.historyPath,
|
131
|
-
previousHistories = JSON.parse(this.secrez.decryptData(encryptedHistory))
|
132
|
-
inquirerCommandPrompt.setHistoryFromPreviousSavedHistories(
|
135
|
+
let encryptedHistory = await fs.readFile(this.historyPath, "utf8");
|
136
|
+
previousHistories = JSON.parse(this.secrez.decryptData(encryptedHistory));
|
137
|
+
inquirerCommandPrompt.setHistoryFromPreviousSavedHistories(
|
138
|
+
previousHistories
|
139
|
+
);
|
133
140
|
}
|
134
141
|
}
|
135
142
|
|
136
143
|
async loading() {
|
137
|
-
this.loadingIndex = 0
|
138
|
-
this.showLoading = true
|
139
|
-
await sleep(100)
|
144
|
+
this.loadingIndex = 0;
|
145
|
+
this.showLoading = true;
|
146
|
+
await sleep(100);
|
140
147
|
while (this.showLoading) {
|
141
|
-
const loader = [
|
142
|
-
this.loadingIndex = (this.loadingIndex + 1) % 4
|
143
|
-
process.stdout.write(
|
144
|
-
|
145
|
-
|
146
|
-
|
148
|
+
const loader = ["\\", "|", "/", "-"];
|
149
|
+
this.loadingIndex = (this.loadingIndex + 1) % 4;
|
150
|
+
process.stdout.write(
|
151
|
+
loader[this.loadingIndex] + " " + this.loadingMessage
|
152
|
+
);
|
153
|
+
await sleep(100);
|
154
|
+
process.stdout.clearLine();
|
155
|
+
process.stdout.cursorTo(0);
|
147
156
|
}
|
148
157
|
}
|
149
158
|
|
150
159
|
short(l, m) {
|
151
|
-
let res = []
|
160
|
+
let res = [];
|
152
161
|
if (l) {
|
153
|
-
l = _.trim(l)
|
154
|
-
let r = l.split(
|
162
|
+
l = _.trim(l);
|
163
|
+
let r = l.split("/");
|
155
164
|
if (r.length !== 1) {
|
156
|
-
r.pop()
|
157
|
-
r = r.join(
|
165
|
+
r.pop();
|
166
|
+
r = r.join("/") + "/";
|
158
167
|
} else {
|
159
|
-
r = l.split(
|
168
|
+
r = l.split(" ");
|
160
169
|
if (r.length !== 1) {
|
161
|
-
r.pop()
|
162
|
-
r = r.join(
|
170
|
+
r.pop();
|
171
|
+
r = r.join(" ") + " ";
|
163
172
|
} else {
|
164
|
-
r = l
|
173
|
+
r = l;
|
165
174
|
}
|
166
175
|
}
|
167
176
|
for (let i = 0; i < m.length; i++) {
|
168
177
|
try {
|
169
178
|
if (m[i] !== l) {
|
170
179
|
if (r !== l) {
|
171
|
-
m[i] = m[i].replace(RegExp(
|
180
|
+
m[i] = m[i].replace(RegExp("^" + r), "");
|
172
181
|
}
|
173
182
|
if (m[i]) {
|
174
|
-
res.push(m[i].replace(/^(-[a-zA-Z]{1} |--\w+(=| ))/,
|
183
|
+
res.push(m[i].replace(/^(-[a-zA-Z]{1} |--\w+(=| ))/, ""));
|
175
184
|
}
|
176
185
|
}
|
177
|
-
} catch (e) {
|
178
|
-
}
|
186
|
+
} catch (e) {}
|
179
187
|
}
|
180
188
|
}
|
181
|
-
return res
|
189
|
+
return res;
|
182
190
|
}
|
183
191
|
|
184
192
|
async preRun(options) {
|
@@ -190,44 +198,44 @@ class CommandPrompt {
|
|
190
198
|
}
|
191
199
|
|
192
200
|
prePromptMessage() {
|
193
|
-
return
|
201
|
+
return "MainPrompt";
|
194
202
|
}
|
195
203
|
|
196
204
|
promptMessage() {
|
197
|
-
return
|
205
|
+
return "$";
|
198
206
|
}
|
199
207
|
|
200
208
|
availableOptionsMessage(options) {
|
201
|
-
return chalk.grey(
|
209
|
+
return chalk.grey("Available options:");
|
202
210
|
}
|
203
211
|
|
204
212
|
noColorOnAnswered() {
|
205
|
-
return false
|
213
|
+
return false;
|
206
214
|
}
|
207
215
|
|
208
216
|
colorOnAnswered() {
|
209
|
-
return
|
217
|
+
return "grey";
|
210
218
|
}
|
211
219
|
|
212
220
|
onBeforeRewrite(line) {
|
213
221
|
if (/ (#|£)\d+(\w+:|)\/[\w/]+/.test(line)) {
|
214
|
-
line = line.replace(/ (#|£)\d+((\w+:|)\/[\w/]+)/,
|
222
|
+
line = line.replace(/ (#|£)\d+((\w+:|)\/[\w/]+)/, " $2");
|
215
223
|
}
|
216
|
-
return line
|
224
|
+
return line;
|
217
225
|
}
|
218
226
|
|
219
227
|
async run(options = {}) {
|
220
|
-
await this.firstRun()
|
221
|
-
await this.preRun(options)
|
228
|
+
await this.firstRun();
|
229
|
+
await this.preRun(options);
|
222
230
|
if (this.disableRun) {
|
223
|
-
return
|
231
|
+
return;
|
224
232
|
}
|
225
233
|
try {
|
226
|
-
let prefix = this.lastPrefix = this.prePromptMessage(options)
|
227
|
-
let {cmd} = await inquirer.prompt([
|
234
|
+
let prefix = (this.lastPrefix = this.prePromptMessage(options));
|
235
|
+
let { cmd } = await inquirer.prompt([
|
228
236
|
{
|
229
|
-
type:
|
230
|
-
name:
|
237
|
+
type: "command",
|
238
|
+
name: "cmd",
|
231
239
|
autoCompletion: this.getCommands,
|
232
240
|
short: this.short,
|
233
241
|
prefix,
|
@@ -240,57 +248,57 @@ class CommandPrompt {
|
|
240
248
|
onBeforeRewrite: this.onBeforeRewrite,
|
241
249
|
context: this.context,
|
242
250
|
onClose: () => {
|
243
|
-
fs.emptyDirSync(this.secrez.config.tmpPath)
|
251
|
+
fs.emptyDirSync(this.secrez.config.tmpPath);
|
244
252
|
},
|
245
|
-
validate: val => {
|
246
|
-
return val
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
options.cmd = _.trim(cmd)
|
253
|
-
await this.postRun(options)
|
253
|
+
validate: (val) => {
|
254
|
+
return val ? true : chalk.grey("Press TAB for suggestions.");
|
255
|
+
},
|
256
|
+
},
|
257
|
+
]);
|
258
|
+
options.cmd = _.trim(cmd);
|
259
|
+
await this.postRun(options);
|
254
260
|
} catch (e) {
|
255
|
-
console.error(e)
|
256
|
-
Logger.red(e.message)
|
261
|
+
console.error(e);
|
262
|
+
Logger.red(e.message);
|
257
263
|
}
|
258
264
|
}
|
259
265
|
|
260
266
|
getRl() {
|
261
|
-
return inquirerCommandPrompt.getRl()
|
267
|
+
return inquirerCommandPrompt.getRl();
|
262
268
|
}
|
263
269
|
|
264
270
|
async exec(cmds, noRun) {
|
265
271
|
for (let cmd of cmds) {
|
266
272
|
if (cmd) {
|
267
|
-
cmd = cmd.split(
|
268
|
-
const command = cmd[0]
|
273
|
+
cmd = cmd.split(" ");
|
274
|
+
const command = cmd[0];
|
269
275
|
if (this.basicCommands.includes(command)) {
|
270
|
-
let commandLine = cmd.slice(1).join(
|
276
|
+
let commandLine = cmd.slice(1).join(" ");
|
271
277
|
if (!commandLine) {
|
272
278
|
// prevent command-line-args from parsing process.argv
|
273
|
-
commandLine =
|
279
|
+
commandLine = " ";
|
274
280
|
}
|
275
281
|
try {
|
276
|
-
const options = FsUtils.parseCommandLine(
|
277
|
-
|
282
|
+
const options = FsUtils.parseCommandLine(
|
283
|
+
this.commands[command].optionDefinitions,
|
284
|
+
commandLine,
|
285
|
+
true
|
286
|
+
);
|
287
|
+
await this.commands[command].exec(options);
|
278
288
|
} catch (e) {
|
279
289
|
// console.error(e)
|
280
|
-
Logger.red(e.message)
|
281
|
-
await this.run()
|
290
|
+
Logger.red(e.message);
|
291
|
+
await this.run();
|
282
292
|
}
|
283
293
|
} else {
|
284
|
-
Logger.red(
|
294
|
+
Logger.red("Command not found");
|
285
295
|
if (!noRun) {
|
286
|
-
await this.run()
|
296
|
+
await this.run();
|
287
297
|
}
|
288
298
|
}
|
289
299
|
}
|
290
300
|
}
|
291
301
|
}
|
292
|
-
|
293
302
|
}
|
294
303
|
|
295
|
-
module.exports = CommandPrompt
|
296
|
-
|
304
|
+
module.exports = CommandPrompt;
|
@@ -1,112 +1,107 @@
|
|
1
|
-
const _ = require(
|
2
|
-
const {FsUtils} = require(
|
1
|
+
const _ = require("lodash");
|
2
|
+
const { FsUtils } = require("@secrez/fs");
|
3
3
|
|
4
4
|
class _Completion {
|
5
|
-
|
6
5
|
constructor(completion) {
|
7
|
-
this.completion = completion
|
6
|
+
this.completion = completion;
|
8
7
|
}
|
9
8
|
|
10
9
|
basicCommands() {
|
11
10
|
if (!this.commands) {
|
12
|
-
this.commands = []
|
11
|
+
this.commands = [];
|
13
12
|
for (let c in this.completion) {
|
14
|
-
this.commands.push(c)
|
13
|
+
this.commands.push(c);
|
15
14
|
}
|
16
|
-
this.commands.sort()
|
15
|
+
this.commands.sort();
|
17
16
|
}
|
18
|
-
return this.commands
|
17
|
+
return this.commands;
|
19
18
|
}
|
20
19
|
|
21
|
-
async subCommands(line =
|
22
|
-
const originalLine = line
|
23
|
-
const params = line.split(
|
24
|
-
const normalizedParams = params.map(e => e.split(
|
25
|
-
const command = params[0]
|
26
|
-
let c = this.completion[command]
|
20
|
+
async subCommands(line = "", forceCommand) {
|
21
|
+
const originalLine = line;
|
22
|
+
const params = line.split(" ");
|
23
|
+
const normalizedParams = params.map((e) => e.split("=")[0]);
|
24
|
+
const command = params[0];
|
25
|
+
let c = this.completion[command];
|
27
26
|
if (!c && forceCommand) {
|
28
|
-
c = this.completion[forceCommand]
|
29
|
-
line = forceCommand +
|
27
|
+
c = this.completion[forceCommand];
|
28
|
+
line = forceCommand + " " + line;
|
30
29
|
}
|
31
|
-
if (typeof c ===
|
32
|
-
let commands = []
|
33
|
-
let options = {}
|
30
|
+
if (typeof c === "object") {
|
31
|
+
let commands = [];
|
32
|
+
let options = {};
|
34
33
|
if (c._func) {
|
35
|
-
let commandLine = _.trim(line).split(
|
36
|
-
const definitions = c._self.optionDefinitions
|
37
|
-
options = FsUtils.parseCommandLine(definitions, commandLine)
|
34
|
+
let commandLine = _.trim(line).split(" ").slice(1).join(" ");
|
35
|
+
const definitions = c._self.optionDefinitions;
|
36
|
+
options = FsUtils.parseCommandLine(definitions, commandLine);
|
38
37
|
if (options._unknown) {
|
39
|
-
options = {}
|
38
|
+
options = {};
|
40
39
|
}
|
41
|
-
let optionsKeys = Object.keys(options)
|
42
|
-
let currentOption = optionsKeys.pop()
|
40
|
+
let optionsKeys = Object.keys(options);
|
41
|
+
let currentOption = optionsKeys.pop();
|
43
42
|
if (currentOption === undefined) {
|
44
|
-
let defaultOption = definitions.filter(
|
43
|
+
let defaultOption = definitions.filter(
|
44
|
+
(e) => e.defaultOption === true
|
45
|
+
)[0];
|
45
46
|
if (defaultOption) {
|
46
|
-
defaultOption = defaultOption.name
|
47
|
+
defaultOption = defaultOption.name;
|
47
48
|
}
|
48
|
-
currentOption = defaultOption
|
49
|
+
currentOption = defaultOption;
|
49
50
|
}
|
50
|
-
let files = await c._func(options, originalLine, currentOption)
|
51
|
-
commands = files
|
51
|
+
let files = await c._func(options, originalLine, currentOption);
|
52
|
+
commands = files;
|
52
53
|
} else {
|
53
|
-
commands = _.filter(
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
)
|
59
|
-
if (commands.length === 1 && commands[0] === '_self') {
|
60
|
-
commands = []
|
54
|
+
commands = _.filter(Object.keys(c), (o) => {
|
55
|
+
return !normalizedParams.includes(o);
|
56
|
+
});
|
57
|
+
if (commands.length === 1 && commands[0] === "_self") {
|
58
|
+
commands = [];
|
61
59
|
}
|
62
60
|
}
|
63
61
|
if (commands.length) {
|
64
|
-
let l = line
|
65
|
-
let lastSpace = l.lastIndexOf(
|
62
|
+
let l = line;
|
63
|
+
let lastSpace = l.lastIndexOf(" ");
|
66
64
|
for (;;) {
|
67
|
-
if (l[lastSpace - 1] !==
|
68
|
-
break
|
65
|
+
if (l[lastSpace - 1] !== "\\") {
|
66
|
+
break;
|
69
67
|
}
|
70
|
-
l = l.substring(0, lastSpace)
|
71
|
-
lastSpace = l.lastIndexOf(
|
68
|
+
l = l.substring(0, lastSpace);
|
69
|
+
lastSpace = l.lastIndexOf(" ");
|
72
70
|
}
|
73
71
|
let lasts = [
|
74
|
-
{n:
|
75
|
-
{n:
|
76
|
-
{n:
|
77
|
-
]
|
72
|
+
{ n: "/", l: line.lastIndexOf("/") },
|
73
|
+
{ n: "=", l: line.lastIndexOf("=") },
|
74
|
+
{ n: " ", l: lastSpace },
|
75
|
+
];
|
78
76
|
lasts.sort((a, b) => {
|
79
|
-
let A = a.l
|
80
|
-
let B = b.l
|
81
|
-
return A > B ? -1 : A < B ? 1 : 0
|
82
|
-
})
|
83
|
-
let v = lasts[0].l
|
84
|
-
let prefix = v !== -1 ? line.substring(0, v) + lasts[0].n : line
|
77
|
+
let A = a.l;
|
78
|
+
let B = b.l;
|
79
|
+
return A > B ? -1 : A < B ? 1 : 0;
|
80
|
+
});
|
81
|
+
let v = lasts[0].l;
|
82
|
+
let prefix = v !== -1 ? line.substring(0, v) + lasts[0].n : line;
|
85
83
|
if (c._self && !!c._self.prompt.commands[prefix]) {
|
86
|
-
prefix +=
|
84
|
+
prefix += " ";
|
87
85
|
}
|
88
|
-
commands = commands.map(
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
}`)
|
93
|
-
return commands
|
86
|
+
commands = commands.map(
|
87
|
+
(e) => `${prefix}${e ? e.replace(/ /g, "\\ ") : " "}`
|
88
|
+
);
|
89
|
+
return commands;
|
94
90
|
}
|
95
91
|
}
|
96
92
|
}
|
97
93
|
}
|
98
94
|
|
99
95
|
function Completion(completion, forceCommand) {
|
100
|
-
const instance = new _Completion(completion)
|
96
|
+
const instance = new _Completion(completion);
|
101
97
|
|
102
|
-
return async line => {
|
103
|
-
let subCommands = await instance.subCommands(line, forceCommand)
|
98
|
+
return async (line) => {
|
99
|
+
let subCommands = await instance.subCommands(line, forceCommand);
|
104
100
|
if (subCommands) {
|
105
|
-
return subCommands
|
101
|
+
return subCommands;
|
106
102
|
}
|
107
|
-
return instance.basicCommands()
|
108
|
-
}
|
103
|
+
return instance.basicCommands();
|
104
|
+
};
|
109
105
|
}
|
110
106
|
|
111
|
-
|
112
|
-
module.exports = Completion
|
107
|
+
module.exports = Completion;
|