Skip to content

Commit

Permalink
feat(CLI Onboarding): Dont allow setup with options in service dir
Browse files Browse the repository at this point in the history
  • Loading branch information
pgrzesik committed May 14, 2021
1 parent e63302b commit 7e8e1b6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/cli/interactive-setup/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,14 @@ const resolveProjectNameInput = async (options, workingDir) => {
};

module.exports = {
isApplicable({ serviceDir }) {
isApplicable({ options, serviceDir }) {
if (serviceDir && (options.name || options['template-path'])) {
throw new ServerlessError(
'Cannot setup a new service when being in context of another service ("--name" and "--template-path" options cannot be applied)',
'NOT_APPLICABLE_SERVICE_OPTIONS'
);
}

return !serviceDir;
},
async run(context) {
Expand Down
8 changes: 8 additions & 0 deletions test/unit/lib/cli/interactive-setup/service.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ describe('test/unit/lib/cli/interactive-setup/service.test.js', () => {
it('Should be applied, when not at service path', () =>
expect(step.isApplicable({ options: {} })).to.equal(true));

it('Should result in an error when at service path with `template-path` options provided', () => {
expect(() =>
step.isApplicable({ serviceDir: '/foo', options: { 'template-path': 'path/to/template' } })
)
.to.throw()
.and.have.property('code', 'NOT_APPLICABLE_SERVICE_OPTIONS');
});

it("Should abort if user doesn't want setup", async () => {
configureInquirerStub(inquirer, {
confirm: { shouldCreateNewProject: false },
Expand Down

0 comments on commit 7e8e1b6

Please sign in to comment.