secrez 1.1.0 → 1.1.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/LICENSE +21 -0
- package/README.md +414 -291
- package/bin/secrez.js +50 -47
- package/coverage.report +81 -0
- package/package.json +18 -20
- package/src/Command.js +78 -57
- package/src/PreCommand.js +74 -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 +153 -114
- 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
package/bin/secrez.js
CHANGED
@@ -1,86 +1,90 @@
|
|
1
1
|
#!/usr/bin/env node
|
2
2
|
|
3
|
-
const path = require(
|
4
|
-
const homedir = require(
|
5
|
-
const chalk = require(
|
6
|
-
const commandLineArgs = require(
|
3
|
+
const path = require("path");
|
4
|
+
const homedir = require("homedir");
|
5
|
+
const chalk = require("chalk");
|
6
|
+
const commandLineArgs = require("command-line-args");
|
7
7
|
|
8
|
-
const pkg = require(
|
8
|
+
const pkg = require("../package");
|
9
9
|
|
10
|
-
const MainPrompt = require(
|
11
|
-
const Logger = require(
|
10
|
+
const MainPrompt = require("../src/prompts/MainPrompt");
|
11
|
+
const Logger = require("../src/utils/Logger");
|
12
12
|
|
13
13
|
const optionDefinitions = [
|
14
14
|
{
|
15
|
-
name:
|
16
|
-
alias:
|
17
|
-
type: Boolean
|
15
|
+
name: "help",
|
16
|
+
alias: "h",
|
17
|
+
type: Boolean,
|
18
18
|
},
|
19
19
|
{
|
20
|
-
name:
|
21
|
-
alias:
|
22
|
-
type: Number
|
20
|
+
name: "iterations",
|
21
|
+
alias: "i",
|
22
|
+
type: Number,
|
23
23
|
},
|
24
24
|
{
|
25
|
-
name:
|
26
|
-
alias:
|
27
|
-
type: String
|
25
|
+
name: "container",
|
26
|
+
alias: "c",
|
27
|
+
type: String,
|
28
28
|
},
|
29
29
|
{
|
30
|
-
name:
|
31
|
-
alias:
|
32
|
-
type: Boolean
|
30
|
+
name: "save-iterations",
|
31
|
+
alias: "s",
|
32
|
+
type: Boolean,
|
33
33
|
},
|
34
34
|
{
|
35
|
-
name:
|
36
|
-
alias:
|
37
|
-
type: String
|
38
|
-
}
|
39
|
-
]
|
35
|
+
name: "localDir",
|
36
|
+
alias: "l",
|
37
|
+
type: String,
|
38
|
+
},
|
39
|
+
];
|
40
40
|
|
41
41
|
function error(message) {
|
42
42
|
if (!Array.isArray(message)) {
|
43
|
-
message = [message]
|
43
|
+
message = [message];
|
44
44
|
}
|
45
|
-
Logger.red(message[0])
|
45
|
+
Logger.red(message[0]);
|
46
46
|
if (message[1]) {
|
47
|
-
Logger.log(message[1])
|
47
|
+
Logger.log(message[1]);
|
48
48
|
}
|
49
49
|
/*eslint-disable-next-line*/
|
50
|
-
process.exit(1)
|
50
|
+
process.exit(1);
|
51
51
|
}
|
52
52
|
|
53
|
-
let options = {}
|
53
|
+
let options = {};
|
54
54
|
try {
|
55
55
|
options = commandLineArgs(optionDefinitions, {
|
56
|
-
camelCase: true
|
57
|
-
})
|
56
|
+
camelCase: true,
|
57
|
+
});
|
58
58
|
} catch (e) {
|
59
|
-
error(e.message)
|
59
|
+
error(e.message);
|
60
60
|
}
|
61
61
|
|
62
62
|
if (options.container) {
|
63
|
-
options.container = options.container.replace(/\/+$/,
|
63
|
+
options.container = options.container.replace(/\/+$/, "");
|
64
64
|
if (!path.isAbsolute(options.container)) {
|
65
65
|
if (/^~/.test(options.container)) {
|
66
|
-
options.container = path.join(homedir(), options.container.substring(2))
|
66
|
+
options.container = path.join(homedir(), options.container.substring(2));
|
67
67
|
} else {
|
68
|
-
error([
|
68
|
+
error([
|
69
|
+
"The path must be absolute or relative to home dir.",
|
69
70
|
`If that path is relative to the current directory, you can absolutize it running, for example:
|
70
71
|
secrez -c \`pwd\`/${options.container}
|
71
|
-
|
72
|
+
`,
|
73
|
+
]);
|
72
74
|
}
|
73
75
|
}
|
74
76
|
}
|
75
77
|
|
76
78
|
if (!options.localDir) {
|
77
|
-
options.localDir = homedir()
|
79
|
+
options.localDir = homedir();
|
78
80
|
}
|
79
81
|
|
80
|
-
Logger.log(
|
82
|
+
Logger.log("bold", chalk.grey(`Secrez v${pkg.version}`));
|
81
83
|
|
82
84
|
if (options.help) {
|
83
|
-
Logger.log(
|
85
|
+
Logger.log(
|
86
|
+
"reset",
|
87
|
+
`${pkg.description}
|
84
88
|
|
85
89
|
Options:
|
86
90
|
-h, --help This help.
|
@@ -103,15 +107,14 @@ Examples:
|
|
103
107
|
$ secrez -si 1213672
|
104
108
|
$ secrez -c ~/.secrez-archive
|
105
109
|
|
106
|
-
`
|
110
|
+
`
|
111
|
+
);
|
107
112
|
// eslint-disable-next-line no-process-exit
|
108
|
-
process.exit(0)
|
113
|
+
process.exit(0);
|
109
114
|
}
|
110
115
|
|
111
116
|
(async () => {
|
112
|
-
const prompt = new MainPrompt
|
113
|
-
await prompt.init(options)
|
114
|
-
prompt.run(options)
|
115
|
-
})()
|
116
|
-
|
117
|
-
|
117
|
+
const prompt = new MainPrompt();
|
118
|
+
await prompt.init(options);
|
119
|
+
prompt.run(options);
|
120
|
+
})();
|
package/coverage.report
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
|
2
|
+
> secrez@1.1.2 test /Users/francescosullo/Projects/Personal/secrez/packages/secrez
|
3
|
+
> cross-env NODE_ENV=test nyc --reporter=lcov --reporter=text mocha test/*.test.js test/**/*.test.js test/**/**/*.js --exit
|
4
|
+
|
5
|
+
|
6
|
+
|
7
|
+
#Touch
|
8
|
+
✓ should return the help
|
9
|
+
✓ should create a file
|
10
|
+
✓ should create a file with content
|
11
|
+
✓ should throw if trying to create a child of a file
|
12
|
+
✓ should throw if wrong parameters
|
13
|
+
✓ should create a file and generate a wallet (43ms)
|
14
|
+
New file "/folder2/file1" created.
|
15
|
+
✓ should generate 5 prefixed wallet
|
16
|
+
New file "/folder2/file1" created.
|
17
|
+
✓ should generate a wallet with mnemonic and 2 keys
|
18
|
+
|
19
|
+
|
20
|
+
8 passing (1s)
|
21
|
+
|
22
|
+
-----------------------|---------|----------|---------|---------|-----------------------------------
|
23
|
+
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
|
24
|
+
-----------------------|---------|----------|---------|---------|-----------------------------------
|
25
|
+
All files | 19.31 | 6.31 | 17.43 | 19.32 |
|
26
|
+
src | 33.03 | 15.07 | 25 | 33.33 |
|
27
|
+
Command.js | 37.29 | 23.4 | 38.46 | 37.93 | 29-35,40-97,108,119,122-130
|
28
|
+
PreCommand.js | 12.2 | 0 | 0 | 12.2 | 8-115
|
29
|
+
cliConfig.js | 100 | 100 | 100 | 100 |
|
30
|
+
src/commands | 15.44 | 2.67 | 19.63 | 15.5 |
|
31
|
+
Alias.js | 8.11 | 0 | 25 | 8.22 | 62-213
|
32
|
+
Bash.js | 62.5 | 0 | 33.33 | 62.5 | 11-19
|
33
|
+
Cat.js | 12.09 | 0 | 14.29 | 12.09 | 61-220
|
34
|
+
Cd.js | 17.86 | 0 | 25 | 17.86 | 28-73
|
35
|
+
Chat.js | 19.51 | 0 | 16.67 | 19.51 | 23-144
|
36
|
+
Conf.js | 8.96 | 0 | 12.5 | 8.96 | 67-499
|
37
|
+
Contacts.js | 6 | 0 | 7.14 | 6.04 | 55-352
|
38
|
+
Copy.js | 10.26 | 0 | 14.29 | 10.39 | 69-237
|
39
|
+
Courier.js | 6.25 | 0 | 7.14 | 6.38 | 20-221
|
40
|
+
Ds.js | 5.97 | 0 | 16.67 | 6.06 | 39-160
|
41
|
+
Edit.js | 12.35 | 0 | 20 | 12.35 | 61-214
|
42
|
+
Export.js | 12.99 | 0 | 16.67 | 12.99 | 68-232
|
43
|
+
Find.js | 7.69 | 0 | 8.33 | 7.89 | 63-211
|
44
|
+
Help.js | 73.33 | 40 | 75 | 73.33 | 26,36-40
|
45
|
+
Import.js | 6.31 | 0 | 9.09 | 6.37 | 87-496
|
46
|
+
Lcat.js | 30 | 0 | 25 | 30 | 35-65
|
47
|
+
Lcd.js | 17.39 | 0 | 25 | 17.39 | 30-72
|
48
|
+
Lls.js | 22.73 | 0 | 25 | 22.73 | 49-99
|
49
|
+
Lpwd.js | 30.77 | 0 | 25 | 30.77 | 15-38
|
50
|
+
Ls.js | 5.8 | 0 | 10 | 6.15 | 46-183
|
51
|
+
Mkdir.js | 22.73 | 0 | 25 | 22.73 | 27-61
|
52
|
+
Mv.js | 6.52 | 0 | 16.67 | 6.67 | 46-240
|
53
|
+
Paste.js | 14.89 | 0 | 25 | 14.89 | 40-131
|
54
|
+
Pwd.js | 30.77 | 0 | 25 | 30.77 | 15-35
|
55
|
+
Quit.js | 50 | 0 | 33.33 | 50 | 19-40
|
56
|
+
Rm.js | 16 | 0 | 16.67 | 16.33 | 36-137
|
57
|
+
Shell.js | 29.41 | 0 | 25 | 29.41 | 25-57
|
58
|
+
Ssh.js | 22.22 | 0 | 20 | 22.22 | 49-120
|
59
|
+
Tag.js | 8.82 | 0 | 9.09 | 8.91 | 66-236
|
60
|
+
Totp.js | 15.29 | 0 | 10 | 15.29 | 75-288
|
61
|
+
Touch.js | 95.92 | 81.48 | 100 | 95.83 | 152,202
|
62
|
+
Use.js | 12.9 | 0 | 25 | 12.9 | 30-85
|
63
|
+
Ver.js | 50 | 0 | 33.33 | 50 | 17-28
|
64
|
+
Whoami.js | 24.14 | 0 | 20 | 24.14 | 22-66
|
65
|
+
chat.js | 19.51 | 0 | 16.67 | 19.51 | 23-144
|
66
|
+
index.js | 87.5 | 50 | 100 | 86.96 | 15,22,31
|
67
|
+
src/prompts | 14 | 0 | 4.76 | 14.12 |
|
68
|
+
ChatPrompt.js | 6.17 | 0 | 0 | 6.17 | 8-163
|
69
|
+
ChatPromptMock.js | 42.86 | 100 | 0 | 42.86 | 6-14
|
70
|
+
CommandPrompt.js | 10.42 | 0 | 0 | 10.56 | 24-296
|
71
|
+
Completion.js | 4.41 | 0 | 0 | 4.48 | 6-103
|
72
|
+
MainPromptMock.js | 100 | 100 | 33.33 | 100 |
|
73
|
+
MultiEditorPrompt.js | 25 | 0 | 0 | 25 | 7-36
|
74
|
+
SigintManager.js | 25 | 0 | 20 | 25 | 10-36
|
75
|
+
src/utils | 51.63 | 40.63 | 20.83 | 51.03 |
|
76
|
+
AliasManager.js | 5.88 | 0 | 0 | 5.88 | 3-48
|
77
|
+
ContactManager.js | 7.14 | 0 | 0 | 7.14 | 3-44
|
78
|
+
Fido2Client.js | 9.62 | 0 | 0 | 9.62 | 8-108
|
79
|
+
HelpProto.js | 78.99 | 62.32 | 83.33 | 78.63 | 11-39,49,153-154,171-176,195
|
80
|
+
Logger.js | 59.09 | 56.25 | 26.32 | 58.14 | ...29,37-57,65-69,74,84,88,93,105
|
81
|
+
-----------------------|---------|----------|---------|---------|-----------------------------------
|
package/package.json
CHANGED
@@ -1,25 +1,18 @@
|
|
1
1
|
{
|
2
2
|
"name": "secrez",
|
3
|
-
"version": "1.1.
|
3
|
+
"version": "1.1.2",
|
4
4
|
"license": "MIT",
|
5
|
-
"scripts": {
|
6
|
-
"dev": "cross-env NODE_ENV=dev bin/secrez.js -c `pwd`/tmp/secrez-dev -i 1e3 -l `pwd`/tmp",
|
7
|
-
"lint": "eslint -c .eslintrc 'src/**/*.js' 'bin/*.js' 'test/*.test.js' 'test/**/*.js' 'test/**/**/*.js'",
|
8
|
-
"test-only": "cross-env NODE_ENV=test ./node_modules/.bin/mocha test/*.test.js test/**/*.test.js test/**/**/*.js --exit",
|
9
|
-
"test": "cross-env NODE_ENV=test nyc --reporter=lcov --reporter=text ./node_modules/.bin/_mocha test/*.test.js test/**/*.test.js test/**/**/*.js --exit",
|
10
|
-
"posttest": "nyc check-coverage --statements 65 --branches 50 --functions 65 --lines 65",
|
11
|
-
"build-helpers": "cd test/helpers/os && ./build.sh"
|
12
|
-
},
|
13
5
|
"nyc": {
|
14
6
|
"include": "src",
|
15
7
|
"exclude": []
|
16
8
|
},
|
17
9
|
"dependencies": {
|
18
|
-
"@secrez/core": "
|
19
|
-
"@secrez/crypto": "
|
20
|
-
"@secrez/
|
21
|
-
"@secrez/
|
22
|
-
"@secrez/
|
10
|
+
"@secrez/core": "~1.0.4",
|
11
|
+
"@secrez/crypto": "~1.0.3",
|
12
|
+
"@secrez/eth": "~0.0.2",
|
13
|
+
"@secrez/fs": "~1.0.4",
|
14
|
+
"@secrez/hub": "~0.2.2",
|
15
|
+
"@secrez/utils": "~1.0.3",
|
23
16
|
"case": "^1.6.3",
|
24
17
|
"chalk": "^3.0.0",
|
25
18
|
"clipboardy": "^2.3.0",
|
@@ -37,13 +30,11 @@
|
|
37
30
|
"tiny-cli-editor": "^0.1.1"
|
38
31
|
},
|
39
32
|
"devDependencies": {
|
40
|
-
"@secrez/courier": "
|
41
|
-
"@secrez/test-helpers": "
|
33
|
+
"@secrez/courier": "~0.2.3",
|
34
|
+
"@secrez/test-helpers": "~2.0.0",
|
42
35
|
"chai": "^4.2.0",
|
43
36
|
"chalk": "^3.0.0",
|
44
37
|
"cross-env": "^7.0.2",
|
45
|
-
"eslint": "^6.8.0",
|
46
|
-
"eslint-plugin-node": "^11.0.0",
|
47
38
|
"mocha": "^7.1.1",
|
48
39
|
"nyc": "^15.1.0",
|
49
40
|
"test-console": "^1.1.0"
|
@@ -69,5 +60,12 @@
|
|
69
60
|
"engines": {
|
70
61
|
"node": ">=10.0.0"
|
71
62
|
},
|
72
|
-
"gitHead": "42cbc519dd2802a1e03c6203bb724c726c2bfb79"
|
73
|
-
|
63
|
+
"gitHead": "42cbc519dd2802a1e03c6203bb724c726c2bfb79",
|
64
|
+
"scripts": {
|
65
|
+
"dev": "cross-env NODE_ENV=dev bin/secrez.js -c `pwd`/tmp/secrez-dev -i 1e3 -l `pwd`/tmp",
|
66
|
+
"test-only": "cross-env NODE_ENV=test ./node_modules/.bin/mocha test/*.test.js test/**/*.test.js test/**/**/*.js --exit",
|
67
|
+
"test": "cross-env NODE_ENV=test nyc --reporter=lcov --reporter=text mocha test/*.test.js test/**/*.test.js test/**/**/*.js --exit",
|
68
|
+
"posttest": "nyc check-coverage --statements 65 --branches 50 --functions 65 --lines 65",
|
69
|
+
"build-helpers": "cd test/helpers/os && ./build.sh"
|
70
|
+
}
|
71
|
+
}
|
package/src/Command.js
CHANGED
@@ -1,115 +1,136 @@
|
|
1
|
-
const {chalk} = require(
|
2
|
-
const Logger = require(
|
3
|
-
const cliConfig = require(
|
4
|
-
const PreCommand = require(
|
1
|
+
const { chalk } = require("./utils/Logger");
|
2
|
+
const Logger = require("./utils/Logger");
|
3
|
+
const cliConfig = require("./cliConfig");
|
4
|
+
const PreCommand = require("./PreCommand");
|
5
5
|
|
6
6
|
class Command extends PreCommand {
|
7
|
-
|
8
7
|
constructor(prompt) {
|
9
|
-
super()
|
10
|
-
this.prompt = prompt
|
11
|
-
this.secrez = prompt.secrez
|
12
|
-
this.optionDefinitions = []
|
13
|
-
this.cliConfig = cliConfig
|
14
|
-
this.internalFs = prompt.internalFs
|
15
|
-
this.externalFs = prompt.externalFs
|
16
|
-
this.Logger = Logger
|
17
|
-
this.chalk = chalk
|
8
|
+
super();
|
9
|
+
this.prompt = prompt;
|
10
|
+
this.secrez = prompt.secrez;
|
11
|
+
this.optionDefinitions = [];
|
12
|
+
this.cliConfig = cliConfig;
|
13
|
+
this.internalFs = prompt.internalFs;
|
14
|
+
this.externalFs = prompt.externalFs;
|
15
|
+
this.Logger = Logger;
|
16
|
+
this.chalk = chalk;
|
18
17
|
}
|
19
18
|
|
20
|
-
help() {
|
21
|
-
}
|
19
|
+
help() {}
|
22
20
|
|
23
21
|
showHelp() {
|
24
|
-
let command = this.constructor.name.toLowerCase()
|
25
|
-
this.prompt.commands.help.exec({command})
|
22
|
+
let command = this.constructor.name.toLowerCase();
|
23
|
+
this.prompt.commands.help.exec({ command });
|
26
24
|
}
|
27
25
|
|
28
|
-
setHelpAndCompletion() {
|
29
|
-
}
|
26
|
+
setHelpAndCompletion() {}
|
30
27
|
|
31
28
|
getCompletionType(option) {
|
32
29
|
if (!this.completionTypes) {
|
33
|
-
this.completionTypes = {}
|
30
|
+
this.completionTypes = {};
|
34
31
|
for (let item of this.optionDefinitions) {
|
35
|
-
this.completionTypes[item.name] = item.completionType
|
32
|
+
this.completionTypes[item.name] = item.completionType;
|
36
33
|
}
|
37
34
|
}
|
38
|
-
return this.completionTypes[option]
|
35
|
+
return this.completionTypes[option];
|
39
36
|
}
|
40
37
|
|
41
38
|
selfCompletion(self, extraOptions = {}) {
|
42
39
|
return async (options, originalLine, currentOption) => {
|
43
|
-
options = Object.assign(options, extraOptions)
|
44
|
-
options.forAutoComplete = true
|
45
|
-
let completionType = this.getCompletionType(currentOption)
|
40
|
+
options = Object.assign(options, extraOptions);
|
41
|
+
options.forAutoComplete = true;
|
42
|
+
let completionType = this.getCompletionType(currentOption);
|
46
43
|
/* istanbul ignore if */
|
47
44
|
if (this.customCompletion) {
|
48
|
-
let extra = await this.customCompletion(
|
45
|
+
let extra = await this.customCompletion(
|
46
|
+
options,
|
47
|
+
originalLine,
|
48
|
+
currentOption
|
49
|
+
);
|
49
50
|
if (extra) {
|
50
|
-
return extra
|
51
|
+
return extra;
|
51
52
|
}
|
52
53
|
}
|
53
|
-
if (completionType ===
|
54
|
-
let datasetsInfo = await this.internalFs.getDatasetsInfo()
|
55
|
-
options.forAutoComplete = true
|
54
|
+
if (completionType === "dataset") {
|
55
|
+
let datasetsInfo = await this.internalFs.getDatasetsInfo();
|
56
|
+
options.forAutoComplete = true;
|
56
57
|
if (options.dataset) {
|
57
|
-
return datasetsInfo
|
58
|
+
return datasetsInfo
|
59
|
+
.map((e) => e.name)
|
60
|
+
.filter((e) => RegExp("^" + options.dataset).test(e));
|
58
61
|
} else {
|
59
|
-
return datasetsInfo.map(e => e.name)
|
62
|
+
return datasetsInfo.map((e) => e.name);
|
60
63
|
}
|
61
64
|
}
|
62
|
-
if (
|
63
|
-
|
65
|
+
if (
|
66
|
+
(process.env.NODE_ENV === "test" && currentOption === "path") ||
|
67
|
+
completionType === "file"
|
68
|
+
) {
|
64
69
|
if (options[currentOption] === null) {
|
65
|
-
delete options[currentOption]
|
70
|
+
delete options[currentOption];
|
66
71
|
}
|
67
|
-
if (currentOption !==
|
68
|
-
options.path = options[currentOption]
|
72
|
+
if (currentOption !== "path") {
|
73
|
+
options.path = options[currentOption];
|
69
74
|
}
|
70
|
-
if (
|
71
|
-
|
75
|
+
if (
|
76
|
+
self.prompt.cache &&
|
77
|
+
self.prompt.cache.findResult &&
|
78
|
+
/^(#|£)\d+$/.test(options.path)
|
79
|
+
) {
|
80
|
+
return [
|
81
|
+
options.path +
|
82
|
+
self.prompt.cache.findResult[
|
83
|
+
options.path.replace(/^(#|£)/, "")
|
84
|
+
][1] || undefined,
|
85
|
+
];
|
72
86
|
}
|
73
|
-
return await self.prompt[
|
87
|
+
return await self.prompt[
|
88
|
+
extraOptions.external ? "externalFs" : "internalFs"
|
89
|
+
].getFileList(options, true);
|
74
90
|
} else {
|
75
|
-
return []
|
91
|
+
return [];
|
76
92
|
}
|
77
|
-
}
|
93
|
+
};
|
78
94
|
}
|
79
95
|
|
80
96
|
threeRedDots(large) {
|
81
|
-
return chalk.cyan(large ?
|
97
|
+
return chalk.cyan(large ? "•••" : "···");
|
82
98
|
}
|
83
99
|
|
84
100
|
checkPath(options) {
|
85
|
-
if (typeof options.path !==
|
86
|
-
throw new Error(
|
101
|
+
if (typeof options.path !== "string" || !options.path) {
|
102
|
+
throw new Error("A valid path is required");
|
87
103
|
}
|
88
104
|
}
|
89
105
|
|
90
106
|
validate(options, mandatoryOptions) {
|
91
107
|
if (options._unknown) {
|
92
|
-
throw new Error(
|
108
|
+
throw new Error(
|
109
|
+
`Unknown option: ${options._unknown} ` +
|
110
|
+
chalk.grey(
|
111
|
+
`(run "${this.constructor.name.toLowerCase()} -h" for help)`
|
112
|
+
)
|
113
|
+
);
|
93
114
|
}
|
94
|
-
if (
|
95
|
-
options.path
|
115
|
+
if (
|
116
|
+
options.path &&
|
117
|
+
(/^(#|£)\d+\//.test(options.path) || /^(#|£)\d+\w+:\//.test(options.path))
|
118
|
+
) {
|
119
|
+
options.path = options.path.replace(/^(#|£)\d+/, "");
|
96
120
|
}
|
97
121
|
if (mandatoryOptions) {
|
98
|
-
let err =
|
99
|
-
let prefix =
|
122
|
+
let err = "";
|
123
|
+
let prefix = "Missing options: ";
|
100
124
|
for (let o in mandatoryOptions) {
|
101
125
|
if (!options[o]) {
|
102
|
-
err += (err ?
|
126
|
+
err += (err ? ", " : "") + o;
|
103
127
|
}
|
104
128
|
}
|
105
129
|
if (err) {
|
106
|
-
throw new Error(prefix + err)
|
130
|
+
throw new Error(prefix + err);
|
107
131
|
}
|
108
132
|
}
|
109
133
|
}
|
110
|
-
|
111
134
|
}
|
112
135
|
|
113
|
-
module.exports = Command
|
114
|
-
|
115
|
-
|
136
|
+
module.exports = Command;
|