-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2395452
commit ca8a95a
Showing
2 changed files
with
40 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,43 @@ | ||
#!/usr/bin/env node | ||
'use strict'; | ||
var pkg = require('./package.json'); | ||
var movieTrailer = require('./index'); | ||
var movie = process.argv[2]; | ||
'use strict' | ||
const meow = require( 'meow' ) | ||
const movieTrailer = require('./index') | ||
|
||
var cb = function (err, url) { | ||
if (err) { | ||
console.error(err); | ||
process.exit(1); | ||
} | ||
console.log(url); | ||
}; | ||
|
||
var help = function () { | ||
console.log(pkg.description); | ||
console.log(''); | ||
console.log('Usage'); | ||
console.log(' $ movie-trailer movie [year]'); | ||
console.log(''); | ||
console.log('Example'); | ||
console.log(' $ movie-trailer \'Oceans Eleven\' 1960'); | ||
console.log(' http://path/to/trailer'); | ||
}; | ||
const cli = meow( ` | ||
Usage | ||
$ movie-trailer movie [year] | ||
if (process.argv.indexOf('-h') !== -1 || process.argv.indexOf('--help') !== -1) { | ||
help(); | ||
return; | ||
} | ||
Options | ||
--year, -year Specify a release year to search | ||
--multi, -m Returns an array of URLs instead of a single URL | ||
if (process.argv.indexOf('-v') !== -1 || process.argv.indexOf('--version') !== -1) { | ||
console.log(pkg.version); | ||
return; | ||
} | ||
Example | ||
$ movie-trailer Avatar | ||
// => http://path/to/trailer | ||
`, { | ||
flags: { | ||
multi: { | ||
alias: 'm' | ||
}, | ||
year: { | ||
type: 'string', | ||
alias: 'y' | ||
} | ||
} | ||
} ) | ||
|
||
var multi = false; | ||
if (process.argv.indexOf('-m') !== -1 || process.argv.indexOf('--multi') !== -1) { | ||
multi = true; | ||
let opts = { | ||
multi: false, | ||
year: null | ||
} | ||
|
||
var argc = process.argv.length; | ||
if (argc === 3){ | ||
movieTrailer(movie, null, multi, cb); | ||
} else if (!isNaN(parseFloat(process.argv[3])) && isFinite(process.argv[3])){ | ||
movieTrailer(movie, process.argv[3], multi, cb); | ||
} else { | ||
help(); | ||
} | ||
if ( cli.flags.m ) opts.multi = !!cli.flags.m | ||
if ( cli.flags.y ) opts.year = cli.flags.y | ||
if ( !cli.input[0] ) cli.showHelp() | ||
|
||
// Search artist, album and size | ||
// albumArt( cli.input[0], opts ).then( console.log ) | ||
movieTrailer( cli.input[0], opts.year, opts.multi, function (err,res){ | ||
console.log(res) | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters