UNPKG

1.82 kBJavaScriptView Raw
1/**
2 * Copyright (c) 2018, Kinvey, Inc. All rights reserved.
3 *
4 * This software is licensed to you under the Kinvey terms of service located at
5 * http://www.kinvey.com/terms-of-use. By downloading, accessing and/or using this
6 * software, you hereby accept such terms of service (and any agreement referenced
7 * therein) and agree that you have read, understand and agree to be bound by such
8 * terms of service and are of legal age to agree to such terms with Kinvey.
9 *
10 * This software contains valuable confidential and proprietary information of
11 * KINVEY, INC and is subject to applicable licensing agreements.
12 * Unauthorized reproduction, transmission or distribution of this file and its
13 * contents is a violation of applicable laws.
14 */
15
16const { PromptTypes } = require('./Constants');
17
18class BaseController {
19 constructor({ cliManager, exporter }) {
20 this.cliManager = cliManager;
21 this.exporter = exporter;
22 }
23
24 getActiveOrSpecifiedIdentifier(activeItemName, optionName, cmdOptions) {
25 const active = this.cliManager.getActiveItem(activeItemName);
26 const wanted = cmdOptions[optionName] || (active && active.id);
27 return wanted;
28 }
29
30 confirmDeleteOperation(noPrompt, entityType, identifier, done) {
31 if (noPrompt) {
32 return setImmediate(done);
33 }
34
35 const msg = `Are you sure you want to delete ${entityType} with identifier '${identifier}'?`;
36 const q = this.cliManager.prompter.buildQuestion(msg, 'confirmDelete', PromptTypes.CONFIRM, true);
37 this.cliManager.prompter.prompt(q, (err, data) => {
38 if (err) {
39 return done(err);
40 }
41
42 if (!data.confirmDelete) {
43 return done(new Error('Delete cancelled by user.'));
44 }
45
46 done();
47 });
48 }
49}
50
51module.exports = BaseController;