Skip to content

Commit

Permalink
Add types for the options in the docs. Replaced -d option with -v opt… (
Browse files Browse the repository at this point in the history
#684)

* Add types for the options in the docs. Replaced -d option with -v option in 'wait' command.

* wip
  • Loading branch information
denis-codefresh authored Jun 11, 2021
1 parent bc75e0e commit abf3b92
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 9 deletions.
2 changes: 1 addition & 1 deletion docs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
25 changes: 23 additions & 2 deletions lib/interface/cli/Command.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand All @@ -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 = '';
Expand Down
6 changes: 4 additions & 2 deletions lib/interface/cli/commands/hybrid/init.cmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
15 changes: 11 additions & 4 deletions lib/interface/cli/commands/workflow/wait.cmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const { sdk } = require('../../../../logic');
const Promise = require('bluebird');


const annotate = new Command({
const wait = new Command({
root: true,
command: 'wait <id..>',
description: 'Wait until a condition will be met on a build',
Expand All @@ -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',
Expand All @@ -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)) {
Expand All @@ -67,4 +74,4 @@ const annotate = new Command({
},
});

module.exports = annotate;
module.exports = wait;

0 comments on commit abf3b92

Please sign in to comment.