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/Ls.js
CHANGED
@@ -1,177 +1,187 @@
|
|
1
|
-
class Ls extends require(
|
2
|
-
|
1
|
+
class Ls extends require("../Command") {
|
3
2
|
setHelpAndCompletion() {
|
4
3
|
this.cliConfig.completion.ls = {
|
5
4
|
_func: this.selfCompletion(this),
|
6
|
-
_self: this
|
7
|
-
}
|
8
|
-
this.cliConfig.completion.help.ls = true
|
5
|
+
_self: this,
|
6
|
+
};
|
7
|
+
this.cliConfig.completion.help.ls = true;
|
9
8
|
this.optionDefinitions = [
|
10
9
|
{
|
11
|
-
name:
|
12
|
-
alias:
|
13
|
-
type: Boolean
|
10
|
+
name: "help",
|
11
|
+
alias: "h",
|
12
|
+
type: Boolean,
|
14
13
|
},
|
15
14
|
{
|
16
|
-
name:
|
17
|
-
completionType:
|
18
|
-
alias:
|
15
|
+
name: "path",
|
16
|
+
completionType: "file",
|
17
|
+
alias: "p",
|
19
18
|
defaultOption: true,
|
20
|
-
type: String
|
19
|
+
type: String,
|
21
20
|
},
|
22
21
|
{
|
23
|
-
name:
|
24
|
-
alias:
|
25
|
-
type: Boolean
|
22
|
+
name: "list",
|
23
|
+
alias: "l",
|
24
|
+
type: Boolean,
|
26
25
|
},
|
27
26
|
{
|
28
|
-
name:
|
29
|
-
alias:
|
30
|
-
type: Boolean
|
27
|
+
name: "all",
|
28
|
+
alias: "a",
|
29
|
+
type: Boolean,
|
31
30
|
},
|
32
31
|
{
|
33
|
-
name:
|
34
|
-
completionType:
|
35
|
-
alias:
|
36
|
-
type: Boolean
|
32
|
+
name: "datasets",
|
33
|
+
completionType: "dataset",
|
34
|
+
alias: "d",
|
35
|
+
type: Boolean,
|
37
36
|
},
|
38
37
|
{
|
39
|
-
name:
|
40
|
-
alias:
|
41
|
-
type: String
|
42
|
-
}
|
43
|
-
]
|
38
|
+
name: "only",
|
39
|
+
alias: "o",
|
40
|
+
type: String,
|
41
|
+
},
|
42
|
+
];
|
44
43
|
}
|
45
44
|
|
46
45
|
help() {
|
47
46
|
return {
|
48
|
-
description: [
|
47
|
+
description: ["Browses the directories."],
|
49
48
|
examples: [
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
[
|
54
|
-
|
55
|
-
|
49
|
+
"ls coin",
|
50
|
+
"ls ../passwords",
|
51
|
+
"ls ~",
|
52
|
+
[
|
53
|
+
"ls -l",
|
54
|
+
"Shows details:",
|
55
|
+
"size, creation date, last update date,",
|
56
|
+
" number of versions and name",
|
56
57
|
],
|
57
|
-
[
|
58
|
-
[
|
59
|
-
[
|
60
|
-
[
|
61
|
-
]
|
62
|
-
}
|
58
|
+
["ls -al", "Includes hidden files"],
|
59
|
+
["ls -o d", "Lists only the directories"],
|
60
|
+
["ls -o f", "Lists only the files"],
|
61
|
+
["ls -d", "Lists the existent datasets"],
|
62
|
+
],
|
63
|
+
};
|
63
64
|
}
|
64
65
|
|
65
66
|
formatTs(ts) {
|
66
|
-
let months =
|
67
|
-
let d = new Date(ts)
|
68
|
-
let today = new Date()
|
69
|
-
let currentYear = today.getFullYear()
|
70
|
-
let year = d.getFullYear()
|
67
|
+
let months = "Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec".split(",");
|
68
|
+
let d = new Date(ts);
|
69
|
+
let today = new Date();
|
70
|
+
let currentYear = today.getFullYear();
|
71
|
+
let year = d.getFullYear();
|
71
72
|
if (year === currentYear) {
|
72
|
-
year =
|
73
|
+
year =
|
74
|
+
this.prependWithSpace(d.getHours(), 2) +
|
75
|
+
":" +
|
76
|
+
this.prependWithSpace(d.getMinutes(), 2);
|
73
77
|
}
|
74
78
|
return [
|
75
79
|
months[d.getMonth()],
|
76
80
|
this.prependWithSpace(d.getDate().toString(), 2),
|
77
|
-
this.prependWithSpace(year.toString(), 5)
|
78
|
-
].join(
|
81
|
+
this.prependWithSpace(year.toString(), 5),
|
82
|
+
].join(" ");
|
79
83
|
}
|
80
84
|
|
81
85
|
prependWithSpace(str, max) {
|
82
|
-
return
|
86
|
+
return " ".repeat(max - str.length) + str;
|
83
87
|
}
|
84
88
|
|
85
89
|
async ls(options = {}) {
|
86
|
-
let datasetInfo = await this.internalFs.getDatasetsInfo()
|
90
|
+
let datasetInfo = await this.internalFs.getDatasetsInfo();
|
87
91
|
if (options.datasets) {
|
88
|
-
return datasetInfo.map(e => e.name)
|
92
|
+
return datasetInfo.map((e) => e.name);
|
89
93
|
} else {
|
90
94
|
if (!options.path) {
|
91
|
-
options.path =
|
95
|
+
options.path = ".";
|
92
96
|
}
|
93
|
-
let ds
|
97
|
+
let ds;
|
94
98
|
if (/^[a-zA-Z]{1}\w{1,15}:/.test(options.path)) {
|
95
|
-
ds = options.path.split(
|
99
|
+
ds = options.path.split(":")[0];
|
96
100
|
}
|
97
|
-
options.ignoreDatasets = true
|
98
|
-
if (datasetInfo.map(e => e.name).includes(options.path)) {
|
99
|
-
options.path +=
|
101
|
+
options.ignoreDatasets = true;
|
102
|
+
if (datasetInfo.map((e) => e.name).includes(options.path)) {
|
103
|
+
options.path += ":";
|
100
104
|
}
|
101
105
|
if (options.list) {
|
102
|
-
let list = await this.internalFs.fileList(options, false, true)
|
103
|
-
let maxLength = 0
|
104
|
-
let maxVersionNumber = 0
|
105
|
-
let finalList = []
|
106
|
-
let tree
|
106
|
+
let list = await this.internalFs.fileList(options, false, true);
|
107
|
+
let maxLength = 0;
|
108
|
+
let maxVersionNumber = 0;
|
109
|
+
let finalList = [];
|
110
|
+
let tree;
|
107
111
|
for (let i = 0; i < list.length; i++) {
|
108
112
|
if (!tree) {
|
109
113
|
if (ds) {
|
110
114
|
for (let d of datasetInfo) {
|
111
115
|
if (d.name === ds) {
|
112
|
-
tree = this.internalFs.trees[d.index]
|
116
|
+
tree = this.internalFs.trees[d.index];
|
113
117
|
}
|
114
118
|
}
|
115
119
|
} else {
|
116
|
-
tree = this.internalFs.tree
|
120
|
+
tree = this.internalFs.tree;
|
117
121
|
}
|
118
122
|
}
|
119
|
-
let ts = list[i].lastTs
|
120
|
-
let details = await tree.getEntryDetails(list[i], ts)
|
121
|
-
let ts0 = ts = parseInt(ts.split(
|
122
|
-
let versions = Object.keys(list[i].versions)
|
123
|
+
let ts = list[i].lastTs;
|
124
|
+
let details = await tree.getEntryDetails(list[i], ts);
|
125
|
+
let ts0 = (ts = parseInt(ts.split(".")[0]) * 1000);
|
126
|
+
let versions = Object.keys(list[i].versions);
|
123
127
|
for (let v of versions) {
|
124
|
-
let timestamp = parseInt(v.split(
|
128
|
+
let timestamp = parseInt(v.split(".")[0]) * 1000;
|
125
129
|
if (timestamp < ts0) {
|
126
|
-
ts0 = timestamp
|
130
|
+
ts0 = timestamp;
|
127
131
|
}
|
128
132
|
}
|
129
|
-
details.ts0 = ts0
|
130
|
-
details.ts = ts
|
131
|
-
details.size = ((details.content ||
|
132
|
-
maxLength = Math.max(maxLength, details.size.length)
|
133
|
-
details.versions = versions.length.toString()
|
134
|
-
maxVersionNumber = Math.max(
|
135
|
-
|
133
|
+
details.ts0 = ts0;
|
134
|
+
details.ts = ts;
|
135
|
+
details.size = ((details.content || "").length || 0).toString();
|
136
|
+
maxLength = Math.max(maxLength, details.size.length);
|
137
|
+
details.versions = versions.length.toString();
|
138
|
+
maxVersionNumber = Math.max(
|
139
|
+
maxVersionNumber,
|
140
|
+
details.versions.length
|
141
|
+
);
|
142
|
+
finalList.push(details);
|
136
143
|
}
|
137
|
-
finalList = finalList.map(e => {
|
144
|
+
finalList = finalList.map((e) => {
|
138
145
|
return [
|
139
146
|
this.prependWithSpace(e.size, maxLength),
|
140
147
|
this.formatTs(e.ts0),
|
141
148
|
this.formatTs(e.ts),
|
142
149
|
this.prependWithSpace(e.versions, maxVersionNumber),
|
143
|
-
e.name + (e.type === this.secrez.config.types.DIR ?
|
144
|
-
].join(
|
145
|
-
})
|
146
|
-
return finalList
|
147
|
-
|
150
|
+
e.name + (e.type === this.secrez.config.types.DIR ? "/" : ""),
|
151
|
+
].join(" ");
|
152
|
+
});
|
153
|
+
return finalList;
|
148
154
|
} else {
|
149
|
-
return await this.internalFs.fileList(options, true)
|
155
|
+
return await this.internalFs.fileList(options, true);
|
150
156
|
}
|
151
157
|
}
|
152
158
|
}
|
153
159
|
|
154
160
|
async exec(options = {}) {
|
155
161
|
if (options.help) {
|
156
|
-
return this.showHelp()
|
162
|
+
return this.showHelp();
|
157
163
|
}
|
158
164
|
try {
|
159
|
-
this.validate(options)
|
160
|
-
let list = await this.ls(options)
|
161
|
-
list = list.filter(e => !/^\./.test(e) || options.all).sort()
|
165
|
+
this.validate(options);
|
166
|
+
let list = await this.ls(options);
|
167
|
+
list = list.filter((e) => !/^\./.test(e) || options.all).sort();
|
162
168
|
if (list.length) {
|
163
|
-
this.Logger.reset(
|
164
|
-
|
165
|
-
|
166
|
-
|
169
|
+
this.Logger.reset(
|
170
|
+
options.list
|
171
|
+
? list.join("\n")
|
172
|
+
: this.prompt.commandPrompt.formatList(
|
173
|
+
list,
|
174
|
+
26,
|
175
|
+
true,
|
176
|
+
this.threeRedDots()
|
177
|
+
)
|
178
|
+
);
|
167
179
|
}
|
168
180
|
} catch (e) {
|
169
|
-
this.Logger.red(e.message)
|
181
|
+
this.Logger.red(e.message);
|
170
182
|
}
|
171
|
-
await this.prompt.run()
|
183
|
+
await this.prompt.run();
|
172
184
|
}
|
173
185
|
}
|
174
186
|
|
175
|
-
module.exports = Ls
|
176
|
-
|
177
|
-
|
187
|
+
module.exports = Ls;
|
package/src/commands/Mkdir.js
CHANGED
@@ -1,68 +1,65 @@
|
|
1
|
-
const {config, Entry} = require(
|
2
|
-
|
3
|
-
class Mkdir extends require('../Command') {
|
1
|
+
const { config, Entry } = require("@secrez/core");
|
4
2
|
|
3
|
+
class Mkdir extends require("../Command") {
|
5
4
|
setHelpAndCompletion() {
|
6
5
|
this.cliConfig.completion.mkdir = {
|
7
6
|
_func: this.selfCompletion(this),
|
8
|
-
_self: this
|
9
|
-
}
|
10
|
-
this.cliConfig.completion.help.mkdir = true
|
7
|
+
_self: this,
|
8
|
+
};
|
9
|
+
this.cliConfig.completion.help.mkdir = true;
|
11
10
|
this.optionDefinitions = [
|
12
11
|
{
|
13
|
-
name:
|
14
|
-
alias:
|
15
|
-
type: Boolean
|
12
|
+
name: "help",
|
13
|
+
alias: "h",
|
14
|
+
type: Boolean,
|
16
15
|
},
|
17
16
|
{
|
18
|
-
name:
|
19
|
-
completionType:
|
20
|
-
alias:
|
17
|
+
name: "path",
|
18
|
+
completionType: "file",
|
19
|
+
alias: "p",
|
21
20
|
defaultOption: true,
|
22
|
-
type: String
|
23
|
-
}
|
24
|
-
]
|
21
|
+
type: String,
|
22
|
+
},
|
23
|
+
];
|
25
24
|
}
|
26
25
|
|
27
26
|
help() {
|
28
27
|
return {
|
29
|
-
description: [
|
28
|
+
description: ["Creates a directory."],
|
30
29
|
examples: [
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
'mkdir "super folder"'
|
35
|
-
]
|
36
|
-
}
|
30
|
+
"mkdir cryptos",
|
31
|
+
"mkdir coin/tron/wallet",
|
32
|
+
"mkdir ../other\\ people",
|
33
|
+
'mkdir "super folder"',
|
34
|
+
],
|
35
|
+
};
|
37
36
|
}
|
38
37
|
|
39
38
|
async mkdir(options = {}) {
|
40
|
-
this.checkPath(options)
|
41
|
-
options.type = config.types.DIR
|
42
|
-
return await this.internalFs.make(options)
|
39
|
+
this.checkPath(options);
|
40
|
+
options.type = config.types.DIR;
|
41
|
+
return await this.internalFs.make(options);
|
43
42
|
}
|
44
43
|
|
45
44
|
async exec(options = {}) {
|
46
45
|
if (options.help) {
|
47
|
-
return this.showHelp()
|
46
|
+
return this.showHelp();
|
48
47
|
}
|
49
48
|
try {
|
50
|
-
this.validate(options)
|
51
|
-
this.checkPath(options)
|
52
|
-
let data = await this.internalFs.getTreeIndexAndPath(options.path)
|
53
|
-
let sanitizedPath = Entry.sanitizePath(data.path)
|
49
|
+
this.validate(options);
|
50
|
+
this.checkPath(options);
|
51
|
+
let data = await this.internalFs.getTreeIndexAndPath(options.path);
|
52
|
+
let sanitizedPath = Entry.sanitizePath(data.path);
|
54
53
|
if (sanitizedPath !== data.path) {
|
55
|
-
throw new Error(
|
54
|
+
throw new Error("A filename cannot contain \\/><|:&?*^$ chars.");
|
56
55
|
}
|
57
|
-
await this.mkdir(options)
|
58
|
-
this.Logger.grey(`New folder "${options.path}" created.`)
|
56
|
+
await this.mkdir(options);
|
57
|
+
this.Logger.grey(`New folder "${options.path}" created.`);
|
59
58
|
} catch (e) {
|
60
|
-
this.Logger.red(e.message)
|
59
|
+
this.Logger.red(e.message);
|
61
60
|
}
|
62
|
-
await this.prompt.run()
|
61
|
+
await this.prompt.run();
|
63
62
|
}
|
64
63
|
}
|
65
64
|
|
66
|
-
module.exports = Mkdir
|
67
|
-
|
68
|
-
|
65
|
+
module.exports = Mkdir;
|