Skip to content

Commit 69c5d66

Browse files
committed
Merge branch 'feat-cli-g2' into feat-cli-sudo
2 parents 60b73a2 + acbec0b commit 69c5d66

File tree

5 files changed

+100
-9
lines changed

5 files changed

+100
-9
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: CLI beta Publish
2+
on:
3+
pull_request:
4+
paths:
5+
- 'templates/cli/**.twig'
6+
- 'src/SDK/Language/CLI.php'
7+
8+
env:
9+
PACKAGE_NAME: "${{ vars.PACKAGE_NAME }}@0.16.0${{ github.event.pull_request.head.sha }}"
10+
11+
jobs:
12+
publish:
13+
environment: cli-testing
14+
permissions:
15+
contents: write
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: Checkout repo
19+
uses: actions/checkout@v3
20+
- name: Setup Composer dependencies
21+
run: docker run --rm --volume "$(pwd)":/app composer install --ignore-platform-reqs
22+
- name: Generate SDKS
23+
run: docker run --rm -v "$(pwd)":/app -w /app php:8.1-cli php example.php
24+
- name: Fix permission
25+
run: sudo chown -R 1001:1001 examples
26+
- name: Setup Node
27+
uses: actions/setup-node@v4
28+
with:
29+
node-version: 'latest'
30+
registry-url: 'https://registry.npmjs.org'
31+
- name: Setup
32+
working-directory: ./examples/cli/
33+
run: npm install
34+
- name: Set version
35+
working-directory: ./examples/cli/
36+
run: |
37+
sed -i "s#appwrite-cli#${{ vars.PACKAGE_NAME }}#g" package.json
38+
sed -i "s#0.16.0#0.16.0${{ github.event.pull_request.head.sha }}#g" package.json
39+
- name: Publish
40+
working-directory: examples/cli/
41+
run: npm publish --access public
42+
env:
43+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
44+
- name: Instruction
45+
run: |
46+
echo "Install it by running npm install ${{ env.PACKAGE_NAME }}"
47+
echo "Run it using npx ${{ env.PACKAGE_NAME }}"

example.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ function getSSLPage($url) {
186186
->setTwitter('appwrite_io')
187187
->setDiscord('564160730845151244', 'https://appwrite.io/discord')
188188
->setDefaultHeaders([
189-
'X-Appwrite-Response-Format' => '0.15.0',
189+
'X-Appwrite-Response-Format' => '1.5.0',
190190
])
191191
;
192192

@@ -393,7 +393,7 @@ function getSSLPage($url) {
393393
;
394394

395395
$sdk->generate(__DIR__ . '/examples/apple');
396-
396+
397397
// DotNet
398398
$sdk = new SDK(new DotNet(), new Swagger2($spec));
399399

@@ -442,7 +442,7 @@ function getSSLPage($url) {
442442
// Android
443443

444444
$sdk = new SDK(new Android(), new Swagger2($spec));
445-
445+
446446
$sdk
447447
->setName('Android')
448448
->setNamespace('io appwrite')
@@ -466,7 +466,7 @@ function getSSLPage($url) {
466466

467467
// Kotlin
468468
$sdk = new SDK(new Kotlin(), new Swagger2($spec));
469-
469+
470470
$sdk
471471
->setName('Kotlin')
472472
->setNamespace('io appwrite')

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 %}
@@ -53,6 +53,7 @@ program
5353
})
5454
.showSuggestionAfterError()
5555
{% if sdk.test != "true" %}
56+
.addCommand(whoami)
5657
.addCommand(login)
5758
.addCommand(pull)
5859
.addCommand(push)

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

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,51 @@ 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");
1010

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+
1151
const login = new Command("login")
1252
.description(commandDescriptions['login'])
1353
.configureHelp({
@@ -34,7 +74,7 @@ const login = new Command("login")
3474
sdk: client,
3575
parseOutput: false
3676
});
37-
} catch(error) {
77+
} catch (error) {
3878
if (error.response === 'user_more_factors_required') {
3979
const { factor } = await inquirer.prompt(questionsListFactors);
4080

@@ -158,9 +198,10 @@ const client = new Command("client")
158198
}));
159199

160200
module.exports = {
161-
{% if sdk.test != "true" %}
201+
{% if sdk.test != "true" %}
202+
whoami,
162203
login,
163204
logout,
164-
{% endif %}
205+
{% endif %}
165206
client
166207
};

templates/cli/lib/parser.js.twig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ const commandDescriptions = {
208208
"client": `The client command allows you to configure your CLI`,
209209
"login": `The login command allows you to authenticate and manage a user account.`,
210210
"logout": `The logout command allows you to logout of your {{ spec.title|caseUcfirst }} account.`,
211+
"whoami": `The whoami command gives information about the currently logged in user.`,
211212
"console" : `The console command allows gives you access to the APIs used by the Appwrite console.`,
212213
"assistant": `The assistant command allows you to interact with the Appwrite Assistant AI`,
213214
"messaging": `The messaging command allows you to send messages.`,
@@ -224,6 +225,7 @@ const commandDescriptions = {
224225
}
225226

226227
module.exports = {
228+
drawTable,
227229
parse,
228230
actionRunner,
229231
parseInteger,

0 commit comments

Comments
 (0)