forked from ether/etherpad-cli-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.js
More file actions
48 lines (42 loc) · 1.29 KB
/
cli.js
File metadata and controls
48 lines (42 loc) · 1.29 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
var etherpad = require("./index.js");
var args = process.argv;
var host = args[2];
var action = args[3];
var 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'");
process.exit(code=0);
}
if(host){
if(!action){
// Stream pad to UI
var pad = etherpad.connect(host);
pad.on("connected", function (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", function(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");
process.exit(code=0);
}
var pad = etherpad.connect(host);
pad.on("connected", function(){
pad.append(string); // Appends Hello to the Pad contents
console.log("Appended", string, "to ", host);
process.exit(code=0);
});
}
}
}