-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathcli.js
More file actions
executable file
·48 lines (43 loc) · 1.31 KB
/
cli.js
File metadata and controls
executable file
·48 lines (43 loc) · 1.31 KB
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
41
42
43
44
45
46
47
48
#!/usr/bin/env node
'use strict';
const etherpad = require('./index.js');
const args = process.argv;
const host = args[2];
const action = args[3];
const string = args[4];
if (args.length < 3) {
console.log('No host specified..');
console.log('Stream Pad to CLI: etherpad http://127.0.0.1:9001/p/test');
console.log("Append contents to pad: etherpad http://127.0.0.1:9001/p/test -a 'hello world'");
throw new Error();
}
if (host) {
if (!action) {
// Stream pad to UI
const pad = etherpad.connect(host);
pad.on('connected', (padState) => {
console.log('Connected to', padState.host, 'with padId', padState.padId);
console.log('\u001b[2J\u001b[0;0H');
console.log('Pad Contents', `\n${padState.atext.text}`);
});
pad.on('newContents', (atext) => {
console.log('\u001b[2J\u001b[0;0H');
console.log('Pad Contents', `\n${atext.text}`);
});
}
if (action) {
if (action === '-a') {
// appending a string to a pad
if (!string) {
console.log('No string specified with pad');
throw new Error();
}
const pad = etherpad.connect(host);
pad.on('connected', () => {
pad.append(string); // Appends Hello to the Pad contents
console.log('Appended', string, 'to ', host);
throw new Error();
});
}
}
}