-
Notifications
You must be signed in to change notification settings - Fork 0
/
izone.js
58 lines (49 loc) · 1.17 KB
/
izone.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
const cli = require('./lib/cli')
const google = require('./lib/adapters/google')
let exitCode = 0
let _command = process.argv[2]
if (!_command) {
_command = 'summary'
}
const r = () => {
switch (_command) {
/**
* Save time entries to izone db.
*/
case 'import':
return google.checkConfiguration()
.then(() => cli.import(process.argv[3]))
/**
* List all time entries from google calendar and izone db.
*/
case 'ls':
return google.checkConfiguration()
.then(() => cli.ls(process.argv[3]))
/**
* Show a summary of time spent.
*/
case 'summary':
return google.checkConfiguration()
.then(() => cli.summary(process.argv[3]))
default:
return Promise.reject(new Error((`Command '${_command}' is not declared.`)))
}
}
r()
.then(() => {
console.log()
})
.catch(error => {
exitCode = 1
if (error.message) {
console.error(`Error: ${error.message}`)
}
if (error.statusMessage) {
console.error(`Error: ${error.statusCode} ${error.statusMessage}`)
}
console.error(error)
})
.then(() => {
console.log()
process.exit(exitCode)
})