@@ -3,7 +3,7 @@ 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");
@@ -60,6 +60,47 @@ const loginCommand = async () => {
60
60
success("Signed in as user with ID: " + account.$id);
61
61
};
62
62
63
+ const whoami = new Command("whoami")
64
+ .description(commandDescriptions['whoami'])
65
+ .option("-j, --json", "Output in JSON format")
66
+ .action(actionRunner(async ({ json }) => {
67
+ if (globalConfig.getEndpoint() === '' || globalConfig.getCookie() === '') {
68
+ error("No user is signed in. To sign in, run: appwrite login ");
69
+ return;
70
+ }
71
+
72
+ let client = await sdkForConsole(false);
73
+
74
+ let account;
75
+
76
+ try {
77
+ account = await accountGet({
78
+ sdk: client,
79
+ parseOutput: false
80
+ });
81
+ } catch (error) {
82
+ error("No user is signed in. To sign in, run: appwrite login");
83
+ return;
84
+ }
85
+
86
+ const data = [
87
+ {
88
+ 'ID': account.$id,
89
+ 'Name': account.name,
90
+ 'Email': account.email,
91
+ 'MFA enabled': account.mfa ? 'Yes' : 'No'
92
+ }
93
+ ];
94
+ if (json) {
95
+ console.log(data);
96
+
97
+ return;
98
+ }
99
+
100
+ drawTable(data)
101
+ }));
102
+
103
+
63
104
const login = new Command("login")
64
105
.description(commandDescriptions['login'])
65
106
.configureHelp({
@@ -160,10 +201,11 @@ const client = new Command("client")
160
201
}));
161
202
162
203
module.exports = {
163
- {% if sdk .test != " true" %}
204
+ {% if sdk .test != " true" %}
164
205
loginCommand,
206
+ whoami,
165
207
login,
166
208
logout,
167
- {% endif %}
209
+ {% endif %}
168
210
client
169
211
};
0 commit comments