Skip to content

Commit

Permalink
feat: Add exit flag
Browse files Browse the repository at this point in the history
Implemented for the following commands: `play`, `stop`, `pause`, `next`, `previous` and `back`.

Example usage from the interactive mode:

```
$ itunes
iTunes: start --exit
$
```

Example usage from outside:

```
$ itunes stop --exit
iTunes:
✔ Stopped playing ♪♬
$
```

Closes #9
  • Loading branch information
mischah committed Jul 20, 2017
1 parent a616bf5 commit 65dc2ea
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 13 deletions.
35 changes: 29 additions & 6 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,17 @@ vorpal
vorpal.find('exit').description('Exit itunes-remote.');

vorpal
.command('play', 'Start playing the current selection')
.command('play', 'Start playing the current selection.')
.alias('start')
.option('-E, --exit', 'exit itunes-remote after executing the command')
.action(function (args, callback) {
var self = this;
var spinner = ora().start();
itunesRemote('play', function (response) {
spinner.stop();
self.log(response);
if (args.options.exit) {
vorpal.execSync('exit');
}
callback();
});
});
Expand Down Expand Up @@ -90,71 +93,91 @@ vorpal

vorpal
.command('stop', 'Stop playing the current selection')
.option('-E, --exit', 'exit itunes-remote after executing the command')
.action(function (args, callback) {
var self = this;
var spinner = ora().start();
itunesRemote('stop', function (response) {
spinner.stop();
self.log(response);
if (args.options.exit) {
vorpal.execSync('exit');
}
callback();
});
});

vorpal
.command('pause', 'Pause playing the current selection')
.option('-E, --exit', 'exit itunes-remote after executing the command')
.action(function (args, callback) {
var self = this;
var spinner = ora().start();
itunesRemote('pause', function (response) {
spinner.stop();
self.log(response);
if (args.options.exit) {
vorpal.execSync('exit');
}
callback();
});
});

vorpal
.command('next', 'Advance to the next track in the current playlist.')
.option('-E, --exit', 'exit itunes-remote after executing the command')
.action(function (args, callback) {
var self = this;
var spinner = ora().start();
itunesRemote('next', function (response) {
spinner.stop();
self.log(response);
if (args.options.exit) {
vorpal.execSync('exit');
}
callback();
});
});

vorpal
.command('previous', 'Return to the previous track in the current playlist.')
.alias('prev')
.option('-E, --exit', 'exit itunes-remote after executing the command')
.action(function (args, callback) {
var self = this;
var spinner = ora().start();
itunesRemote('previous', function (response) {
spinner.stop();
self.log(response);
if (args.options.exit) {
vorpal.execSync('exit');
}
callback();
});
});

vorpal
.command('back', 'Reposition to beginning of current track or go to previous track if already at start of current track.')
.option('-E, --exit', 'exit itunes-remote after executing the command')
.action(function (args, callback) {
var self = this;
var spinner = ora().start();
itunesRemote('back', function (response) {
spinner.stop();
self.log(response);
if (args.options.exit) {
vorpal.execSync('exit');
}
callback();
});
});

vorpal
.command('search <searchterm>', 'Fuzzy search album, artists and songs.')
.option('-A, --albums', 'Limit search to albums.')
.option('-s, --songs', 'Limit search to songs.')
.option('-a, --artists', 'Limit search to artist.')
.option('-d, --dont-play', 'Prevent playing the search result.')
.option('-A, --albums', 'Limit search to albums')
.option('-s, --songs', 'Limit search to songs')
.option('-a, --artists', 'Limit search to artist')
.option('-d, --dont-play', 'Prevent playing the search result')
.action(function (args, callback) {
var self = this;
var spinner = ora('Searching …').start();
Expand Down
13 changes: 6 additions & 7 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,14 @@ iTunes: help
iTunes:
```

But you also can pass command line arguments to quickly start a search with starting the CLI:
**Note:**
You can also pass commands and options from the outside.

```
$ itunes search nicknack -artist
iTunes:
Hold on …
✔ Found songs by ”nicknack“ and generated a temporary playlist
✔ Playing 44 song(s) ♪♬
iTunes:
$ itunes stop --exit
iTunes:
✔ Stopped playing ♪♬
$
```

## Thanks
Expand Down

0 comments on commit 65dc2ea

Please sign in to comment.