From 36f9af2917d58112850ec8789232881ce2657b81 Mon Sep 17 00:00:00 2001 From: michaelzoidl Date: Fri, 2 Jun 2017 08:53:21 +0200 Subject: [PATCH] add option to pass directly the station via cl --- cli.js | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/cli.js b/cli.js index c723005..debfb3c 100755 --- a/cli.js +++ b/cli.js @@ -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 + + 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(); @@ -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});