-
Notifications
You must be signed in to change notification settings - Fork 83
/
gtt-log.js
executable file
·42 lines (35 loc) · 1.77 KB
/
gtt-log.js
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
const _ = require('underscore');
const program = require('commander');
const colors = require('colors');
const moment = require('moment-timezone');
const Config = require('./include/file-config');
const Cli = require('./include/cli');
const Time = require('./models/time');
const Tasks = require('./include/tasks');
program
.option('--verbose', 'show verbose output')
.option('--hours_per_day <hours>', 'hours per day for human readable time formats')
.option('--time_format <time_format>', 'time format')
.parse(process.argv);
Cli.verbose = program.verbose;
let config = new Config(__dirname).set('hoursPerDay', program.hours_per_day),
tasks = new Tasks(config),
timeFormat = config.set('timeFormat', program.time_format).get('timeFormat', 'log');
function toHumanReadable(input) {
return Time.toHumanReadable(Math.ceil(input), config.get('hoursPerDay'), timeFormat);
}
tasks.log()
.then(({frames, times}) => {
Object.keys(frames).sort().forEach(date => {
if (!frames.hasOwnProperty(date)) return;
console.log(`${moment(date).format('MMMM Do YYYY')} (${toHumanReadable(times[date])})`.green);
frames[date]
.sort((a, b) => a.start.isBefore(b.start) ? -1 : 1)
.forEach(frame => {
let issue = frame.resource.new ? `new ${frame.resource.type + ' "' + frame.resource.id.blue}"` : `${(frame.resource.type + ' #' + frame.resource.id).blue}`;
console.log(` ${frame.id} ${frame.start.clone().format('HH:mm').green} to ${frame.stop.clone().format('HH:mm').green}\t${toHumanReadable(frame.duration)}\t\t${frame.project.magenta}\t\t${issue}`)
});
});
}
)
.catch(error => Cli.error(error));