Skip to content

Commit 793689e

Browse files
committed
Merge branch 'refs/heads/feat-cli-g2' into feat-create-resources
# Conflicts: # templates/cli/index.js.twig # templates/cli/lib/commands/generic.js.twig
2 parents cd505f3 + 4b3a3e1 commit 793689e

File tree

3 files changed

+49
-5
lines changed

3 files changed

+49
-5
lines changed

templates/cli/index.js.twig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +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");
15-
const { init } = require("./lib/commands/init");
14+
const { login, logout, whoami } = require("./lib/commands/generic");
1615
const { pull } = require("./lib/commands/pull");
1716
const { push } = require("./lib/commands/push");
1817
{% endif %}
@@ -37,6 +36,7 @@ program
3736
})
3837
.showSuggestionAfterError()
3938
{% if sdk.test != "true" %}
39+
.addCommand(whoami)
4040
.addCommand(login)
4141
.addCommand(init)
4242
.addCommand(pull)

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

Lines changed: 45 additions & 3 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, log, parse } = require("../parser");
6+
const { actionRunner, success, parseBool, commandDescriptions, error, 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");
@@ -60,6 +60,47 @@ const loginCommand = async () => {
6060
success("Signed in as user with ID: " + account.$id);
6161
};
6262

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+
63104
const login = new Command("login")
64105
.description(commandDescriptions['login'])
65106
.configureHelp({
@@ -160,10 +201,11 @@ const client = new Command("client")
160201
}));
161202

162203
module.exports = {
163-
{% if sdk.test != "true" %}
204+
{% if sdk.test != "true" %}
164205
loginCommand,
206+
whoami,
165207
login,
166208
logout,
167-
{% endif %}
209+
{% endif %}
168210
client
169211
};

templates/cli/lib/parser.js.twig

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

187188
module.exports = {
189+
drawTable,
188190
parse,
189191
actionRunner,
190192
parseInteger,

0 commit comments

Comments
 (0)