forked from danibram/time-tracker-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
59 lines (47 loc) · 2.33 KB
/
Copy pathindex.js
File metadata and controls
59 lines (47 loc) · 2.33 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
import 'babel-polyfill'
import program from 'commander'
import updateNotifier from 'update-notifier'
import Task from './Task'
import {sumarize} from './Output'
import {humanParseDiff} from './Utils'
import timer from './Manager'
import pkg from '../package.json'
updateNotifier({pkg}).notify()
module.exports = function createTimer (p) {
program
.version(pkg.version)
.description('Tiny time tracker for projects')
.option('-s, --start <task> <description>', 'Start the timer task.')
.option('-f, --finish <task> <description>', 'Stops the timer task.')
.option('-d, --description <description>', 'Adds a description for the task only in start/stop methods.')
.option('-a, --add <task> <timeString>', 'Adds time to a task. Example: "1h2m3s"')
.option('--remove <task> <timeString>', 'Subtract time from a task. Example: "1h2m3s"')
.option('-l, --log <task>', 'Logs the timer task.')
.option('-r, --report <task> <rate>', 'Report time of the tasks, searched by key, you can report all using all as key. Also you can pass a rate to calc an amount ex: 20h, calc the hours and mulpitly by 20')
.option('-e, --export', 'Prints the json of all tasks.')
.parse(p.argv)
let description
if (program.start){
description = program.description || program.args[0]
timer.start(program.start, description)
} else if (program.finish){
description = program.description || program.args[0]
timer.stop(program.finish, description)
console.log(humanParseDiff(timer.getTime(program.finish)))
} else if (program.add){
timer.modifyTask('add', program.add, program.args[0])
sumarize(program.add, timer.search(program.add))
} else if (program.remove){
timer.modifyTask('subtract', program.remove, program.args[0])
sumarize(program.remove, timer.search(program.remove))
} else if (program.log){
setInterval(function() {
process.stdout.clearLine()
process.stdout.write(`\r Task: ${program.log} ${humanParseDiff(timer.getTime(program.log))}`)
}, 100)
} else if (program.report){
sumarize(program.report, timer.search(program.report), program.args[0], true)
} else if (program.export){
console.log(JSON.stringify(timer.getTasksJson(), null, 4))
}
}