Skip to content

Commit d09b929

Browse files
authored
Merge pull request #147 from appwrite/feat-cli-issue-fixes
feat: fix cli issues
2 parents af26a6b + 1e33dfe commit d09b929

File tree

11 files changed

+77
-54
lines changed

11 files changed

+77
-54
lines changed

src/SDK/Language/CLI.php

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -172,18 +172,6 @@ public function getFiles()
172172
'template' => '/cli/bin/client.twig',
173173
'minify' => false,
174174
],
175-
[
176-
'scope' => 'default',
177-
'destination' => '/install.sh',
178-
'template' => '/cli/install.sh.twig',
179-
'minify' => false,
180-
],
181-
[
182-
'scope' => 'default',
183-
'destination' => '/install.ps1',
184-
'template' => '/cli/install.ps1.twig',
185-
'minify' => false,
186-
],
187175
[
188176
'scope' => 'default',
189177
'destination' => '/bin/help',
@@ -204,25 +192,25 @@ public function getFiles()
204192
],
205193
[
206194
'scope' => 'service',
207-
'destination' => '/app/{{ spec.title | caseUcfirst}}/Services/{{service.name | caseDash}}.php',
195+
'destination' => '/app/{{ spec.title | caseUcfirst}}/services/{{service.name | caseDash}}.php',
208196
'template' => '/cli/app/services/service.php.twig',
209197
'minify' => false,
210198
],
211199
[
212200
'scope' => 'default',
213-
'destination' => 'app/{{ spec.title | caseUcfirst}}/Services/client.php',
201+
'destination' => 'app/{{ spec.title | caseUcfirst}}/services/client.php',
214202
'template' => '/cli/app/services/client.php.twig',
215203
'minify' => false,
216204
],
217205
[
218206
'scope' => 'default',
219-
'destination' => 'app/{{ spec.title | caseUcfirst}}/Services/help.php',
207+
'destination' => 'app/{{ spec.title | caseUcfirst}}/services/help.php',
220208
'template' => '/cli/app/services/help.php.twig',
221209
'minify' => false,
222210
],
223211
[
224212
'scope' => 'default',
225-
'destination' => 'app/{{ spec.title | caseUcfirst}}/Services/init.php',
213+
'destination' => 'app/{{ spec.title | caseUcfirst}}/services/init.php',
226214
'template' => '/cli/app/services/init.php.twig',
227215
'minify' => false,
228216
],
@@ -232,6 +220,18 @@ public function getFiles()
232220
'template' => '/cli/.travis.yml.twig',
233221
'minify' => false,
234222
],
223+
[
224+
'scope' => 'default',
225+
'destination' => '/install.sh',
226+
'template' => '/cli/install.sh.twig',
227+
'minify' => false,
228+
],
229+
[
230+
'scope' => 'default',
231+
'destination' => '/install.ps1',
232+
'template' => '/cli/install.ps1.twig',
233+
'minify' => false,
234+
],
235235
];
236236
}
237237

templates/cli/README.md.twig

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,21 +43,23 @@ $ {{ language.params.executableName }} init
4343

4444
The CLI requires an endpoint, project ID, API key and a locale to be able to communicate with the {{ spec.title | caseUcfirst }} backend server. There are two ways to achieve this
4545

46-
### 1. Environment file
47-
```sh
48-
$ {{ language.params.executableName }} --env-file path/to/your/environment/file init
49-
```
50-
The .env file must have the following keys
46+
### 1. Pass in the project settings along with `appwrite init`
47+
5148
```sh
52-
endpoint=http://192.168.1.6/v1
53-
X-{{ spec.title | caseUcfirst }}-Project=5ff450422d42f
54-
X-{{ spec.title | caseUcfirst }}-Key=0773c7...a2672a
55-
X-{{ spec.title | caseUcfirst }}-Locale=en-US
49+
$ {{ language.params.executableName }} init --endpoint="YOUR ENDPOINT" --project="YOUR PROJECT ID" --key="YOUR API KEY" --locale="YOUR LOCALE"
5650
```
5751

52+
If any of the required values are missing, a prompt will show up, asking for those missing values.
53+
5854
### 2. Using the prompt
5955

60-
Invoking `{{ language.params.executableName }} init` without an env file triggers an interactive prompt where you can manually enter the details. These values are saved locally so that you dont have to re-enter them everytime.
56+
Invoking `{{ language.params.executableName }} init` without any params triggers an interactive prompt where you can manually enter the details. These values are saved locally so that you dont have to re-enter them everytime.
57+
58+
### Note
59+
By default, requests to domains with self signed SSL certificates (or no certificates) are disabled. If you trust the domain, you can bypass the certificate validation by using
60+
```sh
61+
$ appwrite client setSelfSigned --value=true
62+
```
6163

6264
## Usage
6365

templates/cli/app/services/client.php.twig

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,21 @@ $cli
3939
->task('setEndpoint')
4040
->param('endpoint', '', new Mock(), 'Your {{ spec.title | title }} endpoint', false)
4141
->action(function($endpoint) use ($client) {
42-
$client->setPreference('endpoint', $endpoint);
43-
$result = $client->savePreferences();
42+
$result = $client->setPreference('endpoint', $endpoint)
43+
->savePreferences();
44+
if ($result === false) {
45+
Console::error('❌ Could not save preferences.');
46+
} else {
47+
Console::success('✅ Preferences saved successfully');
48+
}
49+
});
50+
51+
$cli
52+
->task('setSelfSigned')
53+
->param('value', '', new Mock(), 'A boolean representing whether you are using a self signed certificate', false)
54+
->action(function($value) use ($client) {
55+
$result = $client->setPreference('selfSigned', $value)
56+
->savePreferences();
4457
if ($result === false) {
4558
Console::error('❌ Could not save preferences.');
4659
} else {
@@ -54,8 +67,8 @@ $cli
5467
->task('set{{ header.key }}')
5568
->param('{{ header.key | lower }}', '', new Mock(), '{{ header.description }}', false)
5669
->action(function(${{ header.key | lower }}) use ($client) {
57-
$client->setPreference('{{ header.name }}', ${{ header.key | lower }});
58-
$result = $client->savePreferences();
70+
$result = $client->setPreference('{{ header.name }}', ${{ header.key | lower }})
71+
->savePreferences();
5972
if ($result === false) {
6073
Console::error('❌ Could not save preferences.');
6174
} else {
@@ -83,7 +96,9 @@ $cli
8396
"setEndpoint" => "Set your server endpoint.",
8497
"setProject" => "Set the project you want to connect to.",
8598
"setKey" => "Set the API key for the project.",
86-
"setLocale" => "Set your preferred locale (eg: en-US)."
99+
"setLocale" => "Set your preferred locale (eg: en-US).",
100+
"setSelfSigned" => "Set whether you are using a self signed certificate",
101+
"version" => "Get the current cli version"
87102
];
88103
$parser->formatArray($commands);
89104
Console::log("\nRun '{{ language.params.executableName }} client COMMAND --help' for more information on a command.");

templates/cli/app/services/service.php.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ $cli
4242
{% for parameter in method.parameters.all %}
4343
->param('{{ parameter.name }}', {{ parameter | paramDefault }} , new Mock(), '{{ parameter.description}}', {% if not parameter.required %} true{% else %} false{% endif %})
4444
{% endfor %}
45-
->action(function ({% for parameter in method.parameters.all %} ${{ parameter.name}}{% if not loop.last %},{% endif %}{% endfor %} ) use ($parser) {
45+
->action(function ({% for parameter in method.parameters.all %} ${{ parameter.name}}{% if not loop.last %},{% endif %}{% endfor %} ) use ($parser) {
4646
$client = new Client();
4747
$path = str_replace([{% for parameter in method.parameters.path %}'{{ '{' }}{{ parameter.name | caseCamel }}{{ '}' }}'{% if not loop.last %}, {% endif %}{% endfor %}], [{% for parameter in method.parameters.path %}${{ parameter.name | caseCamel }}{% if not loop.last %}, {% endif %}{% endfor %}], '{{ method.path }}');
4848
$params = [];

templates/cli/bin/client.twig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/sh
22

3-
if [[ -z "$@" ]]; then
4-
php /usr/local/code/app/{{ spec.title | caseUcfirst}}/Services/client.php help
3+
if [[ $# -eq 0 ]]; then
4+
php /usr/local/code/app/{{ spec.title | caseUcfirst}}/services/client.php help
55
else
6-
php /usr/local/code/app/{{ spec.title | caseUcfirst}}/Services/client.php $@
6+
php /usr/local/code/app/{{ spec.title | caseUcfirst}}/services/client.php $@
77
fi

templates/cli/bin/help.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#!/bin/sh
22

3-
php /usr/local/code/app/{{ spec.title | caseUcfirst}}/Services/help.php $@
3+
php /usr/local/code/app/{{ spec.title | caseUcfirst}}/services/help.php $@

templates/cli/bin/init.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#!/bin/sh
22

3-
php /usr/local/code/app/{{ spec.title | caseUcfirst}}/Services/init.php init $@
3+
php /usr/local/code/app/{{ spec.title | caseUcfirst}}/services/init.php init $@

templates/cli/bin/service.twig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/sh
22

3-
if [[ -z "$@" ]]; then
4-
php /usr/local/code/app/{{ spec.title | caseUcfirst}}/Services/{{service.name | caseDash}}.php help
3+
if [[ $# -eq 0 ]]; then
4+
php /usr/local/code/app/{{ spec.title | caseUcfirst}}/services/{{service.name | caseDash}}.php help
55
else
6-
php /usr/local/code/app/{{ spec.title | caseUcfirst}}/Services/{{service.name | caseDash}}.php $@
6+
php /usr/local/code/app/{{ spec.title | caseUcfirst}}/services/{{service.name | caseDash}}.php $@
77
fi

templates/cli/bin/version.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#!/bin/sh
22

3-
php /usr/local/code/app/{{ spec.title | caseUcfirst}}/Services/client.php version
3+
php /usr/local/code/app/{{ spec.title | caseUcfirst}}/services/client.php version

templates/cli/install.sh.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ if [[ -z $1 ]]; then
125125
set -- "$@" help
126126
fi
127127
128-
# Check if the command is in the whitelist
128+
# Check if the command is in the allowList
129129
if [[ ! " ${allowList[@]} " =~ " ${1} " ]]; then
130130
printf "\nLooks like a crazy hamster 🐹 flipped a bit.\n\nUse {{ language.params.executableName }} help for a list of supported commands.\n"
131131
exit 1

0 commit comments

Comments
 (0)