Skip to content

Commit 2b5a168

Browse files
committed
feat(cli): Console flow add an open flag
1 parent 0357a8a commit 2b5a168

File tree

3 files changed

+9
-12
lines changed

3 files changed

+9
-12
lines changed

templates/cli/base/requests/api.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
{%~ if method.name == 'get' and service.name not in ['health','migrations','locale'] %}
2121
if(console) {
2222
showConsoleLink('{{service.name}}', 'get'
23-
{%- for parameter in method.parameters.path -%}{%- set param = (parameter.name | caseCamel | escapeKeyword) -%}{%- if param ends with 'Id' -%}, {{ param }} {%- endif -%}{%- endfor -%}
23+
{%- for parameter in method.parameters.path -%}{%- set param = (parameter.name | caseCamel | escapeKeyword) -%},open {%- if param ends with 'Id' -%}, {{ param }} {%- endif -%}{%- endfor -%}
2424
);
2525
} else {
2626
parse(response)

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ const {{ service.name | caseLower }}{{ method.name | caseUcfirst }} = async ({
7070
{%- if 'multipart/form-data' in method.consumes -%},onProgress = () => {}{%- endif -%}
7171

7272
{%- if method.type == 'location' -%}, destination{%- endif -%}
73-
{%- if method.name == 'get' -%}, console{%- endif -%}
73+
{%- if method.name == 'get' -%}, console, open{%- endif -%}
7474
}) => {
7575
{%~ endblock %}
7676
let client = !sdk ? await {% if service.name == "projects" %}sdkForConsole(){% else %}sdkForProject(){% endif %} :
@@ -96,7 +96,8 @@ const {{ service.name | caseLower }}{{ method.name | caseUcfirst }} = async ({
9696
.requiredOption(`--destination <path>`, `output file path.`)
9797
{% endif %}
9898
{% if method.name == 'get' %}
99-
.option(`--console`, `View this resource in the console`)
99+
.option(`--console`, `Get the resource console url`)
100+
.option(`--open`, `Use with '--console' to open the using default browser`)
100101
{% endif %}
101102
{% endautoescape %}
102103
.action(actionRunner({{ service.name | caseLower }}{{ method.name | caseUcfirst }}))

templates/cli/lib/utils.js.twig

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ function getAllFiles(folder) {
1818
return files;
1919
}
2020

21-
function showConsoleLink(serviceName, action, id = '') {
21+
function showConsoleLink(serviceName, action, open, id = '') {
2222
let resource = '';
2323
let service = '';
2424

@@ -58,17 +58,13 @@ function showConsoleLink(serviceName, action, id = '') {
5858
const middle = resource !== '' ? `/project-${projectId}` : '';
5959
const url = `${baseUrl}/console${middle}/${service}${end}`
6060

61-
const start = (process.platform == 'darwin' ? 'open' : process.platform == 'win32' ? 'start' : 'xdg-open');
62-
const key = (process.platform == 'darwin' ? 'Return' : 'Enter');
6361

64-
success(`\n ${url}\n Press <${key}> to open URL in your default browser, exising in 3 seconds`);
65-
setTimeout(() => process.exit(0), 3000);
62+
success(url);
6663

67-
const read = readline.createInterface({ input: process.stdin, output: process.stdout });
68-
read.on('line', () => {
64+
if (open) {
65+
const start = (process.platform == 'darwin' ? 'open' : process.platform == 'win32' ? 'start' : 'xdg-open');
6966
cp.exec(`${start} ${url}`);
70-
setTimeout(() => process.exit(0), 250);
71-
});
67+
}
7268
}
7369

7470
module.exports = {

0 commit comments

Comments
 (0)