Skip to content

Commit ee66125

Browse files
committed
refactor(cli): Review refactoring and adding option for json output
1 parent 8c3e359 commit ee66125

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

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

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,10 @@ const { accountUpdateMfaChallenge, accountCreateMfaChallenge, accountGet, accoun
1010

1111
const whoami = new Command("whoami")
1212
.description(commandDescriptions['whoami'])
13-
.configureHelp({
14-
helpWidth: process.stdout.columns || 80
15-
})
16-
.action(actionRunner(async () => {
13+
.option("-j, --json", "Output in JSON format")
14+
.action(actionRunner(async ({ json }) => {
1715
if (globalConfig.getEndpoint() === '' || globalConfig.getCookie() === '') {
18-
error("No user is signed in. Run appwrite login. ..... ");
16+
error("No user is signed in. To sign in, run: appwrite login ");
1917
return;
2018
}
2119

@@ -29,20 +27,23 @@ const whoami = new Command("whoami")
2927
parseOutput: false
3028
});
3129
} catch (error) {
32-
error("No user is signed in");
30+
error("No user is signed in. To sign in, run: appwrite login");
3331
return;
3432
}
3533

36-
success("Signed in");
37-
3834
const data = [
3935
{
4036
'ID': account.$id,
4137
'Name': account.name,
4238
'Email': account.email,
43-
'MFA enabled': account.mfa
39+
'MFA enabled': account.mfa ? 'Yes' : 'No'
4440
}
4541
];
42+
if (json) {
43+
console.log(data);
44+
45+
return;
46+
}
4647

4748
drawTable(data)
4849
}));

0 commit comments

Comments
 (0)