-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
cli.js
112 lines (82 loc) · 1.64 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/usr/bin/env node
'use strict'
const meow = require( 'meow' )
const movieTrailer = require( './index' )
const cli = meow(
`
Usage
$ movie-trailer movie [year] [multi]
Options
--api_key -k (optional) Your own TMDB API key: http://developers.themoviedb.org
--id -i Return just the Youtube video ID.
--language, -l Specify a language code (eg: 'de_DE').
--multi, -m Returns an array of URLs instead of a single URL.
--tmdb_id -t Specify an explicit TMDB ID.
--year, -y Specify a release year to search.
Example
$ movie-trailer 'Oceans Eleven' --year 1960
// => http://path/to/trailer
`,
{
flags: {
// eslint-disable-next-line camelcase
api_key: {
type: 'string',
alias: 'k'
},
id: {
alias: 'i',
type: 'boolean'
},
language: {
type: 'string',
alias: 'l'
},
multi: {
alias: 'm',
type: 'boolean'
},
// eslint-disable-next-line camelcase
tmdb_id: {
type: 'string',
alias: 't'
},
year: {
type: 'string',
alias: 'y'
}
}
}
)
const options = {
id: false,
language: null,
multi: false,
year: null
}
if ( cli.flags.i ) {
options.id = Boolean( cli.flags.i )
}
if ( cli.flags.k ) {
options.apiKey = cli.flags.k
}
if ( cli.flags.l ) {
options.language = cli.flags.l
}
if ( cli.flags.m ) {
options.multi = Boolean( cli.flags.m )
}
if ( cli.flags.t ) {
options.tmdbId = cli.flags.t
}
if ( cli.flags.y ) {
options.year = cli.flags.y
}
if ( !cli.input[0] && !options.tmdbId ) {
cli.showHelp()
}
movieTrailer( cli.input[0], options ).then( result => {
if ( result ) {
console.log( result )
}
} )