Skip to content

Commit

Permalink
refactor: Group play commands for listing in help
Browse files Browse the repository at this point in the history
  • Loading branch information
mischah committed Jul 19, 2017
1 parent 5c1eb89 commit 9a06b70
Showing 1 changed file with 62 additions and 62 deletions.
124 changes: 62 additions & 62 deletions cli.js
Expand Up @@ -37,6 +37,68 @@ vorpal
});
});

vorpal
.command('play artist', 'Plays songs by an artist.')
.action(function (args, callback) {
var self = this;
var getDataIndicator = startWaitingIndicator('getData');

itunesRemote('getData', function (response) {
var artists = [];
stopWaitingIndicator(getDataIndicator);
artists = response.artists;

self.prompt({
type: 'list',
name: 'artist',
message: 'Choose an artist',
choices: artists
}, function (result) {
var selectedArtist = result.artist;
var searchArtistIndicator = startWaitingIndicator();
itunesRemote('search', function (response) {
stopWaitingIndicator(searchArtistIndicator);
self.log(response);
callback();
}, {
searchterm: selectedArtist,
options: {artists: true}
});
});
});
});

vorpal
.command('play album', 'Plays an album.')
.action(function (args, callback) {
var self = this;
var getDataIndicator = startWaitingIndicator('getData');

itunesRemote('getData', function (response) {
var albums = [];
stopWaitingIndicator(getDataIndicator);
albums = response.albums;

self.prompt({
type: 'list',
name: 'album',
message: 'Choose an album',
choices: albums
}, function (result) {
var selectedAlbum = result.album;
var searchAlbumIndicator = startWaitingIndicator();
itunesRemote('search', function (response) {
stopWaitingIndicator(searchAlbumIndicator);
self.log(response);
callback();
}, {
searchterm: selectedAlbum,
options: {albums: true}
});
});
});
});

vorpal
.command('stop', 'Stop playing the current selection')
.action(function (args, callback) {
Expand Down Expand Up @@ -109,66 +171,4 @@ vorpal
}, args);
});

vorpal
.command('play artist', 'Plays songs by an artist.')
.action(function (args, callback) {
var self = this;
var getDataIndicator = startWaitingIndicator('getData');

itunesRemote('getData', function (response) {
var artists = [];
stopWaitingIndicator(getDataIndicator);
artists = response.artists;

self.prompt({
type: 'list',
name: 'artist',
message: 'Choose an artist',
choices: artists
}, function (result) {
var selectedArtist = result.artist;
var searchArtistIndicator = startWaitingIndicator();
itunesRemote('search', function (response) {
stopWaitingIndicator(searchArtistIndicator);
self.log(response);
callback();
}, {
searchterm: selectedArtist,
options: {artists: true}
});
});
});
});

vorpal
.command('play album', 'Plays an album.')
.action(function (args, callback) {
var self = this;
var getDataIndicator = startWaitingIndicator('getData');

itunesRemote('getData', function (response) {
var albums = [];
stopWaitingIndicator(getDataIndicator);
albums = response.albums;

self.prompt({
type: 'list',
name: 'album',
message: 'Choose an album',
choices: albums
}, function (result) {
var selectedAlbum = result.album;
var searchAlbumIndicator = startWaitingIndicator();
itunesRemote('search', function (response) {
stopWaitingIndicator(searchAlbumIndicator);
self.log(response);
callback();
}, {
searchterm: selectedAlbum,
options: {albums: true}
});
});
});
});

vorpal.parse(process.argv);

0 comments on commit 9a06b70

Please sign in to comment.