Skip to content

Commit 3cee4c1

Browse files
Merge pull request #840 from appwrite/feat-organization-support
Feat organization support
2 parents 9276294 + 31a7560 commit 3cee4c1

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

templates/cli/lib/questions.js.twig

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
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");
67
const { validateRequired } = require("./validations");
8+
const { paginate } = require('./paginate');
79

810
const { databasesList } = require('./commands/databases');
911
const JSONbig = require("json-bigint")({ storeAsString: false });
@@ -118,6 +120,31 @@ const questionsPullProject = [
118120
return Object.keys(localConfig.getProject()).length !== 0;
119121
}
120122
},
123+
{
124+
type: "list",
125+
name: "organization",
126+
message: "Choose the project organization",
127+
choices: async () => {
128+
let client = await sdkForConsole(true);
129+
const { teams } = await paginate(teamsList, { parseOutput: false , sdk: client}, 100, 'teams');
130+
131+
let choices = teams.map((team, idx) => {
132+
return {
133+
name: `${team.name} (${team['$id']})`,
134+
value: {
135+
name: team.name,
136+
id: team['$id']
137+
}
138+
}
139+
})
140+
141+
if (choices.length == 0) {
142+
throw new Error("No organizations found. Please create a new organization.")
143+
}
144+
145+
return choices;
146+
}
147+
},
121148
{
122149
type: "list",
123150
name: "start",
@@ -164,9 +191,10 @@ const questionsPullProject = [
164191
when(answers) {
165192
return answers.start == "existing";
166193
},
167-
choices: async () => {
194+
choices: async (answers) => {
168195
let response = await projectsList({
169-
parseOutput: false
196+
parseOutput: false,
197+
queries: [JSON.stringify({ method: 'equal', attribute:'teamId', values: [answers.organization.id] })],
170198
})
171199
let projects = response["projects"]
172200
let choices = projects.map((project, idx) => {

0 commit comments

Comments
 (0)