Skip to content

Commit 81ded63

Browse files
Merge pull request #853 from appwrite/feat-cli-sudo
Feat cli sudo
2 parents 1251bff + e4483bb commit 81ded63

File tree

6 files changed

+316
-214
lines changed

6 files changed

+316
-214
lines changed

templates/cli/index.js.twig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ program
2929
.version(version, "-v, --version")
3030
.option("--verbose", "Show complete error log")
3131
.option("--json", "Output in JSON format")
32+
.option("-f,--force", "Flag to confirm all warnings")
33+
.option("-a,--all", "Flag to push all resources")
34+
.option("--id [id...]", "Flag to pass list of ids for a giving action")
3235
.option("--report", "Enable reporting in case of CLI errors")
3336
.on("option:json", () => {
3437
cliConfig.json = true;
@@ -40,6 +43,15 @@ program
4043
cliConfig.report = true;
4144
cliConfig.reportData = { data: this };
4245
})
46+
.on("option:force", () => {
47+
cliConfig.force = true;
48+
})
49+
.on("option:all", () => {
50+
cliConfig.all = true;
51+
})
52+
.on("option:id", function() {
53+
cliConfig.ids = this.opts().id;
54+
})
4355
.showSuggestionAfterError()
4456
{% if sdk.test != "true" %}
4557
.addCommand(whoami)

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

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const { storageListBuckets } = require("./storage");
1111
const { localConfig } = require("../config");
1212
const { paginate } = require("../paginate");
1313
const { questionsPullCollection, questionsPullFunctions } = require("../questions");
14-
const { success, log, actionRunner, commandDescriptions } = require("../parser");
14+
const { cliConfig, success, log, actionRunner, commandDescriptions } = require("../parser");
1515

1616
const pullProject = async () => {
1717
try {
@@ -29,10 +29,10 @@ const pullProject = async () => {
2929
}
3030
}
3131

32-
const pullFunctions = async ({ all } = {}) => {
32+
const pullFunctions = async () => {
3333
const localFunctions = localConfig.getFunctions();
3434

35-
const functions = all
35+
const functions = cliConfig.all
3636
? (await paginate(functionsList, { parseOutput: false }, 100, 'functions')).functions
3737
: (await inquirer.prompt(questionsPullFunctions)).functions;
3838

@@ -76,25 +76,18 @@ const pullFunctions = async ({ all } = {}) => {
7676
}
7777
}
7878

79-
const pullCollection = async ({ all, databaseId } = {}) => {
80-
const databaseIds = [];
79+
const pullCollection = async () => {
80+
let databases = cliConfig.ids;
8181

82-
if (databaseId) {
83-
databaseIds.push(databaseId);
84-
} else if (all) {
85-
let allDatabases = await databasesList({
86-
parseOutput: false
87-
})
88-
89-
databaseIds.push(...allDatabases.databases.map((d) => d.$id));
90-
}
91-
92-
if (databaseIds.length <= 0) {
93-
let answers = await inquirer.prompt(questionsPullCollection)
94-
databaseIds.push(...answers.databases);
82+
if (databases.length === 0) {
83+
if (cliConfig.all) {
84+
databases = (await paginate(databasesList, { parseOutput: false }, 100, 'databases')).databases.map(database=>database.$id);
85+
} else{
86+
databases = (await inquirer.prompt(questionsPullCollection)).databases;
87+
}
9588
}
9689

97-
for (const databaseId of databaseIds) {
90+
for (const databaseId of databases) {
9891
const database = await databasesGet({
9992
databaseId,
10093
parseOutput: false
@@ -109,17 +102,18 @@ const pullCollection = async ({ all, databaseId } = {}) => {
109102

110103
log(`Found ${total} collections`);
111104

112-
collections.forEach(async collection => {
105+
collections.map(async collection => {
113106
log(`Fetching ${collection.name} ...`);
114107
localConfig.addCollection({
115108
...collection,
116109
'$createdAt': undefined,
117-
'$updatedAt': undefined,
110+
'$updatedAt': undefined
118111
});
119112
});
113+
114+
success();
120115
}
121116

122-
success();
123117
}
124118

125119
const pullBucket = async () => {
@@ -176,14 +170,11 @@ pull
176170
pull
177171
.command("functions")
178172
.description(`Pulling your {{ spec.title|caseUcfirst }} functions`)
179-
.option(`--all`, `Flag to pull all functions`)
180173
.action(actionRunner(pullFunctions));
181174

182175
pull
183176
.command("collections")
184177
.description("Pulling your {{ spec.title|caseUcfirst }} collections")
185-
.option(`--databaseId <databaseId>`, `Database ID`)
186-
.option(`--all`, `Flag to pull all databases`)
187178
.action(actionRunner(pullCollection))
188179

189180
pull

0 commit comments

Comments
 (0)