Skip to content

Commit 46a1b5e

Browse files
committed
feat(cli): Adding console whoami command
1 parent c91aa21 commit 46a1b5e

File tree

3 files changed

+39
-2
lines changed

3 files changed

+39
-2
lines changed

templates/cli/index.js.twig

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const { version } = require("./package.json");
1111
const { commandDescriptions, cliConfig } = require("./lib/parser");
1212
const { client } = require("./lib/commands/generic");
1313
{% if sdk.test != "true" %}
14-
const { login, logout } = require("./lib/commands/generic");
14+
const { login, logout, whoami } = require("./lib/commands/generic");
1515
const { pull } = require("./lib/commands/pull");
1616
const { push } = require("./lib/commands/push");
1717
{% endif %}
@@ -36,6 +36,7 @@ program
3636
})
3737
.showSuggestionAfterError()
3838
{% if sdk.test != "true" %}
39+
.addCommand(whoami)
3940
.addCommand(login)
4041
.addCommand(pull)
4142
.addCommand(push)

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

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,44 @@ 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, log, parse } = require("../parser");
6+
const { actionRunner, success, parseBool, commandDescriptions, log, parse, drawTable } = require("../parser");
77
{% if sdk.test != "true" %}
88
const { questionsLogin, questionsListFactors, questionsMfaChallenge } = require("../questions");
99
const { accountUpdateMfaChallenge, accountCreateMfaChallenge, accountGet, accountCreateEmailPasswordSession, accountDeleteSession } = require("./account");
1010

11+
const whoami = new Command("whoami")
12+
.description(commandDescriptions['whoami'])
13+
.configureHelp({
14+
helpWidth: process.stdout.columns || 80
15+
})
16+
.action(actionRunner(async () => {
17+
let client = await sdkForConsole(false);
18+
19+
let account;
20+
21+
try {
22+
account = await accountGet({
23+
sdk: client,
24+
parseOutput: false
25+
});
26+
} catch(error) {
27+
throw error;
28+
}
29+
30+
success("Signed in");
31+
32+
const data = [
33+
{
34+
'ID': account.$id,
35+
'Name': account.name,
36+
'Email': account.email,
37+
'MFA enabled': account.mfa
38+
}
39+
];
40+
41+
drawTable(data)
42+
}));
43+
1144
const login = new Command("login")
1245
.description(commandDescriptions['login'])
1346
.configureHelp({
@@ -159,6 +192,7 @@ const client = new Command("client")
159192

160193
module.exports = {
161194
{% if sdk.test != "true" %}
195+
whoami,
162196
login,
163197
logout,
164198
{% endif %}

templates/cli/lib/parser.js.twig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ const commandDescriptions = {
168168
"client": `The client command allows you to configure your CLI`,
169169
"login": `The login command allows you to authenticate and manage a user account.`,
170170
"logout": `The logout command allows you to logout of your {{ spec.title|caseUcfirst }} account.`,
171+
"whoami": `The whoami command gives a basic account information about the logged in user.`,
171172
"console" : `The console command allows gives you access to the APIs used by the Appwrite console.`,
172173
"assistant": `The assistant command allows you to interact with the Appwrite Assistant AI`,
173174
"messaging": `The messaging command allows you to send messages.`,
@@ -184,6 +185,7 @@ const commandDescriptions = {
184185
}
185186

186187
module.exports = {
188+
drawTable,
187189
parse,
188190
actionRunner,
189191
parseInteger,

0 commit comments

Comments
 (0)