Skip to content

Commit a61cb67

Browse files
committed
feat(cli): Adding organization select before selecting the project.
1 parent 36a37b8 commit a61cb67

File tree

1 file changed

+38
-7
lines changed

1 file changed

+38
-7
lines changed

templates/cli/lib/questions.js.twig

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const { localConfig } = require('./config');
22
const { projectsList } = require('./commands/projects');
3+
const { teamsList } = require('./commands/teams');
34
const { functionsListRuntimes } = require('./commands/functions');
45
const { accountListMfaFactors } = require("./commands/account");
56
const { sdkForConsole } = require("./sdks");
@@ -117,6 +118,35 @@ const questionsInitProject = [
117118
return Object.keys(localConfig.getProject()).length !== 0;
118119
}
119120
},
121+
{
122+
type: "list",
123+
name: "organization",
124+
message: "Choose the project Organization",
125+
choices: async () => {
126+
let client = await sdkForConsole(true);
127+
128+
let response = await teamsList({
129+
parseOutput: false,
130+
sdk: client
131+
})
132+
let teams = response["teams"]
133+
let choices = teams.map((team, idx) => {
134+
return {
135+
name: `${team.name} (${team['$id']})`,
136+
value: {
137+
name: team.name,
138+
id: team['$id']
139+
}
140+
}
141+
})
142+
143+
if (choices.length == 0) {
144+
throw new Error("No organizations found. Please create a new organization.")
145+
}
146+
147+
return choices;
148+
}
149+
},
120150
{
121151
type: "list",
122152
name: "start",
@@ -163,9 +193,10 @@ const questionsInitProject = [
163193
when(answers) {
164194
return answers.start == "existing";
165195
},
166-
choices: async () => {
196+
choices: async (answers) => {
167197
let response = await projectsList({
168-
parseOutput: false
198+
parseOutput: false,
199+
queries: [JSON.stringify({ method: 'equal', attribute:'teamId', values: [answers.organization.id] })],
169200
})
170201
let projects = response["projects"]
171202
let choices = projects.map((project, idx) => {
@@ -209,12 +240,12 @@ const questionsInitFunction = [
209240
parseOutput: false
210241
})
211242
let runtimes = response["runtimes"]
212-
let choices = runtimes.map((runtime, idx) => {
243+
let choices = runtimes.map((runtime, idx) => {
213244
return {
214245
name: `${runtime.name} (${runtime['$id']})`,
215-
value: {
216-
id: runtime['$id'],
217-
entrypoint: getEntrypoint(runtime['$id']),
246+
value: {
247+
id: runtime['$id'],
248+
entrypoint: getEntrypoint(runtime['$id']),
218249
ignore: getIgnores(runtime['$id']),
219250
commands : getInstallCommand(runtime['$id'])
220251
},
@@ -403,7 +434,7 @@ const questionsListFactors = [
403434
sdk: client,
404435
parseOutput: false
405436
});
406-
437+
407438
const choices = [
408439
{
409440
name: `TOTP (Time-based One-time Password)`,

0 commit comments

Comments
 (0)