-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwr
executable file
·98 lines (91 loc) · 2.91 KB
/
wr
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/usr/bin/env node
// TODO: Yank out per-WR queries (like timesheets) into post processing
// TODO: Add timesheet-centric output variant
var _ = require('underscore')._,
db = require('./db.js'),
wrms_cli= require('./wrms_cli.js'),
bind = require('./common.js').bind,
die = require('./common.js').die,
getopt = require('posix-getopt');
function usage(){
die(
'Usage: wr [options] <wr...>' +
'\n\t--timesheets (show a timesheet-oriented view of the work requests)' +
'\n\t--allocated-to <user> (Filter by case-insensitive regex, e.g. "james|sam")' +
'\n\t--host <db-host=\033[1m' + db.config.host + '\033[0m>' +
'\n\t--format [\033[1mpretty\033[0m|csv]' +
'\n\t--port <port=\033[1m' + db.config.port + '\033[0m>' +
'\n\t--sort-by [wr|brief|\033[1mstatus\033[0m]' +
'\n\t--verbose' +
'\n\t--debug' +
''
);
}
var config = {
on_completion: 'wr_view',
sort_by: 'status',
allocated_to: null,
output: 'pretty',
verbose: false,
debug: false
};
(function(){
var parser = new getopt.BasicParser('t(timesheets)d(debug)v(verbose)a:(allocated-to)f:(format)s:(sort-by)h:(host)p:(port)', process.argv);
var option = undefined;
while ((option = parser.getopt()) !== undefined){
switch (option.option){
case 'a':
config.allocated_to = option.optarg;
break;
case 'h':
db.config.host = option.optarg;
break;
case 's':
if (option.optarg.match(/^(wr|brief|status)$/)){
config.sort_by = option.optarg;
}else{
usage();
}
break;
case 'f':
if (option.optarg.match(/^(pretty|csv)$/)){
config.output = option.optarg;
}else{
usage();
}
break;
case 'p':
db.config.port = parseInt(option.optarg);
if (isNaN(db.config.port)){
die('Invalid database port "' + option.optarg + '"');
}
break;
case 'd':
config.debug = true;
break;
case 'v':
config.verbose = true;
break;
case 't':
config.on_completion = 'timesheet_view';
break;
}
}
var wrs = process.argv.slice(parser.optind());
if (wrs.length < 1){
usage();
}
wrms_cli.init({
config: config,
db: db
});
function finish(){
try{
db.close();
}catch(ex){
console.error('Exception at wrms_cli.js:finish() - [[' + ex + ']]');
}
process.exit(0);
}
db.init().then(bind(wrms_cli.run, wrs)).fail(die).fin(finish);
})();