@@ -3,11 +3,51 @@ const { Command } = require("commander");
3
3
const Client = require("../client");
4
4
const { sdkForConsole } = require("../sdks");
5
5
const { globalConfig, localConfig } = require("../config");
6
- const { actionRunner, success, parseBool, commandDescriptions, log , parse } = require("../parser");
6
+ const { actionRunner, success, parseBool, commandDescriptions, error , parse, drawTable } = require("../parser");
7
7
{% if sdk .test != " true" %}
8
8
const { questionsLogin, questionsListFactors, questionsMfaChallenge } = require("../questions");
9
9
const { accountUpdateMfaChallenge, accountCreateMfaChallenge, accountGet, accountCreateEmailPasswordSession, accountDeleteSession } = require("./account");
10
10
11
+ const whoami = new Command("whoami")
12
+ .description(commandDescriptions['whoami'])
13
+ .option("-j, --json", "Output in JSON format")
14
+ .action(actionRunner(async ({ json }) => {
15
+ if (globalConfig.getEndpoint() === '' || globalConfig.getCookie() === '') {
16
+ error("No user is signed in. To sign in, run: appwrite login ");
17
+ return;
18
+ }
19
+
20
+ let client = await sdkForConsole(false);
21
+
22
+ let account;
23
+
24
+ try {
25
+ account = await accountGet({
26
+ sdk: client,
27
+ parseOutput: false
28
+ });
29
+ } catch (error) {
30
+ error("No user is signed in. To sign in, run: appwrite login");
31
+ return;
32
+ }
33
+
34
+ const data = [
35
+ {
36
+ 'ID': account.$id,
37
+ 'Name': account.name,
38
+ 'Email': account.email,
39
+ 'MFA enabled': account.mfa ? 'Yes' : 'No'
40
+ }
41
+ ];
42
+ if (json) {
43
+ console.log(data);
44
+
45
+ return;
46
+ }
47
+
48
+ drawTable(data)
49
+ }));
50
+
11
51
const login = new Command("login")
12
52
.description(commandDescriptions['login'])
13
53
.configureHelp({
@@ -34,7 +74,7 @@ const login = new Command("login")
34
74
sdk: client,
35
75
parseOutput: false
36
76
});
37
- } catch(error) {
77
+ } catch (error) {
38
78
if (error.response === 'user_more_factors_required') {
39
79
const { factor } = await inquirer.prompt(questionsListFactors);
40
80
@@ -158,9 +198,10 @@ const client = new Command("client")
158
198
}));
159
199
160
200
module.exports = {
161
- {% if sdk .test != " true" %}
201
+ {% if sdk .test != " true" %}
202
+ whoami,
162
203
login,
163
204
logout,
164
- {% endif %}
205
+ {% endif %}
165
206
client
166
207
};
0 commit comments