Skip to content

Commit feb6d75

Browse files
authored
Merge pull request #155 from appwrite/feat-cli-issue-fixes
feat: added wildcard param to cli
2 parents 5f9dfb3 + 59c4310 commit feb6d75

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ require_once './vendor/autoload.php';
66
77
use {{ spec.title | caseUcfirst }}\Client;
88
use Utopia\CLI\CLI;
9-
use Utopia\Validator\Mock;
9+
use Utopia\Validator\Wildcard;
1010
use Utopia\CLI\Console;
1111
use {{ spec.title | caseUcfirst }}\Parser;
1212
@@ -37,7 +37,7 @@ $cli->
3737
3838
$cli
3939
->task('setEndpoint')
40-
->param('endpoint', '', new Mock(), 'Your {{ spec.title | title }} endpoint', false)
40+
->param('endpoint', '', new Wildcard(), 'Your {{ spec.title | title }} endpoint', false)
4141
->action(function($endpoint) use ($client) {
4242
$result = $client->setPreference('endpoint', $endpoint)
4343
->savePreferences();
@@ -50,7 +50,7 @@ $cli
5050
5151
$cli
5252
->task('setSelfSigned')
53-
->param('value', '', new Mock(), 'A boolean representing whether you are using a self signed certificate', false)
53+
->param('value', '', new Wildcard(), 'A boolean representing whether you are using a self signed certificate', false)
5454
->action(function($value) use ($client) {
5555
$result = $client->setPreference('selfSigned', $value)
5656
->savePreferences();
@@ -65,7 +65,7 @@ $cli
6565
{% for header in spec.global.headers %}
6666
$cli
6767
->task('set{{ header.key }}')
68-
->param('{{ header.key | lower }}', '', new Mock(), '{{ header.description }}', false)
68+
->param('{{ header.key | lower }}', '', new Wildcard(), '{{ header.description }}', false)
6969
->action(function(${{ header.key | lower }}) use ($client) {
7070
$result = $client->setPreference('{{ header.name }}', ${{ header.key | lower }})
7171
->savePreferences();

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ require_once './vendor/autoload.php';
66
77
use Exception;
88
use Utopia\CLI\CLI;
9-
use Utopia\Validator\Mock;
9+
use Utopia\Validator\Wildcard;
1010
use Utopia\CLI\Console;
1111
use {{ spec.title | caseUcfirst }}\Parser;
1212
@@ -168,9 +168,9 @@ $cli->
168168
$cli
169169
->task('init')
170170
->label('description', "The init command is used to initialise your CLI\n")
171-
->param('endpoint', '', new Mock(), 'Your {{ spec.title | caseUcfirst }} endpoint', true)
171+
->param('endpoint', '', new Wildcard(), 'Your {{ spec.title | caseUcfirst }} endpoint', true)
172172
{% for header in spec.global.headers %}
173-
->param('{{ header.key | lower }}', '', new Mock(), '{{ header.description }}', true)
173+
->param('{{ header.key | lower }}', '', new Wildcard(), '{{ header.description }}', true)
174174
{% endfor %}
175175
->action(function( $endpoint, {% for header in spec.global.headers %} ${{ header.key | lower }}{% if not loop.last %},{% endif %}{% endfor %} ) {
176176
/* Check if enviroment variables exist

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use {{ spec.title | caseUcfirst }}\Client;
99
use {{ spec.title | caseUcfirst }}\Parser;
1010
use Utopia\CLI\CLI;
1111
use Utopia\CLI\Console;
12-
use Utopia\Validator\Mock;
12+
use Utopia\Validator\Wildcard;
1313
1414
$parser = new Parser();
1515
$cli = new CLI();
@@ -40,9 +40,12 @@ $cli
4040
->task('{{ method.name | caseCamel }}')
4141
->label('description', "{{ method.description | replace({'"':'\''}) | raw }}\n\n")
4242
{% for parameter in method.parameters.all %}
43-
->param('{{ parameter.name }}', {{ parameter | paramDefault }} , new Mock(), '{{ parameter.description}}', {% if not parameter.required %} true{% else %} false{% endif %})
43+
->param('{{ parameter.name }}', {{ parameter | paramDefault }} , new Wildcard() , '{{ parameter.description}}', {% if not parameter.required %} true{% else %} false{% endif %})
44+
{% endfor %}
45+
->action(function ({% for parameter in method.parameters.all %} ${{ parameter.name}}{% if not loop.last %},{% endif %}{% endfor %} ) use ($parser) {
46+
{% for parameter in method.parameters.all %}
47+
/** @var {{ parameter.type }} ${{ parameter.name }} */
4448
{% endfor %}
45-
->action(function ({% for parameter in method.parameters.all %} ${{ parameter.name}}{% if not loop.last %},{% endif %}{% endfor %} ) use ($parser) {
4649
$client = new Client();
4750
$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 }}');
4851
$params = [];
@@ -71,7 +74,7 @@ $cli
7174
$cFile = new \CURLFile(${{ parameter.name | caseCamel }}, {% if method.packaging %} 'application/x-gzip' {% else %} 'image/png' {% endif %}, basename(${{ parameter.name | caseCamel }}));
7275
$params['{{ parameter.name }}'] = $cFile;
7376
{% else %}
74-
$params['{{ parameter.name }}'] = ${{ parameter.name | caseCamel }};
77+
$params['{{ parameter.name }}'] = {% if parameter.type == 'integer' %}(int){% endif %} ${{ parameter.name | caseCamel }};
7578
{% endif %}
7679
{% endfor %}
7780
{% for parameter in method.parameters.formData %}

0 commit comments

Comments
 (0)