Skip to content

Commit d4f2428

Browse files
authored
Merge pull request #913 from appwrite/improve-cli-qa
Improving CLI 2.0 qa
2 parents e703a73 + d366a01 commit d4f2428

File tree

10 files changed

+249
-94
lines changed

10 files changed

+249
-94
lines changed

src/SDK/Language/CLI.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Appwrite\SDK\Language;
44

5+
use Twig\TwigFilter;
56
use Twig\TwigFunction;
67

78
class CLI extends Node
@@ -364,6 +365,14 @@ public function getParamExample(array $param): string
364365
return $output;
365366
}
366367

368+
public function getFilters(): array
369+
{
370+
return array_merge(parent::getFilters(), [
371+
new TwigFilter('caseKebab', function ($value) {
372+
return strtolower(preg_replace('/(?<!^)([A-Z][a-z]|(?<=[a-z])[^a-z]|(?<=[A-Z])[0-9_])/', '-$1', $value));
373+
})
374+
]);
375+
}
367376
/**
368377
* Language specific filters.
369378
* @return array

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,11 @@ const {{ service.name | caseLower }}{{ method.name | caseUcfirst }} = async ({
8686
{% endfor %}
8787
{% for method in service.methods %}
8888
{{service.name | caseLower }}
89-
.command(`{{ method.name | caseCamel }}`)
89+
.command(`{{ method.name | caseKebab }}`)
9090
{% autoescape false %}
9191
.description(`{{ method.description | replace({'`':'\''}) | replace({'\n':' '}) | replace({'\n \n':' '}) }}`)
9292
{% for parameter in method.parameters.all %}
93-
.{% if parameter.required and not parameter.nullable %}requiredOption{% else %}option{% endif %}(`--{{ parameter.name | escapeKeyword }} {% if parameter.array.type|length > 0 %}[{% else %}<{% endif %}{{ parameter.name | escapeKeyword }}{% if parameter.array.type|length > 0 %}...{% endif %}{% if parameter.array.type|length > 0 %}]{% else %}>{% endif %}`, `{{ parameter.description | replace({'`':'\''}) | replace({'\n':' '}) | replace({'\n \n':' '}) }}`{% if parameter | typeName == 'boolean' %}, parseBool{% elseif parameter | typeName == 'number' %}, parseInteger{% endif %})
93+
.{% if parameter.required and not parameter.nullable %}requiredOption{% else %}option{% endif %}(`--{{ parameter.name | escapeKeyword | caseKebab }} {% if parameter.array.type|length > 0 %}[{% else %}<{% endif %}{{ parameter.name | escapeKeyword | caseKebab }}{% if parameter.array.type|length > 0 %}...{% endif %}{% if parameter.array.type|length > 0 %}]{% else %}>{% endif %}`, `{{ parameter.description | replace({'`':'\''}) | replace({'\n':' '}) | replace({'\n \n':' '}) }}`{% if parameter | typeName == 'boolean' %}, parseBool{% elseif parameter | typeName == 'number' %}, parseInteger{% endif %})
9494
{% endfor %}
9595
{% if method.type == 'location' %}
9696
.requiredOption(`--destination <path>`, `output file path.`)

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -226,10 +226,10 @@ const client = new Command("client")
226226
.configureHelp({
227227
helpWidth: process.stdout.columns || 80
228228
})
229-
.option("-ss, --selfSigned <value>", "Configure the CLI to use a self-signed certificate ( true or false )", parseBool)
230-
.option("-e, --endpoint <endpoint>", "Set your Appwrite server endpoint")
231-
.option("-p, --projectId <projectId>", "Set your Appwrite project ID")
232-
.option("-k, --key <key>", "Set your Appwrite server's API key")
229+
.option("-ss, --self-signed <value>", "Configure the CLI to use a self-signed certificate ( true or false )", parseBool)
230+
.option("-e, --endpoint <endpoint>", "Set your {{ spec.title|caseUcfirst }} server endpoint")
231+
.option("-p, --project-id <project-id>", "Set your {{ spec.title|caseUcfirst }} project ID")
232+
.option("-k, --key <key>", "Set your {{ spec.title|caseUcfirst }} server's API key")
233233
.option("-d, --debug", "Print CLI debug information")
234234
.option("-r, --reset", "Reset the CLI configuration")
235235
.action(actionRunner(async ({ selfSigned, endpoint, projectId, key, debug, reset }, command) => {

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -334,9 +334,9 @@ const init = new Command("init")
334334
init
335335
.command("project")
336336
.description("Init a new {{ spec.title|caseUcfirst }} project")
337-
.option("--organizationId <organizationId>", "{{ spec.title|caseUcfirst }} organization ID")
338-
.option("--projectId <projectId>", "{{ spec.title|caseUcfirst }} project ID")
339-
.option("--projectName <projectName>", "{{ spec.title|caseUcfirst }} project ID")
337+
.option("--organization-id <organization-id>", "{{ spec.title|caseUcfirst }} organization ID")
338+
.option("--project-id <project-id>", "{{ spec.title|caseUcfirst }} project ID")
339+
.option("--project-name <project-name>", "{{ spec.title|caseUcfirst }} project ID")
340340
.action(actionRunner(initProject));
341341

342342
init

0 commit comments

Comments
 (0)