creepercli 1.0.0 → 1.1.1
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 +190 -0
- package/README.md +85 -117
- package/bin/creepercli.js +12 -25
- package/package.json +48 -48
- package/src/client.js +137 -127
- package/src/commands/auth.js +94 -108
- package/src/commands/exec.js +23 -37
- package/src/commands/fs.js +138 -152
- package/src/commands/index.js +129 -139
- package/src/commands/monitor.js +60 -69
- package/src/commands/search.js +56 -70
- package/src/config.js +47 -61
- package/src/editor.js +84 -98
- package/src/formatters.js +120 -134
- package/src/index.js +175 -186
- package/src/prompts.js +120 -134
- package/src/protocol.js +68 -82
- package/src/repl.js +94 -104
- package/src/session.js +40 -58
- package/src/top.js +39 -53
- package/src/transfer.js +292 -217
- package/src/update.js +73 -87
package/src/session.js
CHANGED
|
@@ -1,58 +1,40 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
if (creds.expiresAt && Date.now() > creds.expiresAt) {
|
|
42
|
-
clear();
|
|
43
|
-
return null;
|
|
44
|
-
}
|
|
45
|
-
return creds;
|
|
46
|
-
} catch {
|
|
47
|
-
return null;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function clear() {
|
|
52
|
-
try {
|
|
53
|
-
fs.unlinkSync(CREDS_FILE);
|
|
54
|
-
} catch {
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
module.exports = { DIR, CREDS_FILE, HISTORY_FILE, save, load, clear };
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
'use strict';
|
|
4
|
+
|
|
5
|
+
const fs = require('fs');
|
|
6
|
+
const os = require('os');
|
|
7
|
+
const path = require('path');
|
|
8
|
+
|
|
9
|
+
const DIR = path.join(os.homedir(), '.creepercli');
|
|
10
|
+
const CREDS_FILE = path.join(DIR, 'creds');
|
|
11
|
+
const HISTORY_FILE = path.join(DIR, 'history');
|
|
12
|
+
|
|
13
|
+
function ensureDir() {
|
|
14
|
+
fs.mkdirSync(DIR, { recursive: true, mode: 0o700 });
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function save(creds) {
|
|
18
|
+
ensureDir();
|
|
19
|
+
fs.writeFileSync(CREDS_FILE, JSON.stringify(creds, null, 2), { mode: 0o600 });
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function load(host, port) {
|
|
23
|
+
try {
|
|
24
|
+
const raw = fs.readFileSync(CREDS_FILE, 'utf8');
|
|
25
|
+
const creds = JSON.parse(raw);
|
|
26
|
+
if (creds.host !== host || creds.port !== port) return null;
|
|
27
|
+
return creds;
|
|
28
|
+
} catch {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function clear() {
|
|
34
|
+
try {
|
|
35
|
+
fs.unlinkSync(CREDS_FILE);
|
|
36
|
+
} catch {
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
module.exports = { DIR, CREDS_FILE, HISTORY_FILE, save, load, clear };
|
package/src/top.js
CHANGED
|
@@ -1,53 +1,39 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
readline.clearScreenDown(process.stdout);
|
|
41
|
-
console.log('CreeperCLI top (q to quit)\n');
|
|
42
|
-
console.log(formatStats(res.stats));
|
|
43
|
-
console.log();
|
|
44
|
-
console.log(formatTps(res.tps));
|
|
45
|
-
await sleep(refreshMs);
|
|
46
|
-
}
|
|
47
|
-
} finally {
|
|
48
|
-
process.stdin.removeListener('keypress', onKey);
|
|
49
|
-
if (process.stdin.isTTY) process.stdin.setRawMode(false);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
module.exports = { runTop };
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
'use strict';
|
|
4
|
+
|
|
5
|
+
const readline = require('readline');
|
|
6
|
+
const { formatStats, formatTps } = require('./formatters');
|
|
7
|
+
|
|
8
|
+
function sleep(ms) {
|
|
9
|
+
return new Promise((r) => setTimeout(r, ms));
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
async function runTop(client, refreshMs) {
|
|
13
|
+
if (process.stdin.isTTY) {
|
|
14
|
+
readline.emitKeypressEvents(process.stdin);
|
|
15
|
+
process.stdin.setRawMode(true);
|
|
16
|
+
}
|
|
17
|
+
let stopped = false;
|
|
18
|
+
const onKey = (str, key) => {
|
|
19
|
+
if (key.name === 'q' || key.name === 'escape' || (key.ctrl && key.name === 'c')) stopped = true;
|
|
20
|
+
};
|
|
21
|
+
process.stdin.on('keypress', onKey);
|
|
22
|
+
try {
|
|
23
|
+
while (!stopped) {
|
|
24
|
+
const res = await client.request('monitor.top', {});
|
|
25
|
+
readline.cursorTo(process.stdout, 0, 0);
|
|
26
|
+
readline.clearScreenDown(process.stdout);
|
|
27
|
+
console.log('CreeperCLI top (q to quit)\n');
|
|
28
|
+
console.log(formatStats(res.stats));
|
|
29
|
+
console.log();
|
|
30
|
+
console.log(formatTps(res.tps));
|
|
31
|
+
await sleep(refreshMs);
|
|
32
|
+
}
|
|
33
|
+
} finally {
|
|
34
|
+
process.stdin.removeListener('keypress', onKey);
|
|
35
|
+
if (process.stdin.isTTY) process.stdin.setRawMode(false);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
module.exports = { runTop };
|