Skip to content

Commit 75a01c8

Browse files
committed
feat(cli): Interactive bucket creation
1 parent 2029e8a commit 75a01c8

File tree

1 file changed

+57
-2
lines changed

1 file changed

+57
-2
lines changed

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

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
const { Command } = require("commander");
22
const inquirer = require("inquirer");
33
const { projectsCreate } = require("./projects");
4+
const { storageCreateBucket } = require("./storage");
45
const { sdkForConsole } = require("../sdks");
56
const { localConfig } = require("../config");
6-
const { questionsCreateProject } = require("../questions");
7-
const { success, actionRunner, commandDescriptions } = require("../parser");
7+
const { questionsCreateProject, questionsCreateBucket } = require("../questions");
8+
const { success, error, actionRunner, commandDescriptions } = require("../parser");
89

910
const create = new Command("create")
1011
.description(commandDescriptions['create'])
@@ -31,11 +32,65 @@ const createProject = async () => {
3132
success();
3233
}
3334

35+
36+
const createBucket = async () => {
37+
let response = {}
38+
const answers = await inquirer.prompt(questionsCreateBucket)
39+
if (!answers.bucket || !answers.id || !answers.fileSecurity) process.exit(1)
40+
41+
try {
42+
response = await storageCreateBucket({
43+
bucketId: answers.id,
44+
name: answers.bucket,
45+
fileSecurity: answers.fileSecurity.toLowerCase() === 'yes',
46+
enabled: true,
47+
parseOutput: false
48+
})
49+
50+
localConfig.addBucket(response);
51+
success();
52+
} catch (e) {
53+
error(e.getMessage ?? 'Unknown error occurred. Please try again');
54+
}
55+
};
56+
57+
const createFunction = async () => {
58+
59+
};
60+
61+
const createCollection = async () => {
62+
63+
};
64+
65+
const createTopic = async () => {
66+
67+
};
68+
3469
create
3570
.command("project")
3671
.description("Create a new {{ spec.title|caseUcfirst }} project")
3772
.action(actionRunner(createProject));
3873

74+
create
75+
.command("function")
76+
.description("Create a new {{ spec.title|caseUcfirst }} function")
77+
.action(actionRunner(createFunction));
78+
79+
create
80+
.command("bucket")
81+
.description("Create a new {{ spec.title|caseUcfirst }} bucket")
82+
.action(actionRunner(createBucket));
83+
84+
create
85+
.command("collection")
86+
.description("Create a new {{ spec.title|caseUcfirst }} collection")
87+
.action(actionRunner(createCollection));
88+
89+
create
90+
.command("topic")
91+
.description("Create a new {{ spec.title|caseUcfirst }} topic")
92+
.action(actionRunner(createTopic));
93+
3994
module.exports = {
4095
create,
4196
};

0 commit comments

Comments
 (0)