Skip to content

Commit

Permalink
add option to pass directly the station via cl
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelzoidl committed Jun 2, 2017
1 parent 13e92fd commit 36f9af2
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,30 @@ const inquirer = require('inquirer');
const updateNotifier = require('update-notifier');
const {green} = require('chalk');
const taskler = require('taskler');
const meow = require('meow');
const pkg = require('./package.json');

updateNotifier({pkg}).notify();

const cli = meow(`
Usage
$ takeoff <station>
Example
$ takeoff node-module
`);

const {getPredefinedStations, getCustomStations, loadStationByName} = require('./lib/station');
const {createFilesByList} = require('./lib/wizard');

const getStationId = stations => new Promise(resolve => {
if (cli.input.length === 0) {
inquirer.prompt(stations).then(({stationId}) => resolve(stationId));
} else {
resolve(stations[0].choices.find(({name}) => name === cli.input[0]).value);
}
});

(async () => {
try {
const predefinedStations = await getPredefinedStations();
Expand All @@ -31,7 +48,8 @@ const {createFilesByList} = require('./lib/wizard');
.concat(customStations)
}];

const {stationId} = await inquirer.prompt(chooseBetweenAvailableStations);
const stationId = await getStationId(chooseBetweenAvailableStations);

const {name, type} = stationsCollection.find(({value}) => value === stationId);

const station = await loadStationByName({name, type});
Expand Down

0 comments on commit 36f9af2

Please sign in to comment.