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/src/commands/Tag.js
CHANGED
@@ -1,219 +1,240 @@
|
|
1
|
-
const _ = require(
|
2
|
-
const {chalk} = require(
|
3
|
-
const Case = require(
|
4
|
-
const {Node} = require(
|
5
|
-
const utils = require(
|
6
|
-
|
7
|
-
class Tag extends require('../Command') {
|
1
|
+
const _ = require("lodash");
|
2
|
+
const { chalk } = require("../utils/Logger");
|
3
|
+
const Case = require("case");
|
4
|
+
const { Node } = require("@secrez/fs");
|
5
|
+
const utils = require("@secrez/utils");
|
8
6
|
|
7
|
+
class Tag extends require("../Command") {
|
9
8
|
setHelpAndCompletion() {
|
10
9
|
this.cliConfig.completion.tag = {
|
11
10
|
_func: this.selfCompletion(this),
|
12
|
-
_self: this
|
13
|
-
}
|
14
|
-
this.cliConfig.completion.help.tag = true
|
11
|
+
_self: this,
|
12
|
+
};
|
13
|
+
this.cliConfig.completion.help.tag = true;
|
15
14
|
this.optionDefinitions = [
|
16
15
|
{
|
17
|
-
name:
|
18
|
-
alias:
|
19
|
-
type: Boolean
|
16
|
+
name: "help",
|
17
|
+
alias: "h",
|
18
|
+
type: Boolean,
|
20
19
|
},
|
21
20
|
{
|
22
|
-
name:
|
23
|
-
completionType:
|
24
|
-
alias:
|
21
|
+
name: "path",
|
22
|
+
completionType: "file",
|
23
|
+
alias: "p",
|
25
24
|
defaultOption: true,
|
26
|
-
type: String
|
25
|
+
type: String,
|
27
26
|
},
|
28
27
|
{
|
29
|
-
name:
|
30
|
-
alias:
|
31
|
-
type: Boolean
|
28
|
+
name: "list",
|
29
|
+
alias: "l",
|
30
|
+
type: Boolean,
|
32
31
|
},
|
33
32
|
{
|
34
|
-
name:
|
35
|
-
alias:
|
36
|
-
type: Boolean
|
33
|
+
name: "global",
|
34
|
+
alias: "g",
|
35
|
+
type: Boolean,
|
37
36
|
},
|
38
37
|
{
|
39
|
-
name:
|
40
|
-
alias:
|
38
|
+
name: "show",
|
39
|
+
alias: "s",
|
41
40
|
multiple: true,
|
42
|
-
type: String
|
41
|
+
type: String,
|
43
42
|
},
|
44
43
|
{
|
45
|
-
name:
|
46
|
-
alias:
|
44
|
+
name: "add",
|
45
|
+
alias: "a",
|
47
46
|
multiple: true,
|
48
|
-
type: String
|
47
|
+
type: String,
|
49
48
|
},
|
50
49
|
{
|
51
|
-
name:
|
52
|
-
alias:
|
53
|
-
type: Boolean
|
50
|
+
name: "remove",
|
51
|
+
alias: "r",
|
52
|
+
type: Boolean,
|
54
53
|
},
|
55
54
|
{
|
56
|
-
name:
|
57
|
-
type: String
|
55
|
+
name: "find",
|
56
|
+
type: String,
|
58
57
|
},
|
59
58
|
{
|
60
|
-
name:
|
61
|
-
type: Boolean
|
62
|
-
}
|
63
|
-
]
|
59
|
+
name: "content-too",
|
60
|
+
type: Boolean,
|
61
|
+
},
|
62
|
+
];
|
64
63
|
}
|
65
64
|
|
66
65
|
help() {
|
67
66
|
return {
|
68
|
-
description: [
|
69
|
-
'Tags a file and shows existent tags.'
|
70
|
-
],
|
67
|
+
description: ["Tags a file and shows existent tags."],
|
71
68
|
examples: [
|
72
|
-
|
73
|
-
[
|
74
|
-
[
|
75
|
-
[
|
76
|
-
[
|
77
|
-
[
|
78
|
-
]
|
79
|
-
}
|
69
|
+
"tag ethWallet.yml -a wallet,ethereum",
|
70
|
+
["tag ethWallet.yml -r ethereum", 'removes tag "ethereum"'],
|
71
|
+
["tag", "lists all tags in the current dataset"],
|
72
|
+
["tag -lg", "lists all tags in any dataset"],
|
73
|
+
["tag -s wallet", "lists all files tagged wallet"],
|
74
|
+
["tag -s email cloud", "lists all files tagged email and cloud"],
|
75
|
+
],
|
76
|
+
};
|
80
77
|
}
|
81
78
|
|
82
79
|
async tag(options, nodes) {
|
83
|
-
let result = []
|
80
|
+
let result = [];
|
84
81
|
if (!Object.keys(options).length) {
|
85
|
-
options.list = true
|
82
|
+
options.list = true;
|
86
83
|
}
|
87
84
|
if (options.list) {
|
88
85
|
if (options.global) {
|
89
|
-
let datasetInfo = await this.internalFs.getDatasetsInfo()
|
90
|
-
let result = {}
|
86
|
+
let datasetInfo = await this.internalFs.getDatasetsInfo();
|
87
|
+
let result = {};
|
91
88
|
for (let dataset of datasetInfo) {
|
92
|
-
await this.internalFs.mountTree(dataset.index)
|
93
|
-
let tags = this.internalFs.trees[dataset.index].listTags()
|
89
|
+
await this.internalFs.mountTree(dataset.index);
|
90
|
+
let tags = this.internalFs.trees[dataset.index].listTags();
|
94
91
|
if (tags.length) {
|
95
|
-
result[dataset.name] = tags
|
92
|
+
result[dataset.name] = tags;
|
96
93
|
}
|
97
94
|
}
|
98
|
-
return result
|
95
|
+
return result;
|
99
96
|
} else {
|
100
|
-
return this.internalFs.tree.listTags()
|
97
|
+
return this.internalFs.tree.listTags();
|
101
98
|
}
|
102
99
|
} else if (options.show) {
|
103
100
|
if (options.global) {
|
104
|
-
let datasetInfo = await this.internalFs.getDatasetsInfo()
|
105
|
-
result = []
|
101
|
+
let datasetInfo = await this.internalFs.getDatasetsInfo();
|
102
|
+
result = [];
|
106
103
|
for (let dataset of datasetInfo) {
|
107
|
-
await this.internalFs.mountTree(dataset.index)
|
108
|
-
let tags = this.internalFs.trees[dataset.index]
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
104
|
+
await this.internalFs.mountTree(dataset.index);
|
105
|
+
let tags = this.internalFs.trees[dataset.index]
|
106
|
+
.getNodesByTag(options.show)
|
107
|
+
.map((e) => {
|
108
|
+
e[0] = dataset.name + ":" + e[0];
|
109
|
+
return e;
|
110
|
+
});
|
111
|
+
result = result.concat(tags);
|
113
112
|
}
|
114
113
|
} else {
|
115
|
-
result = this.internalFs.tree.getNodesByTag(options.show)
|
114
|
+
result = this.internalFs.tree.getNodesByTag(options.show);
|
116
115
|
}
|
117
116
|
if (!result.length) {
|
118
|
-
throw new Error(
|
117
|
+
throw new Error("Tagged files not found");
|
119
118
|
}
|
120
|
-
return result
|
119
|
+
return result;
|
121
120
|
} else if (nodes || options.path || options.find) {
|
122
|
-
if (/:[/]*$/.test(options.path ||
|
123
|
-
throw new Error(
|
121
|
+
if (/:[/]*$/.test(options.path || "")) {
|
122
|
+
throw new Error("Datasets are not taggable");
|
124
123
|
}
|
125
124
|
if (!nodes) {
|
126
125
|
if (options.find) {
|
127
|
-
options.getNodes = true
|
128
|
-
options.name = options.find
|
129
|
-
options.content = options.contentToo
|
130
|
-
nodes = (await this.prompt.commands.find.find(options)).filter(n =>
|
126
|
+
options.getNodes = true;
|
127
|
+
options.name = options.find;
|
128
|
+
options.content = options.contentToo;
|
129
|
+
nodes = (await this.prompt.commands.find.find(options)).filter((n) =>
|
130
|
+
Node.isFile(n)
|
131
|
+
);
|
131
132
|
} else {
|
132
|
-
nodes = await this.internalFs.fileList(options.path, null, true)
|
133
|
+
nodes = await this.internalFs.fileList(options.path, null, true);
|
133
134
|
}
|
134
135
|
}
|
135
|
-
let isSaveEnabled = {}
|
136
|
+
let isSaveEnabled = {};
|
136
137
|
for (let node of nodes) {
|
137
|
-
let datasetIndex = Node.getRoot(node).datasetIndex
|
138
|
-
let tree = this.internalFs.trees[datasetIndex]
|
139
|
-
if (typeof isSaveEnabled[datasetIndex.toString()] ===
|
140
|
-
isSaveEnabled[datasetIndex.toString()] = tree.isSaveEnabled()
|
138
|
+
let datasetIndex = Node.getRoot(node).datasetIndex;
|
139
|
+
let tree = this.internalFs.trees[datasetIndex];
|
140
|
+
if (typeof isSaveEnabled[datasetIndex.toString()] === "undefined") {
|
141
|
+
isSaveEnabled[datasetIndex.toString()] = tree.isSaveEnabled();
|
141
142
|
if (tree.isSaveEnabled()) {
|
142
143
|
// it's called from another command, like Import
|
143
|
-
tree.disableSave()
|
144
|
+
tree.disableSave();
|
144
145
|
}
|
145
146
|
}
|
146
147
|
if (options.add) {
|
147
|
-
await tree.addTag(
|
148
|
-
|
149
|
-
|
148
|
+
await tree.addTag(
|
149
|
+
node,
|
150
|
+
options.add.map((e) => Case.snake(_.trim(e)))
|
151
|
+
);
|
152
|
+
let s = options.add.length > 1 ? "s" : "";
|
153
|
+
result = [`Tag${s} added`];
|
150
154
|
} else if (options.remove) {
|
151
|
-
await tree.removeTag(
|
152
|
-
|
153
|
-
|
155
|
+
await tree.removeTag(
|
156
|
+
node,
|
157
|
+
options.remove.map((e) => Case.snake(_.trim(e)))
|
158
|
+
);
|
159
|
+
let s = options.remove.length > 1 ? "s" : "";
|
160
|
+
result = [`Tag${s} removed`];
|
154
161
|
}
|
155
162
|
}
|
156
163
|
for (let datasetIndex in isSaveEnabled) {
|
157
164
|
if (isSaveEnabled[datasetIndex]) {
|
158
|
-
this.internalFs.trees[datasetIndex].enableSave()
|
159
|
-
await this.internalFs.trees[datasetIndex].saveTags()
|
165
|
+
this.internalFs.trees[datasetIndex].enableSave();
|
166
|
+
await this.internalFs.trees[datasetIndex].saveTags();
|
160
167
|
}
|
161
168
|
}
|
162
|
-
return result
|
169
|
+
return result;
|
163
170
|
}
|
164
|
-
throw new Error(
|
171
|
+
throw new Error("Insufficient parameters");
|
165
172
|
}
|
166
173
|
|
167
174
|
formatResult(result) {
|
168
|
-
const cols = utils.getCols()
|
175
|
+
const cols = utils.getCols();
|
169
176
|
|
170
|
-
let max = 0
|
171
|
-
let mak = 0
|
177
|
+
let max = 0;
|
178
|
+
let mak = 0;
|
172
179
|
for (let r of result) {
|
173
|
-
max = Math.max(max, r[0].length)
|
174
|
-
mak = Math.max(mak, r[1].length)
|
180
|
+
max = Math.max(max, r[0].length);
|
181
|
+
mak = Math.max(mak, r[1].length);
|
175
182
|
}
|
176
183
|
|
177
184
|
if (max + mak + 2 > cols) {
|
178
|
-
return result.map(e => e[0] +
|
185
|
+
return result.map((e) => e[0] + "\n" + chalk.cyan(e[1]));
|
179
186
|
} else {
|
180
|
-
return result.map(
|
187
|
+
return result.map(
|
188
|
+
(e) => e[0] + " ".repeat(max - e[0].length) + " " + chalk.cyan(e[1])
|
189
|
+
);
|
181
190
|
}
|
182
191
|
}
|
183
192
|
|
184
193
|
async exec(options = {}) {
|
185
194
|
if (options.help) {
|
186
|
-
return this.showHelp()
|
195
|
+
return this.showHelp();
|
187
196
|
}
|
188
197
|
try {
|
189
|
-
this.validate(options)
|
190
|
-
let result = await this.tag(options)
|
198
|
+
this.validate(options);
|
199
|
+
let result = await this.tag(options);
|
191
200
|
if (options.list) {
|
192
201
|
if (options.global) {
|
193
202
|
for (let name in result) {
|
194
|
-
this.Logger.grey(name)
|
195
|
-
this.Logger.cyan(
|
203
|
+
this.Logger.grey(name);
|
204
|
+
this.Logger.cyan(
|
205
|
+
this.prompt.commandPrompt.formatList(
|
206
|
+
result[name],
|
207
|
+
26,
|
208
|
+
true,
|
209
|
+
this.threeRedDots()
|
210
|
+
)
|
211
|
+
);
|
196
212
|
}
|
197
213
|
} else {
|
198
|
-
this.Logger.cyan(
|
214
|
+
this.Logger.cyan(
|
215
|
+
this.prompt.commandPrompt.formatList(
|
216
|
+
result,
|
217
|
+
26,
|
218
|
+
true,
|
219
|
+
this.threeRedDots()
|
220
|
+
)
|
221
|
+
);
|
199
222
|
}
|
200
223
|
} else if (options.show) {
|
201
224
|
for (let r of this.formatResult(result)) {
|
202
|
-
this.Logger.reset(r)
|
225
|
+
this.Logger.reset(r);
|
203
226
|
}
|
204
227
|
} else {
|
205
228
|
for (let r of result) {
|
206
|
-
this.Logger.grey(r)
|
229
|
+
this.Logger.grey(r);
|
207
230
|
}
|
208
231
|
}
|
209
232
|
} catch (e) {
|
210
233
|
// console.log(e)
|
211
|
-
this.Logger.red(e.message)
|
234
|
+
this.Logger.red(e.message);
|
212
235
|
}
|
213
|
-
await this.prompt.run()
|
236
|
+
await this.prompt.run();
|
214
237
|
}
|
215
238
|
}
|
216
239
|
|
217
|
-
module.exports = Tag
|
218
|
-
|
219
|
-
|
240
|
+
module.exports = Tag;
|