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.
Files changed (69) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +414 -291
  3. package/bin/secrez.js +50 -47
  4. package/coverage.report +81 -0
  5. package/package.json +18 -20
  6. package/src/Command.js +78 -57
  7. package/src/PreCommand.js +74 -70
  8. package/src/Welcome.js +144 -134
  9. package/src/cliConfig.js +14 -14
  10. package/src/commands/Alias.js +123 -100
  11. package/src/commands/Bash.js +10 -12
  12. package/src/commands/Cat.js +117 -107
  13. package/src/commands/Cd.js +39 -42
  14. package/src/commands/Chat.js +75 -63
  15. package/src/commands/Conf.js +123 -99
  16. package/src/commands/Contacts.js +189 -171
  17. package/src/commands/Copy.js +132 -113
  18. package/src/commands/Courier.js +123 -105
  19. package/src/commands/Ds.js +88 -76
  20. package/src/commands/Edit.js +122 -103
  21. package/src/commands/Export.js +153 -114
  22. package/src/commands/Find.js +115 -110
  23. package/src/commands/Help.js +20 -23
  24. package/src/commands/Import.js +296 -225
  25. package/src/commands/Lcat.js +36 -39
  26. package/src/commands/Lcd.js +38 -39
  27. package/src/commands/Lls.js +58 -55
  28. package/src/commands/Lpwd.js +20 -24
  29. package/src/commands/Ls.js +107 -97
  30. package/src/commands/Mkdir.js +35 -38
  31. package/src/commands/Mv.js +147 -114
  32. package/src/commands/Paste.js +68 -65
  33. package/src/commands/Pwd.js +18 -23
  34. package/src/commands/Quit.js +22 -24
  35. package/src/commands/Rm.js +78 -70
  36. package/src/commands/Shell.js +31 -32
  37. package/src/commands/Ssh.js +77 -63
  38. package/src/commands/Tag.js +133 -112
  39. package/src/commands/Totp.js +166 -136
  40. package/src/commands/Touch.js +169 -56
  41. package/src/commands/Use.js +44 -41
  42. package/src/commands/Ver.js +16 -18
  43. package/src/commands/Whoami.js +34 -37
  44. package/src/commands/chat/Contacts.js +41 -44
  45. package/src/commands/chat/Help.js +20 -23
  46. package/src/commands/chat/Join.js +59 -55
  47. package/src/commands/chat/Leave.js +16 -22
  48. package/src/commands/chat/Quit.js +19 -24
  49. package/src/commands/chat/Send.js +58 -57
  50. package/src/commands/chat/Show.js +60 -51
  51. package/src/commands/chat/Whoami.js +18 -22
  52. package/src/commands/index.js +20 -22
  53. package/src/index.js +3 -3
  54. package/src/prompts/ChatPrompt.js +87 -82
  55. package/src/prompts/ChatPromptMock.js +11 -17
  56. package/src/prompts/CommandPrompt.js +146 -138
  57. package/src/prompts/Completion.js +64 -69
  58. package/src/prompts/MainPrompt.js +84 -77
  59. package/src/prompts/MainPromptMock.js +19 -30
  60. package/src/prompts/MultiEditorPrompt.js +21 -22
  61. package/src/prompts/SigintManager.js +21 -24
  62. package/src/utils/AliasManager.js +16 -18
  63. package/src/utils/ContactManager.js +15 -17
  64. package/src/utils/Fido2Client.js +59 -49
  65. package/src/utils/HelpProto.js +130 -117
  66. package/src/utils/Logger.js +48 -50
  67. package/.eslintignore +0 -0
  68. package/.eslintrc +0 -33
  69. package/.jshintrc +0 -3
@@ -1,194 +1,217 @@
1
- const chalk = require('chalk')
2
- const AliasManager = require('../utils/AliasManager')
3
-
4
- class Alias extends require('../Command') {
1
+ const chalk = require("chalk");
2
+ const AliasManager = require("../utils/AliasManager");
5
3
 
4
+ class Alias extends require("../Command") {
6
5
  setHelpAndCompletion() {
7
6
  this.cliConfig.completion.alias = {
8
7
  _func: this.selfCompletion(this),
9
- _self: this
10
- }
11
- this.cliConfig.completion.help.alias = true
8
+ _self: this,
9
+ };
10
+ this.cliConfig.completion.help.alias = true;
12
11
  this.optionDefinitions = [
13
12
  {
14
- name: 'help',
15
- alias: 'h',
16
- type: Boolean
13
+ name: "help",
14
+ alias: "h",
15
+ type: Boolean,
17
16
  },
18
17
  {
19
- name: 'name',
20
- alias: 'n',
18
+ name: "name",
19
+ alias: "n",
21
20
  defaultOption: true,
22
- type: String
21
+ type: String,
23
22
  },
24
23
  {
25
- name: 'command-line',
26
- alias: 'c',
27
- type: String
24
+ name: "command-line",
25
+ alias: "c",
26
+ type: String,
28
27
  },
29
28
  {
30
- name: 'list',
31
- alias: 'l',
32
- type: Boolean
29
+ name: "list",
30
+ alias: "l",
31
+ type: Boolean,
33
32
  },
34
33
  {
35
- name: 'filter',
36
- alias: 'f',
37
- type: String
34
+ name: "filter",
35
+ alias: "f",
36
+ type: String,
38
37
  },
39
38
  {
40
- name: 'previous-command',
41
- alias: 'p',
42
- type: Boolean
39
+ name: "previous-command",
40
+ alias: "p",
41
+ type: Boolean,
43
42
  },
44
43
  {
45
- name: 'rename',
46
- alias: 'r',
44
+ name: "rename",
45
+ alias: "r",
47
46
  type: String,
48
- multiple: true
47
+ multiple: true,
49
48
  },
50
49
  {
51
- name: 'delete',
52
- alias: 'd',
53
- type: String
50
+ name: "delete",
51
+ alias: "d",
52
+ type: String,
54
53
  },
55
54
  {
56
- name: 'skip-confirm',
57
- type: Boolean
58
- }
59
- ]
55
+ name: "skip-confirm",
56
+ type: Boolean,
57
+ },
58
+ ];
60
59
  }
61
60
 
62
61
  help() {
63
62
  return {
64
- description: ['Create aliases of other commands.',
65
- 'Aliases\' name are case sensitive. They can be any combination of letters, numerals, underscores and hiphens',
66
- 'If an alias conflicts with a command, you can disambiguate it prefixing it with a slash ("/"). Like calling the alias "mv" as "/mv".'],
63
+ description: [
64
+ "Create aliases of other commands.",
65
+ "Aliases' name are case sensitive. They can be any combination of letters, numerals, underscores and hiphens",
66
+ 'If an alias conflicts with a command, you can disambiguate it prefixing it with a slash ("/"). Like calling the alias "mv" as "/mv".',
67
+ ],
67
68
  examples: [
68
- ['alias f -c "copy facebook.yml -f email password"', 'creates an alias "f" that executes "copy facebook.yml -f email password"'],
69
- ['alias g --previous-command', 'creates the alias "g" using the previous command; this allows you to test something, and when ready generate an alias for it'],
70
- ['alias C -c "copy coinbase.yml -f email password -d 4 && totp coinbase.yml"', 'creates an alias "C" that copies email and password, and when the comand is executed, runs "totp coinbase.yml" '],
71
- ['alias m -c "copy $1 -f email password -d4 2 && totp $1"', 'creates a macro callable like "m coinbase.yml" '],
72
- ['alias -l', 'lists all the created aliases'],
73
- ['alias -l -f copy', 'lists the aliases filtering the ones that execute a "copy" command'],
74
- ['alias -r f fb', 'renames the alias "f" to "fb"'],
75
- ['alias -d g', 'deletes the alias "g"']
76
- ]
77
- }
69
+ [
70
+ 'alias f -c "copy facebook.yml -f email password"',
71
+ 'creates an alias "f" that executes "copy facebook.yml -f email password"',
72
+ ],
73
+ [
74
+ "alias g --previous-command",
75
+ 'creates the alias "g" using the previous command; this allows you to test something, and when ready generate an alias for it',
76
+ ],
77
+ [
78
+ 'alias C -c "copy coinbase.yml -f email password -d 4 && totp coinbase.yml"',
79
+ 'creates an alias "C" that copies email and password, and when the comand is executed, runs "totp coinbase.yml" ',
80
+ ],
81
+ [
82
+ 'alias m -c "copy $1 -f email password -d4 2 && totp $1"',
83
+ 'creates a macro callable like "m coinbase.yml" ',
84
+ ],
85
+ ["alias -l", "lists all the created aliases"],
86
+ [
87
+ "alias -l -f copy",
88
+ 'lists the aliases filtering the ones that execute a "copy" command',
89
+ ],
90
+ ["alias -r f fb", 'renames the alias "f" to "fb"'],
91
+ ["alias -d g", 'deletes the alias "g"'],
92
+ ],
93
+ };
78
94
  }
79
95
 
80
96
  async alias(options) {
81
97
  if (!this.aliasManager) {
82
- this.aliasManager = new AliasManager(this.secrez.cache)
98
+ this.aliasManager = new AliasManager(this.secrez.cache);
83
99
  }
84
100
  if (options.previousCommand && options.commandLine) {
85
- throw new Error('Conflicting parameters')
101
+ throw new Error("Conflicting parameters");
86
102
  }
87
103
  if (options.name && (options.previousCommand || options.commandLine)) {
88
- let error = this.aliasManager.validateName(options.name)
104
+ let error = this.aliasManager.validateName(options.name);
89
105
  if (error) {
90
- throw new Error(error)
106
+ throw new Error(error);
91
107
  }
92
108
  if (this.aliasManager.get(options.name)) {
93
- throw new Error(`An alias named "${options.name}" already exists`)
109
+ throw new Error(`An alias named "${options.name}" already exists`);
94
110
  }
95
111
  if (!options.commandLine) {
96
112
  options.commandLine = // for testing
97
- process.env.NODE_ENV === 'test'
98
- ? options.previousCommandLine
99
- : this.prompt.previousCommandLine
100
- }
101
- error = this.aliasManager.validateCommand(options.commandLine, this.prompt.commands)
113
+ process.env.NODE_ENV === "test"
114
+ ? options.previousCommandLine
115
+ : this.prompt.previousCommandLine;
116
+ }
117
+ error = this.aliasManager.validateCommand(
118
+ options.commandLine,
119
+ this.prompt.commands
120
+ );
102
121
  if (error) {
103
- throw new Error(error)
122
+ throw new Error(error);
104
123
  }
105
- let yes = options.skipConfirm
124
+ let yes = options.skipConfirm;
106
125
  /* istanbul ignore if */
107
126
  if (!yes) {
108
127
  yes = await this.useConfirm({
109
- message: `Are you sure you want to create the alias ${chalk.cyan(options.name)} for: \n${chalk.grey(options.commandLine)}\n?`,
110
- default: false
111
- })
128
+ message: `Are you sure you want to create the alias ${chalk.cyan(
129
+ options.name
130
+ )} for: \n${chalk.grey(options.commandLine)}\n?`,
131
+ default: false,
132
+ });
112
133
  }
113
134
  if (yes) {
114
135
  if (await this.aliasManager.create(options)) {
115
- return chalk.grey('The alias has been created')
136
+ return chalk.grey("The alias has been created");
116
137
  }
117
138
  } else {
118
- return chalk.grey('Operation canceled')
139
+ return chalk.grey("Operation canceled");
119
140
  }
120
-
121
141
  } else if (options.list) {
122
- let list = []
123
- let aliases = this.aliasManager.get()
124
- let max = 0
142
+ let list = [];
143
+ let aliases = this.aliasManager.get();
144
+ let max = 0;
125
145
  for (let alias in aliases) {
126
- let content = aliases[alias].content
146
+ let content = aliases[alias].content;
127
147
  if (options.filter) {
128
- if (content.split(' ')[0] !== options.filter) {
129
- continue
148
+ if (content.split(" ")[0] !== options.filter) {
149
+ continue;
130
150
  }
131
151
  }
132
- list.push([alias, content])
133
- max = Math.max(max, alias.length)
152
+ list.push([alias, content]);
153
+ max = Math.max(max, alias.length);
134
154
  }
135
- for (let i=0;i<list.length; i++) {
136
- list[i] = chalk.bold(list[i][0]) + ' '.repeat(max - list[i][0].length) + ' ' + chalk.reset(list[i][1])
155
+ for (let i = 0; i < list.length; i++) {
156
+ list[i] =
157
+ chalk.bold(list[i][0]) +
158
+ " ".repeat(max - list[i][0].length) +
159
+ " " +
160
+ chalk.reset(list[i][1]);
137
161
  }
138
- return list
162
+ return list;
139
163
  } else if (options.rename) {
140
- let [existentName, newName] = options.rename
164
+ let [existentName, newName] = options.rename;
141
165
  if (!this.aliasManager.get(existentName)) {
142
- throw new Error(`An alias named "${existentName}" does not exist`)
166
+ throw new Error(`An alias named "${existentName}" does not exist`);
143
167
  }
144
168
  if (this.aliasManager.get(newName)) {
145
- throw new Error(`An alias named "${newName}" already exists`)
169
+ throw new Error(`An alias named "${newName}" already exists`);
146
170
  }
147
- let error = this.aliasManager.validateName(newName)
171
+ let error = this.aliasManager.validateName(newName);
148
172
  if (error) {
149
- throw new Error(error)
173
+ throw new Error(error);
150
174
  }
151
175
  if (await this.aliasManager.rename(existentName, newName)) {
152
- return chalk.grey(`The alias "${existentName}" has been renamed "${newName}"`)
176
+ return chalk.grey(
177
+ `The alias "${existentName}" has been renamed "${newName}"`
178
+ );
153
179
  } else {
154
- throw new Error(`Could not rename "${existentName}"`)
180
+ throw new Error(`Could not rename "${existentName}"`);
155
181
  }
156
182
  } else if (options.delete) {
157
- let existentName = options.delete
183
+ let existentName = options.delete;
158
184
  if (!this.aliasManager.get(existentName)) {
159
- throw new Error(`An alias named "${existentName}" does not exist`)
185
+ throw new Error(`An alias named "${existentName}" does not exist`);
160
186
  }
161
187
  if (await this.aliasManager.remove(existentName)) {
162
- return chalk.grey(`The alias "${existentName}" has been removed`)
188
+ return chalk.grey(`The alias "${existentName}" has been removed`);
163
189
  } else {
164
- throw new Error(`Could not remove "${existentName}"`)
190
+ throw new Error(`Could not remove "${existentName}"`);
165
191
  }
166
-
167
192
  } else {
168
- throw new Error('Wrong parameters')
193
+ throw new Error("Wrong parameters");
169
194
  }
170
195
  }
171
196
 
172
197
  async exec(options = {}) {
173
198
  if (options.help) {
174
- return this.showHelp()
199
+ return this.showHelp();
175
200
  }
176
201
  try {
177
- this.validate(options)
178
- let result = await this.alias(options)
202
+ this.validate(options);
203
+ let result = await this.alias(options);
179
204
  if (!Array.isArray(result)) {
180
- result = [result]
205
+ result = [result];
181
206
  }
182
207
  for (let r of result) {
183
- this.Logger.reset(r)
208
+ this.Logger.reset(r);
184
209
  }
185
210
  } catch (e) {
186
- this.Logger.red(e.message)
211
+ this.Logger.red(e.message);
187
212
  }
188
- await this.prompt.run()
213
+ await this.prompt.run();
189
214
  }
190
215
  }
191
216
 
192
- module.exports = Alias
193
-
194
-
217
+ module.exports = Alias;
@@ -1,25 +1,23 @@
1
- const utils = require('@secrez/utils')
2
-
3
- class Bash extends require('../Command') {
1
+ const utils = require("@secrez/utils");
4
2
 
3
+ class Bash extends require("../Command") {
5
4
  setHelpAndCompletion() {
6
- this.cliConfig.completion.bash = utils.sortKeys({
7
- })
8
- this.cliConfig.completion.help.bash = true
9
- this.optionDefinitions = []
5
+ this.cliConfig.completion.bash = utils.sortKeys({});
6
+ this.cliConfig.completion.help.bash = true;
7
+ this.optionDefinitions = [];
10
8
  }
11
9
 
12
10
  help() {
13
11
  return {
14
12
  description: ['<< deprecated - use "shell" instead'],
15
- examples: []
16
- }
13
+ examples: [],
14
+ };
17
15
  }
18
16
 
19
17
  async exec(options = {}) {
20
- this.Logger.red('"bash" is deprecated. Use "shell" instead')
21
- await this.prompt.run()
18
+ this.Logger.red('"bash" is deprecated. Use "shell" instead');
19
+ await this.prompt.run();
22
20
  }
23
21
  }
24
22
 
25
- module.exports = Bash
23
+ module.exports = Bash;