-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcli.js
More file actions
71 lines (59 loc) · 1.98 KB
/
cli.js
File metadata and controls
71 lines (59 loc) · 1.98 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// Generated by CoffeeScript 1.6.1
(function() {
var Bang, CLI, Command, exec, packageInfo,
__slice = [].slice;
Command = require("commander").Command;
Bang = require("./bang");
exec = require("child_process").exec;
packageInfo = require("../package.json");
module.exports = CLI = (function() {
function CLI(args, mockBang) {
this.bang = mockBang || new Bang;
this.program = new Command;
this.program.version(packageInfo.version, "-v, --version").usage("[options] [key] [value]").option("-d, --delete", "delete the specified key").parse(args);
}
CLI.prototype.start = function() {
var key, value, _ref;
_ref = this.program.args, key = _ref[0], value = _ref[1];
if (key && this.program["delete"]) {
return this.bang["delete"](key);
} else if (key && value) {
return this.bang.set(key, value);
} else if (key) {
value = this.bang.get(key);
if (value) {
this.log(value);
return this.copy(value);
}
} else if (Object.keys(this.bang.data).length === 0) {
return this.log(this.program.helpInformation());
} else {
return this.log(this.bang.list());
}
};
CLI.prototype.log = function() {
var args;
args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
return console.log.apply(console, args);
};
CLI.prototype.copy = function(value) {
var copyCommand;
copyCommand = (function() {
switch (process.platform) {
case "darwin":
return "pbcopy";
case "win32":
return "clip";
default:
return "xclip -selection clipboard";
}
})();
if (process.platform === "win32") {
return exec("echo " + (value.replace(/\'/g, "\\'")) + " | " + copyCommand);
} else {
return exec("printf '" + (value.replace(/\'/g, "\\'")) + "' | " + copyCommand);
}
};
return CLI;
})();
}).call(this);