Skip to content

Commit eb405e8

Browse files
authored
Merge pull request #1164 from appwrite/fix-cli
Fix CLI
2 parents 161d474 + 8b0e705 commit eb405e8

File tree

5 files changed

+58
-14
lines changed

5 files changed

+58
-14
lines changed

src/SDK/Language/CLI.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ public function getFiles(): array
163163
],
164164
[
165165
'scope' => 'method',
166-
'destination' => 'docs/examples/{{service.name | caseLower}}/{{method.name | caseDash}}.md',
166+
'destination' => 'docs/examples/{{service.name | caseLower}}/{{method.name | caseKebab}}.md',
167167
'template' => 'cli/docs/example.md.twig',
168168
],
169169
[
@@ -313,7 +313,7 @@ public function getFiles(): array
313313
],
314314
[
315315
'scope' => 'service',
316-
'destination' => '/lib/commands/{{service.name | caseDash}}.js',
316+
'destination' => '/lib/commands/{{ service.name | caseKebab }}.js',
317317
'template' => 'cli/lib/commands/command.js.twig',
318318
],
319319
[

templates/cli/docs/example.md.twig

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
{{ language.params.executableName }} {{ service.name }} {{ method.name }}{% if method.parameters.all | length > 0 %} \{% endif %}
2-
1+
{% set requiredParams = [] %}
32
{% for parameter in method.parameters.all %}
43
{% if parameter.required %}
5-
--{{ parameter.name }} {{ parameter | paramExample }}{% if not loop.last %} \{% endif %}
4+
{% set requiredParams = requiredParams|merge([parameter]) %}
65
{% endif %}
6+
{% endfor %}
7+
{{ language.params.executableName }} {{ service.name | caseKebab }} {{ method.name | caseKebab }}{% if requiredParams | length > 0 %} \{% endif %}
8+
9+
{% for parameter in requiredParams %}
10+
--{{ parameter.name | caseKebab }} {{ parameter | paramExample }}{% if not loop.last %} \{% endif %}
711

812
{% endfor %}

templates/cli/index.js.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const { update } = require("./lib/commands/update");
2424
const { migrate } = require("./lib/commands/generic");
2525
{% endif %}
2626
{% for service in spec.services %}
27-
const { {{ service.name | caseLower }} } = require("./lib/commands/{{ service.name | caseLower }}");
27+
const { {{ service.name }} } = require("./lib/commands/{{ service.name | caseKebab }}");
2828
{% endfor %}
2929

3030
inquirer.registerPrompt('search-list', require('inquirer-search-list'));

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

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,22 @@ function convertReadStreamToReadableStream(readStream) {
3535
});
3636
}
3737

38-
const {{ service.name | caseLower }} = new Command("{{ service.name | caseLower }}").description(commandDescriptions['{{ service.name | caseLower }}'] ?? '').configureHelp({
38+
const {{ service.name }} = new Command("{{ service.name | caseKebab }}").description(commandDescriptions['{{ service.name | caseKebab }}'] ?? '').configureHelp({
3939
helpWidth: process.stdout.columns || 80
4040
})
4141

4242
{% for method in service.methods %}
43+
{% set commandNameLower = (method.name | caseKebab | lower) %}
44+
{# Check if this method should be skipped (is deprecated and has a non-deprecated duplicate) #}
45+
{% set shouldSkip = false %}
46+
{% if method.deprecated %}
47+
{% for otherMethod in service.methods %}
48+
{% if not otherMethod.deprecated and (otherMethod.name | caseKebab | lower) == commandNameLower %}
49+
{% set shouldSkip = true %}
50+
{% endif %}
51+
{% endfor %}
52+
{% endif %}
53+
{% if not shouldSkip %}
4354
/**
4455
* @typedef {Object} {{ service.name | caseUcfirst }}{{ method.name | caseUcfirst }}RequestParams
4556
{% for parameter in method.parameters.all %}
@@ -60,7 +71,7 @@ const {{ service.name | caseLower }} = new Command("{{ service.name | caseLower
6071
* @param {{ "{" }}{{ service.name | caseUcfirst }}{{ method.name | caseUcfirst }}RequestParams{{ "}" }} params
6172
*/
6273
{% block declaration %}
63-
const {{ service.name | caseLower }}{{ method.name | caseUcfirst }} = async ({
74+
const {{ service.name }}{{ method.name | caseUcfirst }} = async ({
6475
{%- for parameter in method.parameters.all -%}
6576
{{ parameter.name | caseCamel | escapeKeyword }},
6677
{%- endfor -%}
@@ -82,10 +93,24 @@ const {{ service.name | caseLower }}{{ method.name | caseUcfirst }} = async ({
8293
{% endif %}
8394
}
8495
{% endblock declaration %}
85-
96+
{% endif %}
8697
{% endfor %}
98+
{% set processedCommands = [] %}
8799
{% for method in service.methods %}
88-
{{service.name | caseLower }}
100+
{% set commandName = method.name | caseKebab %}
101+
{% set commandNameLower = commandName | lower %}
102+
{# Check if this command name (in lowercase) has already been processed by a non-deprecated method #}
103+
{% set shouldSkip = false %}
104+
{% if method.deprecated %}
105+
{% for otherMethod in service.methods %}
106+
{% if not otherMethod.deprecated and (otherMethod.name | caseKebab | lower) == commandNameLower %}
107+
{% set shouldSkip = true %}
108+
{% endif %}
109+
{% endfor %}
110+
{% endif %}
111+
{% if not shouldSkip %}
112+
{% set processedCommands = processedCommands|merge([commandNameLower]) %}
113+
{{ service.name }}
89114
.command(`{{ method.name | caseKebab }}`)
90115
{% autoescape false %}
91116
.description(`{% if method.deprecated %}[**DEPRECATED** - This command is deprecated.{% if method.replaceWith %} Please use '{{ method.replaceWith | replace({'.': ' '}) | caseKebab }}' instead{% endif %}] {% endif %}{{ method.description | replace({'`':'\''}) | replace({'\n':' '}) | replace({'\n \n':' '}) }}`)
@@ -99,13 +124,28 @@ const {{ service.name | caseLower }}{{ method.name | caseUcfirst }} = async ({
99124
.option(`--console`, `Get the resource console url`)
100125
{% endif %}
101126
{% endautoescape %}
102-
.action(actionRunner({{ service.name | caseLower }}{{ method.name | caseUcfirst }}))
127+
.action(actionRunner({{ service.name }}{{ method.name | caseUcfirst }}))
103128

129+
{% endif %}
104130
{% endfor %}
105131
module.exports = {
106-
{{ service.name | caseLower }},
132+
{{ service.name }},
133+
{% set exportedMethods = [] %}
107134
{% for method in service.methods %}
108-
{{ service.name | caseLower }}{{ method.name | caseUcfirst }}{% if not loop.last %},{% endif %}
135+
{% set commandNameLower = (method.name | caseKebab | lower) %}
136+
{# Check if this method should be skipped (is deprecated and has a non-deprecated duplicate) #}
137+
{% set shouldSkip = false %}
138+
{% if method.deprecated %}
139+
{% for otherMethod in service.methods %}
140+
{% if not otherMethod.deprecated and (otherMethod.name | caseKebab | lower) == commandNameLower %}
141+
{% set shouldSkip = true %}
142+
{% endif %}
143+
{% endfor %}
144+
{% endif %}
145+
{% if not shouldSkip %}
146+
{% set exportedMethods = exportedMethods|merge([service.name ~ method.name | caseUcfirst]) %}
147+
{{ service.name }}{{ method.name | caseUcfirst }}{% if not loop.last %},{% endif %}
109148

149+
{% endif %}
110150
{% endfor %}
111151
};

templates/cli/lib/parser.js.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ const commandDescriptions = {
230230
"main": chalk.redBright(`${logo}${description}`),
231231
{% if sdk.test == "true" %}
232232
{% for service in spec.services %}
233-
"{{ service.name | caseLower }}": `The {{ service.name }} command allows you to manage your {{ service.name }} service.`,
233+
"{{ service.name | caseKebab }}": `The {{ service.name | caseKebab }} command allows you to manage your {{ service.name }} service.`,
234234
{% endfor %}
235235
{% endif %}
236236
}

0 commit comments

Comments
 (0)