From abf3b92404d75fcf5266a5b0d3e1b54d259d7287 Mon Sep 17 00:00:00 2001 From: Denis Melnik <58072595+denis-codefresh@users.noreply.github.com> Date: Fri, 11 Jun 2021 15:37:26 +0300 Subject: [PATCH] =?UTF-8?q?Add=20types=20for=20the=20options=20in=20the=20?= =?UTF-8?q?docs.=20Replaced=20-d=20option=20with=20-v=20opt=E2=80=A6=20(#6?= =?UTF-8?q?84)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add types for the options in the docs. Replaced -d option with -v option in 'wait' command. * wip --- docs/index.js | 2 +- lib/interface/cli/Command.js | 25 +++++++++++++++++-- lib/interface/cli/commands/hybrid/init.cmd.js | 6 +++-- .../cli/commands/workflow/wait.cmd.js | 15 ++++++++--- 4 files changed, 39 insertions(+), 9 deletions(-) diff --git a/docs/index.js b/docs/index.js index e9946e795..5c9008099 100644 --- a/docs/index.js +++ b/docs/index.js @@ -184,7 +184,7 @@ const createCommandFile = async (nestedCategory,command) => { if (docs.options) { let optionsString = ''; _.forEach(docs.options, (options, group) => { - optionsString = `### ${group}\n\nOption | Alias | Default | Description\n--------- | --------- | ----------- | -----------\n${options}` + optionsString; + optionsString = `### ${group}\n\nOption | Alias | Type | Default | Description\n--------- | --------- | --------- |----------- | -----------\n${options}` + optionsString; }); if (skeletonFileExists) { finalFileString = finalFileString.replace('{{OPTIONS}}', optionsString); diff --git a/lib/interface/cli/Command.js b/lib/interface/cli/Command.js index 95921dfe6..7f134de12 100644 --- a/lib/interface/cli/Command.js +++ b/lib/interface/cli/Command.js @@ -227,6 +227,9 @@ class Command { res.options = _.get(parentCommandDocs, 'options', {}); _.forEach(options, (option) => { + if (option.value.omitFromDocs) { + return; + } const group = option.value.group || 'Options'; res.options[group] = res.options[group] || ''; const key = option.key; @@ -241,6 +244,24 @@ class Command { }); description += choicesString; } + + let optionType = ''; + if (option.value.type) { + if (typeof option.value.type === 'string') { + optionType = option.value.type; + } else if (option.value.type === Array) { + optionType = 'array'; + } + } else if (option.value.default) { + const primitiveTypes = ['string', 'number', 'boolean']; + const defaultValueType = typeof option.value.default; + if (primitiveTypes.includes(defaultValueType)) { + optionType = defaultValueType; + } else if (Array.isArray(option.value.default)) { + optionType = 'array'; + } + } + let aliases = ''; if (option.value.alias) { if (_.size(option.value.alias) === 1) { @@ -249,8 +270,8 @@ class Command { aliases += `--${option.value.alias}`; } } - const defaultValue = option.value.default || ''; - res.options[group] += `--${key} | ${aliases} | ${defaultValue} | ${description}\n`; + const defaultValue = option.value.default || (optionType === 'boolean' ? 'false' : ''); + res.options[group] += `--${key} | ${aliases} | ${optionType} | ${defaultValue} | ${description}\n`; }); res.examples = ''; diff --git a/lib/interface/cli/commands/hybrid/init.cmd.js b/lib/interface/cli/commands/hybrid/init.cmd.js index 169239d58..be2af0742 100644 --- a/lib/interface/cli/commands/hybrid/init.cmd.js +++ b/lib/interface/cli/commands/hybrid/init.cmd.js @@ -225,8 +225,10 @@ const initCmd = new Command({ default: false, type: 'boolean', }) - .example('codefresh runner init --values values.yaml (see values file example here: ' - + 'https://github.com/codefresh-io/venona/blob/release-1.0/venonactl/example/values-example.yaml)'), + .example( + 'codefresh runner init --values values.yaml', + 'See values file example here: https://github.com/codefresh-io/venona/blob/release-1.0/venonactl/example/values-example.yaml)', + ), handler: async (argv) => { let resumedInstallation = false; diff --git a/lib/interface/cli/commands/workflow/wait.cmd.js b/lib/interface/cli/commands/workflow/wait.cmd.js index 4571fae09..532ec5a3c 100644 --- a/lib/interface/cli/commands/workflow/wait.cmd.js +++ b/lib/interface/cli/commands/workflow/wait.cmd.js @@ -7,7 +7,7 @@ const { sdk } = require('../../../../logic'); const Promise = require('bluebird'); -const annotate = new Command({ +const wait = new Command({ root: true, command: 'wait ', description: 'Wait until a condition will be met on a build', @@ -26,9 +26,16 @@ const annotate = new Command({ default: 'success', required: true, }) + .option('verbose', { + alias: 'v', + describe: 'Show debug output until the condition will be met.', + default: false, + type: 'boolean', + }) .option('debug', { alias: 'd', - describe: 'Show debug output until the condition will be met', + describe: 'Show debug output until the condition will be met.', + omitFromDocs: true, }) .option('timeout', { alias: 't', @@ -45,7 +52,7 @@ const annotate = new Command({ handler: async (argv) => { const workflowIds = argv.id; const desiredStatus = argv.status; - const descriptive = argv.d; + const descriptive = argv.d || argv.v; _.forEach(workflowIds, (workflowId) => { if (!ObjectID.isValid(workflowId)) { @@ -67,4 +74,4 @@ const annotate = new Command({ }, }); -module.exports = annotate; +module.exports = wait;