Skip to content

Commit b9cd545

Browse files
Merge pull request #895 from appwrite/fix-cli-qa
Feat: CLI QA improvements
2 parents 591e07b + 8432002 commit b9cd545

File tree

13 files changed

+484
-420
lines changed

13 files changed

+484
-420
lines changed

composer.lock

Lines changed: 31 additions & 31 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

templates/cli/index.js.twig

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const { login, logout, whoami, migrate, register } = require("./lib/commands/gen
1616
const { init } = require("./lib/commands/init");
1717
const { pull } = require("./lib/commands/pull");
1818
const { run } = require("./lib/commands/run");
19-
const { push } = require("./lib/commands/push");
19+
const { push, deploy } = require("./lib/commands/push");
2020
{% else %}
2121
const { migrate } = require("./lib/commands/generic");
2222
{% endif %}
@@ -67,6 +67,7 @@ program
6767
.addCommand(init)
6868
.addCommand(pull)
6969
.addCommand(push)
70+
.addCommand(deploy)
7071
.addCommand(run)
7172
.addCommand(logout)
7273
{% endif %}

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

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const { Command } = require("commander");
33
const Client = require("../client");
44
const { sdkForConsole } = require("../sdks");
55
const { globalConfig, localConfig } = require("../config");
6-
const { actionRunner, success, parseBool, commandDescriptions, error, parse, log, drawTable, cliConfig } = require("../parser");
6+
const { actionRunner, success, parseBool, commandDescriptions, error, parse, hint, log, drawTable, cliConfig } = require("../parser");
77
const ID = require("../id");
88
{% if sdk.test != "true" %}
99
const { questionsLogin, questionsLogout, questionsListFactors, questionsMfaChallenge } = require("../questions");
@@ -15,8 +15,20 @@ const loginCommand = async ({ email, password, endpoint, mfa, code }) => {
1515
const oldCurrent = globalConfig.getCurrentSession();
1616
let configEndpoint = endpoint ?? DEFAULT_ENDPOINT;
1717

18+
if(globalConfig.getCurrentSession() !== '') {
19+
log('You are currently signed in as ' + globalConfig.getEmail());
20+
21+
if(globalConfig.getSessions().length === 1) {
22+
hint('You can sign in and manage multiple accounts with Appwrite CLI');
23+
}
24+
}
25+
1826
const answers = email && password ? { email, password } : await inquirer.prompt(questionsLogin);
1927

28+
if(!answers.method) {
29+
answers.method = 'login';
30+
}
31+
2032
if (answers.method === 'select') {
2133
const accountId = answers.accountId;
2234

@@ -88,15 +100,15 @@ const loginCommand = async ({ email, password, endpoint, mfa, code }) => {
88100
}
89101
}
90102

91-
success("Signed in as user with ID: " + account.$id);
92-
log("Next you can create or link to your project using 'appwrite init project'");
103+
success("Successfully signed in as " + account.email);
104+
hint("Next you can create or link to your project using 'appwrite init project'");
93105
};
94106

95107
const whoami = new Command("whoami")
96108
.description(commandDescriptions['whoami'])
97109
.action(actionRunner(async () => {
98110
if (globalConfig.getEndpoint() === '' || globalConfig.getCookie() === '') {
99-
error("No user is signed in. To sign in, run: appwrite login ");
111+
error("No user is signed in. To sign in, run 'appwrite login'");
100112
return;
101113
}
102114

@@ -110,7 +122,7 @@ const whoami = new Command("whoami")
110122
parseOutput: false
111123
});
112124
} catch (error) {
113-
error("No user is signed in. To sign in, run: appwrite login");
125+
error("No user is signed in. To sign in, run 'appwrite login'");
114126
return;
115127
}
116128

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

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const { storageCreateBucket } = require("./storage");
99
const { messagingCreateTopic } = require("./messaging");
1010
const { functionsCreate } = require("./functions");
1111
const { databasesCreateCollection } = require("./databases");
12+
const { pullResources } = require("./pull");
1213
const ID = require("../id");
1314
const { localConfig, globalConfig } = require("../config");
1415
const {
@@ -18,10 +19,11 @@ const {
1819
questionsCreateMessagingTopic,
1920
questionsCreateCollection,
2021
questionsInitProject,
22+
questionsInitProjectAutopull,
2123
questionsInitResources,
2224
questionsCreateTeam
2325
} = require("../questions");
24-
const { success, log, error, actionRunner, commandDescriptions } = require("../parser");
26+
const { cliConfig, success, log, hint, error, actionRunner, commandDescriptions } = require("../parser");
2527
const { accountGet } = require("./account");
2628
const { sdkForConsole } = require("../sdks");
2729

@@ -56,7 +58,7 @@ const initProject = async ({ organizationId, projectId, projectName } = {}) => {
5658
sdk: client
5759
});
5860
} catch (e) {
59-
error('Error Session not found. Please run `appwrite login` to create a session');
61+
error("Error Session not found. Please run 'appwrite login' to create a session");
6062
process.exit(1);
6163
}
6264

@@ -104,11 +106,17 @@ const initProject = async ({ organizationId, projectId, projectName } = {}) => {
104106

105107
success(`Project successfully ${answers.start === 'existing' ? 'linked' : 'created'}. Details are now stored in appwrite.json file.`);
106108

107-
log("Next you can use 'appwrite init' to create resources in your project, or use 'appwrite pull' and 'appwite push' to synchronize your project.")
108-
109109
if(answers.start === 'existing') {
110-
log("Since you connected to an existing project, we highly recommend to run 'appwrite pull all' to synchronize all of your existing resources.");
110+
answers = await inquirer.prompt(questionsInitProjectAutopull);
111+
if(answers.autopull) {
112+
cliConfig.all = true;
113+
await pullResources();
114+
} else {
115+
log("You can run 'appwrite pull all' to synchronize all of your existing resources.");
116+
}
111117
}
118+
119+
hint("Next you can use 'appwrite init' to create resources in your project, or use 'appwrite pull' and 'appwrite push' to synchronize your project.")
112120
}
113121

114122
const initBucket = async () => {
@@ -210,22 +218,24 @@ const initFunction = async () => {
210218
log(`Installation command for this runtime not found. You will be asked to configure the install command when you first push the function.`);
211219
}
212220

213-
214221
fs.mkdirSync(functionDir, "777");
215222
fs.mkdirSync(templatesDir, "777");
216223
const repo = "https://github.com/{{ sdk.gitUserName }}/templates";
217224
const api = `https://api.github.com/repos/{{ sdk.gitUserName }}/templates/contents/${answers.runtime.name}`
218-
const templates = ['starter'];
219225
let selected = undefined;
220226

221-
try {
222-
const res = await fetch(api);
223-
templates.push(...(await res.json()).map((template) => template.name));
224-
225-
selected = await inquirer.prompt(questionsCreateFunctionSelectTemplate(templates))
226-
} catch {
227-
// Not a problem will go with directory pulling
228-
log('Loading templates...');
227+
if(answers.template === 'starter') {
228+
selected = { template: 'starter' };
229+
} else {
230+
try {
231+
const res = await fetch(api);
232+
const templates = [];
233+
templates.push(...(await res.json()).map((template) => template.name));
234+
selected = await inquirer.prompt(questionsCreateFunctionSelectTemplate(templates));
235+
} catch {
236+
// Not a problem will go with directory pulling
237+
log('Loading templates...');
238+
}
229239
}
230240

231241
const sparse = (selected ? `${answers.runtime.name}/${selected.template}` : answers.runtime.name).toLowerCase();
@@ -257,6 +267,7 @@ const initFunction = async () => {
257267

258268
fs.rmSync(path.join(templatesDir, ".git"), { recursive: true });
259269
if (!selected) {
270+
const templates = [];
260271
templates.push(...fs.readdirSync(runtimeDir, { withFileTypes: true })
261272
.filter(item => item.isDirectory() && item.name !== 'starter')
262273
.map(dirent => dirent.name));

0 commit comments

Comments
 (0)