forked from danibram/time-tracker-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoutput.js
More file actions
73 lines (57 loc) · 1.83 KB
/
Copy pathoutput.js
File metadata and controls
73 lines (57 loc) · 1.83 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
72
73
import moment from 'moment'
import Table from 'cli-table'
import chalk from 'chalk'
import { humanParseDiff, calcRate } from './utils'
export const sumarize = function(search, tasks, rate, full, format) {
let table = new Table({
head: ['Duration', 'Dates', 'Task'],
chars: {'mid': '', 'left-mid': '', 'mid-mid': '', 'right-mid': ''},
colAligns: ['right', 'center', 'left'],
style: { head: ['green'] }
});
let total = 0
let head= `Search: ${search} \n`
tasks.forEach((task, index) => {
let name = task.name
task = task.task
let duration = task.getSeconds()
total += duration
table.push([humanParseDiff(duration), moment(task.getStartDate()).format(format), name])
})
console.log(table.toString());
if (full){
let table2 = new Table()
table2.push(
{ 'Search': ['\"' + search + '\"'] },
{ 'Total time': [humanParseDiff(total)] }
)
if (rate){
table2.push({ 'Rate': [calcRate(rate, total)] })
}
console.log(table2.toString());
}
}
export const outputConfig = function (config){
let table = new Table({
head: ['Key', 'value'],
chars: {'mid': '', 'left-mid': '', 'mid-mid': '', 'right-mid': ''},
colAligns: ['center', 'center'],
style: { head: ['green'] }
});
Object.keys(config).map(e => table.push([e, config[e]]))
console.log(table.toString());
}
export const outputVertical = function (...args){
let table2 = new Table()
let key = args.splice(0, 1)
table2.push(
{ [key]: args },
)
return table2.toString()
}
export const cliError = function(err) {
console.error(chalk.red(`Error: ${err}`))
}
export const cliSuccess = function(err) {
console.log(chalk.green(err))
}