Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added convenience methods plan.options() and plan.hosts() #132

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,37 @@ Flightplan.prototype.availableTargets = function() {
return Object.keys(this._targets);
};

/**
* Convenience method to allow easier access to runtime options
*
* ```javascript
* plan.options(); // get all options
* plan.options('myOption'); // get one specific option
* ```
*
* @method options(key)
*/
Flightplan.prototype.options = function(key) {
if(typeof key === 'undefined') {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please replace with !key.

return this.runtime.options;
}
return this.runtime.options && this.runtime.options[key];
};

/**
* Convenience method to allow easier access to runtime hosts
*
* ```javascript
* plan.hosts();
* plan.hosts(0);
* ```
*
* @method hosts([index])
*/
Flightplan.prototype.hosts = function(index) {
return typeof index === 'number' ? this.runtime.hosts[index] : this.runtime.hosts;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above, there's no need to check whether this is a number or another type.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if the user presses Enter?

var hostKey = transfer.prompt('Which host?');
var host = plan.hosts(hostKey);

};

Flightplan.prototype.availableTasks = function() {
return this._flights.reduce(function(result, f) {
f.tasks.forEach(function(task) {
Expand Down