-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
cli.js
79 lines (52 loc) · 1.02 KB
/
cli.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/env node
'use strict'
var pkg = require( './package.json' )
var movieInfo = require( './index' )
var movie = process.argv[2]
var help = function () {
console.log( pkg.description, '\n' )
console.log( 'Usage' )
console.log( ' $ movie-info movie [year]\n' )
console.log( 'Example' )
console.log( ' $ movie-info \'Oceans Eleven\' 1960' )
console.log( ' { ... }' )
}
var main = function () {
if (
process.argv.indexOf( '-h' ) !== -1 ||
process.argv.indexOf( '--help' ) !== -1
) {
help()
return
}
if (
process.argv.indexOf( '-v' ) !== -1 ||
process.argv.indexOf( '--version' ) !== -1
) {
console.log( pkg.version )
return
}
var argc = process.argv.length
if ( argc === 3 ) {
movieInfo( movie, null ).then(
res => {
console.log( res )
},
err => {
console.log( err )
}
)
} else if ( argc === 4 ) {
movieInfo( movie, process.argv[3] ).then(
res => {
console.log( res )
},
err => {
console.log( err )
}
)
} else {
help()
}
}
main()