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.
Files changed (68) hide show
  1. package/README.md +503 -444
  2. package/bin/secrez.js +50 -47
  3. package/coverage.report +91 -85
  4. package/package.json +10 -12
  5. package/src/Command.js +78 -57
  6. package/src/PreCommand.js +75 -70
  7. package/src/Welcome.js +144 -134
  8. package/src/cliConfig.js +14 -14
  9. package/src/commands/Alias.js +123 -100
  10. package/src/commands/Bash.js +10 -12
  11. package/src/commands/Cat.js +117 -107
  12. package/src/commands/Cd.js +39 -42
  13. package/src/commands/Chat.js +75 -63
  14. package/src/commands/Conf.js +123 -99
  15. package/src/commands/Contacts.js +189 -171
  16. package/src/commands/Copy.js +132 -113
  17. package/src/commands/Courier.js +123 -105
  18. package/src/commands/Ds.js +88 -76
  19. package/src/commands/Edit.js +122 -103
  20. package/src/commands/Export.js +201 -116
  21. package/src/commands/Find.js +115 -110
  22. package/src/commands/Help.js +20 -23
  23. package/src/commands/Import.js +296 -225
  24. package/src/commands/Lcat.js +36 -39
  25. package/src/commands/Lcd.js +38 -39
  26. package/src/commands/Lls.js +58 -55
  27. package/src/commands/Lpwd.js +20 -24
  28. package/src/commands/Ls.js +107 -97
  29. package/src/commands/Mkdir.js +35 -38
  30. package/src/commands/Mv.js +147 -114
  31. package/src/commands/Paste.js +68 -65
  32. package/src/commands/Pwd.js +18 -23
  33. package/src/commands/Quit.js +22 -24
  34. package/src/commands/Rm.js +78 -70
  35. package/src/commands/Shell.js +31 -32
  36. package/src/commands/Ssh.js +77 -63
  37. package/src/commands/Tag.js +133 -112
  38. package/src/commands/Totp.js +166 -136
  39. package/src/commands/Touch.js +169 -56
  40. package/src/commands/Use.js +44 -41
  41. package/src/commands/Ver.js +16 -18
  42. package/src/commands/Whoami.js +34 -37
  43. package/src/commands/chat/Contacts.js +41 -44
  44. package/src/commands/chat/Help.js +20 -23
  45. package/src/commands/chat/Join.js +59 -55
  46. package/src/commands/chat/Leave.js +16 -22
  47. package/src/commands/chat/Quit.js +19 -24
  48. package/src/commands/chat/Send.js +58 -57
  49. package/src/commands/chat/Show.js +60 -51
  50. package/src/commands/chat/Whoami.js +18 -22
  51. package/src/commands/index.js +20 -22
  52. package/src/index.js +3 -3
  53. package/src/prompts/ChatPrompt.js +87 -82
  54. package/src/prompts/ChatPromptMock.js +11 -17
  55. package/src/prompts/CommandPrompt.js +146 -138
  56. package/src/prompts/Completion.js +64 -69
  57. package/src/prompts/MainPrompt.js +84 -77
  58. package/src/prompts/MainPromptMock.js +19 -30
  59. package/src/prompts/MultiEditorPrompt.js +21 -22
  60. package/src/prompts/SigintManager.js +21 -24
  61. package/src/utils/AliasManager.js +16 -18
  62. package/src/utils/ContactManager.js +15 -17
  63. package/src/utils/Fido2Client.js +59 -49
  64. package/src/utils/HelpProto.js +130 -117
  65. package/src/utils/Logger.js +48 -50
  66. package/.eslintignore +0 -0
  67. package/.eslintrc +0 -33
  68. package/.jshintrc +0 -3
@@ -1,222 +1,241 @@
1
- const path = require('path')
2
- const clipboardy = require('clipboardy')
3
- const {isYaml, yamlParse, TRUE, sleep, playMp3} = require('@secrez/utils')
4
- const {Node} = require('@secrez/fs')
5
-
6
- class Copy extends require('../Command') {
1
+ const path = require("path");
2
+ const clipboardy = require("clipboardy");
3
+ const { isYaml, yamlParse, TRUE, sleep, playMp3 } = require("@secrez/utils");
4
+ const { Node } = require("@secrez/fs");
7
5
 
6
+ class Copy extends require("../Command") {
8
7
  setHelpAndCompletion() {
9
8
  this.cliConfig.completion.copy = {
10
9
  _func: this.selfCompletion(this),
11
- _self: this
12
- }
13
- this.cliConfig.completion.help.copy = true
10
+ _self: this,
11
+ };
12
+ this.cliConfig.completion.help.copy = true;
14
13
  this.optionDefinitions = [
15
14
  {
16
- name: 'help',
17
- alias: 'h',
18
- type: Boolean
15
+ name: "help",
16
+ alias: "h",
17
+ type: Boolean,
19
18
  },
20
19
  {
21
- name: 'path',
22
- completionType: 'file',
23
- alias: 'p',
20
+ name: "path",
21
+ completionType: "file",
22
+ alias: "p",
24
23
  defaultOption: true,
25
- type: String
24
+ type: String,
26
25
  },
27
26
  {
28
- name: 'duration',
29
- alias: 'd',
27
+ name: "duration",
28
+ alias: "d",
30
29
  multiple: true,
31
- type: Number
30
+ type: Number,
32
31
  },
33
32
  {
34
- name: 'json',
35
- alias: 'j',
36
- type: Boolean
33
+ name: "json",
34
+ alias: "j",
35
+ type: Boolean,
37
36
  },
38
37
  {
39
- name: 'field',
40
- alias: 'f',
38
+ name: "field",
39
+ alias: "f",
41
40
  type: String,
42
- multiple: true
41
+ multiple: true,
43
42
  },
44
43
  {
45
- name: 'version',
46
- alias: 'v',
47
- type: String
44
+ name: "version",
45
+ alias: "v",
46
+ type: String,
48
47
  },
49
48
  {
50
- name: 'all-file',
51
- alias: 'a',
52
- type: Boolean
49
+ name: "all-file",
50
+ alias: "a",
51
+ type: Boolean,
53
52
  },
54
53
  {
55
- name: 'no-beep',
56
- type: Boolean
54
+ name: "no-beep",
55
+ type: Boolean,
57
56
  },
58
57
  {
59
- name: 'this-string',
60
- type: String
58
+ name: "this-string",
59
+ type: String,
61
60
  },
62
61
  {
63
- name: 'wait',
64
- type: Boolean
65
- }
66
- ]
62
+ name: "wait",
63
+ type: Boolean,
64
+ },
65
+ ];
67
66
  }
68
67
 
69
68
  help() {
70
69
  return {
71
- description: [
72
- 'Copy a text file to the clipboard.'
73
- ],
70
+ description: ["Copy a text file to the clipboard."],
74
71
  examples: [
75
- ['copy ethKeys', 'copies to the clipboard for 10 seconds (the default)'],
76
- ['copy google.yml -j', 'copies the google card as a JSON'],
77
- ['copy -ap google.yml', 'copies the google card as is'],
78
- ['copy google.yml', 'it will ask to chose the field to copy'],
79
- ['copy -f user --wait -p google.yml', 'it copies the user from google.yml and wait for the full duration'],
80
- ['copy myKey -v UY5d', 'copies version UY5d of myKey'],
81
- ['copy google.yml -d 10 -f password', 'copies the password in the google card and keeps it in the clipboard for 10 seconds; default is 5 seconds'],
82
- ['copy google.yml -f email password -d 3 2', 'copies email and keeps it in the clipboard for 3 seconds, after copies password and keeps it for 2 seconds; a bip will sound when a new data is copied'],
83
- ['copy google.yml -f user email password -d 3', 'copies user, email and password, one after the other, with an interval of 3 seconds'],
84
- ['copy google.yml -f email password --no-beep', 'copies without emitting a beep at clipboard change']
85
- ]
86
- }
72
+ [
73
+ "copy ethKeys",
74
+ "copies to the clipboard for 10 seconds (the default)",
75
+ ],
76
+ ["copy google.yml -j", "copies the google card as a JSON"],
77
+ ["copy -ap google.yml", "copies the google card as is"],
78
+ ["copy google.yml", "it will ask to chose the field to copy"],
79
+ [
80
+ "copy -f user --wait -p google.yml",
81
+ "it copies the user from google.yml and wait for the full duration",
82
+ ],
83
+ ["copy myKey -v UY5d", "copies version UY5d of myKey"],
84
+ [
85
+ "copy google.yml -d 10 -f password",
86
+ "copies the password in the google card and keeps it in the clipboard for 10 seconds; default is 5 seconds",
87
+ ],
88
+ [
89
+ "copy google.yml -f email password -d 3 2",
90
+ "copies email and keeps it in the clipboard for 3 seconds, after copies password and keeps it for 2 seconds; a bip will sound when a new data is copied",
91
+ ],
92
+ [
93
+ "copy google.yml -f user email password -d 3",
94
+ "copies user, email and password, one after the other, with an interval of 3 seconds",
95
+ ],
96
+ [
97
+ "copy google.yml -f email password --no-beep",
98
+ "copies without emitting a beep at clipboard change",
99
+ ],
100
+ ],
101
+ };
87
102
  }
88
103
 
89
104
  async copy(options = {}) {
90
105
  if (!this.counter) {
91
- this.counter = 0
106
+ this.counter = 0;
92
107
  }
93
108
  if (options.thisString) {
94
- this.counter++
109
+ this.counter++;
95
110
  if (options.wait) {
96
- await this.write([options.thisString], options, 0 + this.counter)
111
+ await this.write([options.thisString], options, 0 + this.counter);
97
112
  } else {
98
- this.write([options.thisString], options, 0 + this.counter)
113
+ this.write([options.thisString], options, 0 + this.counter);
99
114
  }
100
- return `"${options.thisString}"`
115
+ return `"${options.thisString}"`;
101
116
  }
102
- let cat = this.prompt.commands.cat
103
- let currentIndex = this.internalFs.treeIndex
104
- let data = await this.internalFs.getTreeIndexAndPath(options.path)
117
+ let cat = this.prompt.commands.cat;
118
+ let currentIndex = this.internalFs.treeIndex;
119
+ let data = await this.internalFs.getTreeIndexAndPath(options.path);
105
120
  /* istanbul ignore if */
106
121
  if (currentIndex !== data.index) {
107
- await this.internalFs.mountTree(data.index, true)
122
+ await this.internalFs.mountTree(data.index, true);
108
123
  }
109
- options.path = data.path
110
- let tree = data.tree
111
- let p = tree.getNormalizedPath(options.path)
112
- let file = tree.root.getChildFromPath(p)
124
+ options.path = data.path;
125
+ let tree = data.tree;
126
+ let p = tree.getNormalizedPath(options.path);
127
+ let file = tree.root.getChildFromPath(p);
113
128
  if (Node.isFile(file)) {
114
- let entry = (await cat.cat({
115
- path: p,
116
- version: options.version ? [options.version] : undefined,
117
- unformatted: true
118
- }))[0]
129
+ let entry = (
130
+ await cat.cat({
131
+ path: p,
132
+ version: options.version ? [options.version] : undefined,
133
+ unformatted: true,
134
+ })
135
+ )[0];
119
136
  if (Node.isText(entry)) {
120
- let {name, content} = entry
137
+ let { name, content } = entry;
121
138
  if (isYaml(p) && !options.allFile) {
122
- let parsed
139
+ let parsed;
123
140
  try {
124
- parsed = yamlParse(content)
141
+ parsed = yamlParse(content);
125
142
  } catch (e) {
126
- throw new Error('The yml is malformed. To copy the entire content, do not use the options -j or -f')
143
+ throw new Error(
144
+ "The yml is malformed. To copy the entire content, do not use the options -j or -f"
145
+ );
127
146
  }
128
147
  if (options.json) {
129
- content = JSON.stringify(parsed, null, 2)
148
+ content = JSON.stringify(parsed, null, 2);
130
149
  } else if (options.field) {
131
- content = []
150
+ content = [];
132
151
  for (let f of options.field) {
133
152
  if (parsed[f]) {
134
- content.push(parsed[f].toString())
153
+ content.push(parsed[f].toString());
135
154
  } else {
136
- throw new Error(`Field "${f}" not found in "${path.basename(p)}"`)
155
+ throw new Error(
156
+ `Field "${f}" not found in "${path.basename(p)}"`
157
+ );
137
158
  }
138
159
  }
139
160
  } else {
140
161
  /* istanbul ignore if */
141
162
  if (TRUE()) {
142
- options.choices = Object.keys(parsed)
143
- options.message = 'Select the field to copy'
144
- options.field = await this.useSelect(options)
163
+ options.choices = Object.keys(parsed);
164
+ options.message = "Select the field to copy";
165
+ options.field = await this.useSelect(options);
145
166
  if (!options.field) {
146
- throw new Error('Command canceled')
167
+ throw new Error("Command canceled");
147
168
  } else {
148
- content = parsed[options.field]
169
+ content = parsed[options.field];
149
170
  }
150
171
  }
151
172
  }
152
173
  }
153
174
  if (!Array.isArray(content)) {
154
- content = [content]
175
+ content = [content];
155
176
  }
156
- this.counter++
177
+ this.counter++;
157
178
  if (options.wait) {
158
- await this.write(content, options, 0 + this.counter)
179
+ await this.write(content, options, 0 + this.counter);
159
180
  } else {
160
- this.write(content, options, 0 + this.counter)
181
+ this.write(content, options, 0 + this.counter);
161
182
  }
162
- return name
183
+ return name;
163
184
  } else {
164
- throw new Error('You can copy to clipboard only text files.')
185
+ throw new Error("You can copy to clipboard only text files.");
165
186
  }
166
187
  } else {
167
- throw new Error('Cannot copy a folder')
188
+ throw new Error("Cannot copy a folder");
168
189
  }
169
190
  }
170
191
 
171
192
  async write(content, options, counter) {
172
193
  let duration = options.duration
173
- ? options.duration.map(e => 1000 * e)
174
- : [5000]
194
+ ? options.duration.map((e) => 1000 * e)
195
+ : [5000];
175
196
  if (!duration[1]) {
176
- duration[1] = duration[0]
197
+ duration[1] = duration[0];
177
198
  }
178
199
  for (let i = 0; i < content.length; i++) {
179
200
  if (this.counter === counter) {
180
- let wait = i ? duration[1] : duration[0]
181
- await this.writeAndWait(content[i], wait, counter)
201
+ let wait = i ? duration[1] : duration[0];
202
+ await this.writeAndWait(content[i], wait, counter);
182
203
  if (this.counter === counter && !options.noBeep) {
183
- await playMp3(path.resolve(__dirname, '../../sounds/ding.mp3'))
204
+ await playMp3(path.resolve(__dirname, "../../sounds/ding.mp3"));
184
205
  }
185
206
  }
186
207
  }
187
208
  }
188
209
 
189
210
  async writeAndWait(content, wait, counter) {
190
- let previousContent = await clipboardy.read()
211
+ let previousContent = await clipboardy.read();
191
212
  if (this.counter === counter) {
192
- await clipboardy.write(content)
193
- await sleep(wait)
213
+ await clipboardy.write(content);
214
+ await sleep(wait);
194
215
  if (this.counter === counter && content === (await clipboardy.read())) {
195
- await clipboardy.write(previousContent)
216
+ await clipboardy.write(previousContent);
196
217
  }
197
218
  }
198
219
  }
199
220
 
200
221
  async exec(options = {}) {
201
222
  if (options.help) {
202
- return this.showHelp()
223
+ return this.showHelp();
203
224
  }
204
225
  try {
205
226
  /* istanbul ignore if */
206
227
  if (!this.clipboardyVerified) {
207
- await clipboardy.read()
228
+ await clipboardy.read();
208
229
  }
209
- this.validate(options)
210
- let name = await this.copy(options)
211
- this.Logger.grey('Copied to clipboard:')
212
- this.Logger.reset(name)
230
+ this.validate(options);
231
+ let name = await this.copy(options);
232
+ this.Logger.grey("Copied to clipboard:");
233
+ this.Logger.reset(name);
213
234
  } catch (e) {
214
- this.Logger.red(e.message)
235
+ this.Logger.red(e.message);
215
236
  }
216
- await this.prompt.run()
237
+ await this.prompt.run();
217
238
  }
218
239
  }
219
240
 
220
- module.exports = Copy
221
-
222
-
241
+ module.exports = Copy;