From f5f5ee0709897d0572a61aabbc96fdfd390a97dd Mon Sep 17 00:00:00 2001 From: Jeroen Engels Date: Wed, 30 Mar 2016 21:32:50 +0200 Subject: [PATCH] Add prompt/auto-init when no arguments are given (fixes #10) --- cli.js | 40 +++++++++++++++++++++++++++++++++------- 1 file changed, 33 insertions(+), 7 deletions(-) diff --git a/cli.js b/cli.js index 581bae3..497fe18 100755 --- a/cli.js +++ b/cli.js @@ -5,6 +5,7 @@ var fs = require('fs'); var path = require('path'); var yargs = require('yargs'); +var inquirer = require('inquirer'); var init = require('./lib/init'); var generate = require('./lib/generate'); @@ -83,12 +84,37 @@ function onError(error) { } } -var command = argv._[0]; +function promptForCommand(argv, cb) { + try { + fs.statSync(argv.config); + } catch (error) { // No config file --> first time using the command + return cb('init'); + } -if (command === 'init') { - init(onError); -} else if (command === 'generate') { - startGeneration(argv, onError); -} else if (command === 'add') { - addContribution(argv, onError); + var questions = [{ + type: 'list', + name: 'command', + message: "What do you want to do?", + choices: [{ + name: 'Add a new contributor or add a new contribution type', + value: 'add' + }, { + name: 'Re-generate the contributors list', + value: 'generate' + }], + default: 0 + }]; + inquirer.prompt(questions, function treatAnswers(answers) { + return cb(answers.command); + }); } + +promptForCommand(argv, function (command) { + if (command === 'init') { + init(onError); + } else if (command === 'generate') { + startGeneration(argv, onError); + } else if (command === 'add') { + addContribution(argv, onError); + } +});