Daniel Schep d11ff1e316
Allow --app & --org cli option in interactive CLI (#6697)
* Allow plugins to add flags that are allowed during interactive CLI

* simpler return, comment, & move setting sls.interactiveCli

* allow listof starter pr ojects to be customized

* docs!

* lint

* remove return and hide interacive cli "command"

* expose whole initializeService module like aws is

* update copy

* 🤦

* make it easier to update initalizeprojectChoices, avoiding ugly inplace updates

* bump sfe dep

* version bump

* Revert "version bump"

This reverts commit 4c9449136e00ce195b9c119f983845aec26c3693.
2019-10-23 15:52:27 -04:00

71 lines
2.1 KiB
JavaScript

'use strict';
const inquirer = require('./inquirer');
const initializeService = require('./initializeService');
const setupAws = require('./setupAws');
const tabCompletion = require('./tabCompletion');
module.exports = class InteractiveCli {
constructor(serverless) {
this.serverless = serverless;
this.commands = {
interactiveCli: {
isHidden: true,
options: {},
lifecycleEvents: ['initializeService', 'setupAws', 'tabCompletion', 'end'],
},
};
this.hooks = {
'interactiveCli:initializeService': () => {
if (!initializeService.check(serverless)) return null;
process.stdout.write('\n');
return initializeService.run(serverless);
},
'interactiveCli:setupAws': () => {
return setupAws.check(serverless).then(isApplicable => {
if (!isApplicable) return null;
process.stdout.write('\n');
return setupAws.run(serverless);
});
},
'interactiveCli:tabCompletion': () => {
return tabCompletion.check(serverless).then(isApplicable => {
if (!isApplicable) return null;
process.stdout.write('\n');
return tabCompletion.run(serverless);
});
},
};
}
asyncInit() {
/*
* The majority of setup is done here to allow other plugins to modify
* this.commands.interactiveCli.options before deciding if the CLI
* is in interactive mode or not.
*/
if (!process.stdin.isTTY) return;
const { processedInput } = this.serverless;
if (processedInput.commands.length) return;
const options = new Set(Object.keys(processedInput.options));
for (const opt of Object.keys(this.commands.interactiveCli.options)) {
options.delete(opt);
}
if (options.size) return;
// Enforce interactive CLI
processedInput.commands.push('interactiveCli');
// Expose customized inquirer, and setupAws configuration for other plugins
// setupAws is further customized by dashboard plugin
this.serverless.interactiveCli = {
inquirer,
awsSetupConfiguration: setupAws,
initializeServiceConfiguration: initializeService,
};
}
};