secrez 1.1.1 → 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/README.md +414 -291
- package/bin/secrez.js +50 -47
- package/coverage.report +63 -305
- package/package.json +10 -12
- 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/src/commands/Find.js
CHANGED
@@ -1,210 +1,215 @@
|
|
1
|
-
const chalk = require(
|
2
|
-
const {Node} = require(
|
3
|
-
|
4
|
-
class Find extends require('../Command') {
|
1
|
+
const chalk = require("chalk");
|
2
|
+
const { Node } = require("@secrez/fs");
|
5
3
|
|
4
|
+
class Find extends require("../Command") {
|
6
5
|
setHelpAndCompletion() {
|
7
6
|
this.cliConfig.completion.find = {
|
8
7
|
_func: this.selfCompletion(this),
|
9
|
-
_self: this
|
10
|
-
}
|
11
|
-
this.cliConfig.completion.help.find = true
|
8
|
+
_self: this,
|
9
|
+
};
|
10
|
+
this.cliConfig.completion.help.find = true;
|
12
11
|
this.optionDefinitions = [
|
13
12
|
{
|
14
|
-
name:
|
15
|
-
alias:
|
16
|
-
type: Boolean
|
13
|
+
name: "help",
|
14
|
+
alias: "h",
|
15
|
+
type: Boolean,
|
17
16
|
},
|
18
17
|
{
|
19
|
-
name:
|
20
|
-
alias:
|
18
|
+
name: "keywords",
|
19
|
+
alias: "k",
|
21
20
|
defaultOption: true,
|
22
|
-
type: String
|
21
|
+
type: String,
|
23
22
|
},
|
24
23
|
{
|
25
|
-
name:
|
26
|
-
alias:
|
24
|
+
name: "content",
|
25
|
+
alias: "c",
|
27
26
|
type: Boolean,
|
28
|
-
hint:
|
27
|
+
hint: "Search also in contents",
|
29
28
|
},
|
30
29
|
{
|
31
|
-
name:
|
32
|
-
alias:
|
30
|
+
name: "all",
|
31
|
+
alias: "a",
|
33
32
|
type: Boolean,
|
34
|
-
hint:
|
33
|
+
hint: "Search all the versions",
|
35
34
|
},
|
36
35
|
{
|
37
|
-
name:
|
38
|
-
alias:
|
36
|
+
name: "sensitive",
|
37
|
+
alias: "s",
|
39
38
|
type: Boolean,
|
40
|
-
hint:
|
39
|
+
hint: "Make the search case-sensitive",
|
41
40
|
},
|
42
41
|
{
|
43
|
-
name:
|
44
|
-
alias:
|
42
|
+
name: "root",
|
43
|
+
alias: "r",
|
45
44
|
type: Boolean,
|
46
|
-
hint:
|
45
|
+
hint: "Search starting from the root",
|
47
46
|
},
|
48
47
|
{
|
49
|
-
name:
|
50
|
-
alias:
|
48
|
+
name: "global",
|
49
|
+
alias: "g",
|
51
50
|
type: Boolean,
|
52
|
-
hint:
|
51
|
+
hint: "Search in all the datasets",
|
53
52
|
},
|
54
53
|
{
|
55
|
-
name:
|
56
|
-
alias:
|
54
|
+
name: "trash-too",
|
55
|
+
alias: "t",
|
57
56
|
type: Boolean,
|
58
|
-
hint:
|
59
|
-
}
|
60
|
-
]
|
57
|
+
hint: "If global, search also in trash",
|
58
|
+
},
|
59
|
+
];
|
61
60
|
}
|
62
61
|
|
63
62
|
help() {
|
64
63
|
return {
|
65
64
|
description: [
|
66
|
-
|
67
|
-
|
65
|
+
"Find a secret.",
|
66
|
+
"By default the search is case-unsensitive.",
|
68
67
|
],
|
69
68
|
examples: [
|
70
|
-
[
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
[
|
75
|
-
|
76
|
-
|
69
|
+
[
|
70
|
+
"find Ethereum",
|
71
|
+
"Search for entries with ethereum or Ethereum in the name",
|
72
|
+
],
|
73
|
+
[
|
74
|
+
"find -c 0xAB",
|
75
|
+
'Search for files with the string "0xAB" in their content',
|
76
|
+
],
|
77
|
+
[
|
78
|
+
"find -sn Wallet",
|
79
|
+
'Search for names containings "Wallet" from the current dir',
|
80
|
+
],
|
81
|
+
[
|
82
|
+
"find Wallet -ag",
|
83
|
+
"Search scanning all the versions in all the datasets",
|
84
|
+
],
|
85
|
+
["find archive:allet", "Search allet in the archive dataset"],
|
86
|
+
],
|
87
|
+
};
|
77
88
|
}
|
78
89
|
|
79
90
|
async find(options) {
|
80
91
|
if (!options.name && options.keywords) {
|
81
|
-
options.name = options.keywords
|
92
|
+
options.name = options.keywords;
|
82
93
|
}
|
83
|
-
let splitted = options.name.split(
|
84
|
-
let withDataset = splitted.length > 1
|
94
|
+
let splitted = options.name.split(":");
|
95
|
+
let withDataset = splitted.length > 1;
|
85
96
|
if (options.global || (splitted[1] && !splitted[0])) {
|
86
97
|
if (withDataset) {
|
87
|
-
options.name = splitted[1]
|
98
|
+
options.name = splitted[1];
|
88
99
|
}
|
89
100
|
if (!options.name) {
|
90
|
-
throw new Error(
|
101
|
+
throw new Error("Keywords required");
|
91
102
|
}
|
92
|
-
let datasetInfo = await this.internalFs.getDatasetsInfo()
|
93
|
-
let results = []
|
103
|
+
let datasetInfo = await this.internalFs.getDatasetsInfo();
|
104
|
+
let results = [];
|
94
105
|
for (let dataset of datasetInfo) {
|
95
106
|
if (options.global && !options.trashToo && dataset.index === 1) {
|
96
|
-
continue
|
107
|
+
continue;
|
97
108
|
}
|
98
|
-
await this.internalFs.mountTree(dataset.index)
|
99
|
-
options.tree = this.internalFs.trees[dataset.index]
|
100
|
-
options.dataset = dataset.name
|
101
|
-
results = results.concat(await this._find(options))
|
109
|
+
await this.internalFs.mountTree(dataset.index);
|
110
|
+
options.tree = this.internalFs.trees[dataset.index];
|
111
|
+
options.dataset = dataset.name;
|
112
|
+
results = results.concat(await this._find(options));
|
102
113
|
}
|
103
|
-
return results
|
114
|
+
return results;
|
104
115
|
} else {
|
105
|
-
let data = await this.internalFs.getTreeIndexAndPath(options.name)
|
116
|
+
let data = await this.internalFs.getTreeIndexAndPath(options.name);
|
106
117
|
if (withDataset) {
|
107
|
-
options.dataset = data.name
|
118
|
+
options.dataset = data.name;
|
108
119
|
}
|
109
|
-
options.name = data.path
|
110
|
-
options.tree = data.tree
|
111
|
-
return await this._find(options)
|
120
|
+
options.name = data.path;
|
121
|
+
options.tree = data.tree;
|
122
|
+
return await this._find(options);
|
112
123
|
}
|
113
124
|
}
|
114
125
|
|
115
126
|
async _find(options) {
|
116
|
-
let start = options.tree[options.root ?
|
117
|
-
return (await start.find(options)).map(e => {
|
127
|
+
let start = options.tree[options.root ? "root" : "workingNode"];
|
128
|
+
return (await start.find(options)).map((e) => {
|
118
129
|
if (options.dataset) {
|
119
|
-
e[1] = options.dataset +
|
130
|
+
e[1] = options.dataset + ":" + e[1];
|
120
131
|
}
|
121
|
-
return e
|
122
|
-
})
|
132
|
+
return e;
|
133
|
+
});
|
123
134
|
}
|
124
135
|
|
125
136
|
formatResult(result, re) {
|
126
137
|
if (re.test(result)) {
|
127
|
-
return result.replace(re, a => chalk.bold(a))
|
138
|
+
return result.replace(re, (a) => chalk.bold(a));
|
128
139
|
} else {
|
129
|
-
return result
|
140
|
+
return result;
|
130
141
|
}
|
131
142
|
}
|
132
143
|
|
133
144
|
formatIndex(len, i) {
|
134
|
-
return
|
145
|
+
return " ".repeat(len.toString().length - i.toString().length) + i;
|
135
146
|
}
|
136
147
|
|
137
148
|
formatList(list, options) {
|
138
|
-
let re = Node.getFindRe(options)
|
139
|
-
let i = 0
|
149
|
+
let re = Node.getFindRe(options);
|
150
|
+
let i = 0;
|
140
151
|
const setCache = (i, e) => {
|
141
|
-
this.prompt.setCache(
|
142
|
-
}
|
143
|
-
return list.map(e => {
|
144
|
-
i
|
145
|
-
let k = this.formatIndex(list.length, i)
|
152
|
+
this.prompt.setCache("findResult", i, e);
|
153
|
+
};
|
154
|
+
return list.map((e) => {
|
155
|
+
i++;
|
156
|
+
let k = this.formatIndex(list.length, i);
|
146
157
|
if (options.all) {
|
147
|
-
let p = e[1].split(
|
148
|
-
let l = p.length
|
149
|
-
let c = p[l - 1] ? p[l - 1] : p[l - 2]
|
158
|
+
let p = e[1].split("/");
|
159
|
+
let l = p.length;
|
160
|
+
let c = p[l - 1] ? p[l - 1] : p[l - 2];
|
150
161
|
if (e[2] && e[2] !== c) {
|
151
|
-
e[2] = this.formatResult(e[2], re, options.name)
|
162
|
+
e[2] = this.formatResult(e[2], re, options.name);
|
152
163
|
} else {
|
153
|
-
e[2] = undefined
|
164
|
+
e[2] = undefined;
|
154
165
|
}
|
155
|
-
setCache(i, e)
|
166
|
+
setCache(i, e);
|
156
167
|
return [
|
157
168
|
k,
|
158
|
-
|
169
|
+
" ",
|
159
170
|
chalk.yellow(e[0]),
|
160
|
-
|
171
|
+
" ",
|
161
172
|
this.formatResult(e[1], re, options.name),
|
162
|
-
|
163
|
-
e[2]
|
164
|
-
].join(
|
165
|
-
|
173
|
+
" ",
|
174
|
+
e[2],
|
175
|
+
].join("");
|
166
176
|
} else {
|
167
|
-
setCache(i, e)
|
168
|
-
return [
|
169
|
-
k,
|
170
|
-
' ',
|
171
|
-
this.formatResult(e[1], re, options.name)
|
172
|
-
].join('')
|
177
|
+
setCache(i, e);
|
178
|
+
return [k, " ", this.formatResult(e[1], re, options.name)].join("");
|
173
179
|
}
|
174
|
-
})
|
180
|
+
});
|
175
181
|
}
|
176
182
|
|
177
183
|
async exec(options = {}) {
|
178
184
|
if (options.help) {
|
179
|
-
return this.showHelp()
|
185
|
+
return this.showHelp();
|
180
186
|
}
|
181
187
|
try {
|
182
|
-
this.validate(options)
|
183
|
-
options.name = options.keywords
|
188
|
+
this.validate(options);
|
189
|
+
options.name = options.keywords;
|
184
190
|
if (options.name) {
|
185
191
|
try {
|
186
|
-
this.lastResult = await this.find(options)
|
187
|
-
let list = this.formatList(this.lastResult, options)
|
192
|
+
this.lastResult = await this.find(options);
|
193
|
+
let list = this.formatList(this.lastResult, options);
|
188
194
|
if (list && list.length) {
|
189
|
-
this.Logger.grey(
|
190
|
-
|
195
|
+
this.Logger.grey(
|
196
|
+
`${list.length} result${list.length > 1 ? "s" : ""} found:`
|
197
|
+
);
|
198
|
+
for (let l of list) this.Logger.reset(l);
|
191
199
|
} else {
|
192
|
-
this.Logger.grey(
|
200
|
+
this.Logger.grey("No results.");
|
193
201
|
}
|
194
|
-
|
195
202
|
} catch (e) {
|
196
|
-
this.Logger.red(e.message)
|
203
|
+
this.Logger.red(e.message);
|
197
204
|
}
|
198
205
|
} else {
|
199
|
-
this.Logger.grey(
|
206
|
+
this.Logger.grey("Missing parameters");
|
200
207
|
}
|
201
208
|
} catch (e) {
|
202
|
-
this.Logger.red(e.message)
|
209
|
+
this.Logger.red(e.message);
|
203
210
|
}
|
204
|
-
await this.prompt.run()
|
211
|
+
await this.prompt.run();
|
205
212
|
}
|
206
213
|
}
|
207
214
|
|
208
|
-
module.exports = Find
|
209
|
-
|
210
|
-
|
215
|
+
module.exports = Find;
|
package/src/commands/Help.js
CHANGED
@@ -1,50 +1,47 @@
|
|
1
|
-
const HelpProto = require(
|
2
|
-
|
3
|
-
class Help extends require('../Command') {
|
1
|
+
const HelpProto = require("../utils/HelpProto");
|
4
2
|
|
3
|
+
class Help extends require("../Command") {
|
5
4
|
constructor(prompt) {
|
6
|
-
super(prompt)
|
5
|
+
super(prompt);
|
7
6
|
this.proto = new HelpProto({
|
8
7
|
prompt: this.prompt,
|
9
8
|
cliConfig: this.cliConfig,
|
10
9
|
helpDescription: this.helpDescription,
|
11
|
-
completions: this.completion
|
12
|
-
})
|
10
|
+
completions: this.completion,
|
11
|
+
});
|
13
12
|
}
|
14
13
|
|
15
14
|
setHelpAndCompletion() {
|
16
15
|
this.optionDefinitions = [
|
17
16
|
{
|
18
|
-
name:
|
19
|
-
alias:
|
17
|
+
name: "command",
|
18
|
+
alias: "c",
|
20
19
|
defaultOption: true,
|
21
|
-
type: String
|
22
|
-
}
|
23
|
-
]
|
20
|
+
type: String,
|
21
|
+
},
|
22
|
+
];
|
24
23
|
}
|
25
24
|
|
26
25
|
help() {
|
27
|
-
return this.proto.help()
|
26
|
+
return this.proto.help();
|
28
27
|
}
|
29
28
|
|
30
29
|
async exec(options = {}) {
|
31
|
-
let help
|
32
|
-
let command = options.command
|
30
|
+
let help;
|
31
|
+
let command = options.command;
|
33
32
|
if (command) {
|
34
33
|
if (this.prompt.commands[command]) {
|
35
|
-
help = this.prompt.commands[command].help()
|
34
|
+
help = this.prompt.commands[command].help();
|
36
35
|
} else {
|
37
|
-
this.Logger.red(
|
38
|
-
return await this.prompt.run()
|
36
|
+
this.Logger.red("Invalid command.");
|
37
|
+
return await this.prompt.run();
|
39
38
|
}
|
40
39
|
} else {
|
41
|
-
help = this.help()
|
40
|
+
help = this.help();
|
42
41
|
}
|
43
|
-
this.proto.format(help, command)
|
44
|
-
await this.prompt.run()
|
42
|
+
this.proto.format(help, command);
|
43
|
+
await this.prompt.run();
|
45
44
|
}
|
46
45
|
}
|
47
46
|
|
48
|
-
module.exports = Help
|
49
|
-
|
50
|
-
|
47
|
+
module.exports = Help;
|