Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion templates/node-cli/index.js.twig
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
const program = require("commander");
const chalk = require("chalk");
const { version } = require("./package.json");
const { commandDescriptions } = require("./lib/parser");
const { commandDescriptions, cliConfig } = require("./lib/parser");
const { client } = require("./lib/commands/generic");
{% if sdk.isTest != "true" %}
const { login, logout } = require("./lib/commands/generic");
Expand All @@ -16,6 +16,14 @@ const { {{ service.name | caseLower }} } = require("./lib/commands/{{ service.na
program
.description(commandDescriptions['main'])
.version(version, "-v, --version")
.option("--verbose", "Show complete error log")
.option("--json", "Output in JSON format")
.on("option:json", () => {
cliConfig.json = true;
})
.on("option:verbose", () => {
cliConfig.verbose = true;
})
.showSuggestionAfterError()
{% if sdk.isTest != "true" %}
.addCommand(login)
Expand All @@ -28,3 +36,4 @@ program
{% endfor %}
.addCommand(client)
.parse(process.argv);

5 changes: 2 additions & 3 deletions templates/node-cli/lib/commands/command.js.twig
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const { localConfig, globalConfig } = require("../config");
const {{ service.name | caseLower }} = new Command("{{ service.name | caseLower }}").description(commandDescriptions['{{ service.name | caseLower }}'])

{% for method in service.methods %}
const {{ service.name | caseLower }}{{ method.name | caseUcfirst }} = async ({ {% for parameter in method.parameters.all %}{{ parameter.name | caseCamel | escapeKeyword }}, {% endfor %}parseOutput = true, sdk = undefined, json{% if 'multipart/form-data' in method.consumes %}, onProgress = () => {}{% endif %}{% if method.type == 'location' %}, destination{% endif %}}) => {
const {{ service.name | caseLower }}{{ method.name | caseUcfirst }} = async ({ {% for parameter in method.parameters.all %}{{ parameter.name | caseCamel | escapeKeyword }}, {% endfor %}parseOutput = true, sdk = undefined{% if 'multipart/form-data' in method.consumes %}, onProgress = () => {}{% endif %}{% if method.type == 'location' %}, destination{% endif %}}) => {
{% for parameter in method.parameters.all %}
/* @param {{ '{' }}{{ parameter.type | typeName }}{{ '}' }} {{ parameter.name | caseCamel | escapeKeyword }} */
{% endfor %}
Expand Down Expand Up @@ -152,7 +152,7 @@ const {{ service.name | caseLower }}{{ method.name | caseUcfirst }} = async ({ {
{% endif %}

if (parseOutput) {
parse(response, json)
parse(response)
success()
}
return response;
Expand All @@ -172,7 +172,6 @@ const {{ service.name | caseLower }}{{ method.name | caseUcfirst }} = async ({ {
{% if method.type == 'location' %}
.requiredOption(`--destination <path>`, `output file path.`)
{% endif %}
.option(`--json`, `Output in JSON format`)
{% endautoescape %}
.action(actionRunner({{ service.name | caseLower }}{{ method.name | caseUcfirst }}))

Expand Down
21 changes: 16 additions & 5 deletions templates/node-cli/lib/parser.js.twig
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
const chalk = require('chalk');
const commander = require('commander');
const Table = require('cli-table3');
const { description } = require('../package.json')
const { description } = require('../package.json');

const parse = (data, json = false) => {
if (json) {
const cliConfig = {
verbose: false,
json: false
};

const parse = (data) => {
if (cliConfig.json) {
drawJSON(data);
return;
}
Expand Down Expand Up @@ -101,7 +106,12 @@ const drawJSON = (data) => {
}

const parseError = (err) => {
error(err.message)
if(cliConfig.verbose) {
console.error(err);
}

error(err.message);

process.exit(1)
}

Expand Down Expand Up @@ -176,5 +186,6 @@ module.exports = {
log,
success,
error,
commandDescriptions
commandDescriptions,
cliConfig
}