Skip to content

Commit 01d7bc5

Browse files
committed
feat(cli): Interactive collection creation
1 parent 05df5dd commit 01d7bc5

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

templates/cli/lib/commands/create.js.twig

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ const inquirer = require("inquirer");
33
const { projectsCreate } = require("./projects");
44
const { storageCreateBucket } = require("./storage");
55
const { messagingCreateTopic } = require("./messaging");
6+
const { databasesCreateCollection } = require("./databases");
67
const { sdkForConsole } = require("../sdks");
78
const { localConfig } = require("../config");
8-
const { questionsCreateProject, questionsCreateBucket, questionsCreateMessagingTopic } = require("../questions");
9+
const { questionsCreateProject, questionsCreateBucket, questionsCreateMessagingTopic, questionsCreateCollection } = require("../questions");
910
const { success, error, actionRunner, commandDescriptions } = require("../parser");
1011

1112
const create = new Command("create")
@@ -55,7 +56,25 @@ const createBucket = async () => {
5556
};
5657

5758
const createCollection = async () => {
59+
let response = {}
60+
const answers = await inquirer.prompt(questionsCreateCollection)
61+
if (!answers.database || !answers.collection || !answers.id || !answers.documentSecurity) process.exit(1)
62+
63+
try {
64+
response = await databasesCreateCollection({
65+
databaseId: answers.database,
66+
collectionId: answers.id,
67+
name: answers.collection,
68+
documentSecurity: answers.documentSecurity.toLowerCase() === 'yes',
69+
enabled: true,
70+
parseOutput: false
71+
})
5872

73+
localConfig.addCollection(response);
74+
success();
75+
} catch (e) {
76+
error(e.getMessage ?? 'Unknown error occurred. Please try again');
77+
}
5978
};
6079

6180
const createTopic = async () => {
@@ -70,7 +89,7 @@ const createTopic = async () => {
7089
parseOutput: false
7190
})
7291

73-
{#localConfig.addMessagingTopic(response);#}
92+
{# localConfig.addMessagingTopic(response); #}
7493
success();
7594
} catch (e) {
7695
error(e.getMessage ?? 'Unknown error occurred. Please try again');

0 commit comments

Comments
 (0)