Skip to content

Commit

Permalink
🎉 Rewrite CLI for Meow
Browse files Browse the repository at this point in the history
  • Loading branch information
lacymorrow committed Mar 26, 2018
1 parent 2395452 commit ca8a95a
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 42 deletions.
75 changes: 35 additions & 40 deletions cli.js
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)
});
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
"version": "1.0.4",
"description": "Get movie trailer url(s): Oceans Eleven ➔ http://path/to/trailer",
"license": "MIT",
"main": "index.js",
"browser": "index.js",
"repository": {
"type": "git",
"url": "git://github.com/lacymorrow/movie-trailer"
Expand Down Expand Up @@ -43,6 +45,7 @@
"url": "https://github.com/lacymorrow/movie-trailer/issues"
},
"homepage": "https://github.com/lacymorrow/movie-trailer",
"_id": "movie-trailer@1.0.0",
"_from": "movie-trailer@"
"dependencies": {
"meow": "^4.0.0"
}
}

0 comments on commit ca8a95a

Please sign in to comment.