Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide more details in dot api #850

Merged
merged 2 commits into from
Oct 3, 2019
Merged
Changes from 1 commit
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
50 changes: 50 additions & 0 deletions lib/repl/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,24 @@ function displayUsageFor(name) {
return;
}
console.log();
if (e.deprecated) {
console.log(`DEPRECATED ${desc(e.deprecated)}`);
console.log();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any specific reason for empty console.log?
If it is just to achieve a new line, consider using '\n'. If worried about os specific new lines consider using require('os').EOL.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was reusing what was previously in place. EOL is a better fit as suggested.

}
console.log(desc(e.description));
if (e.params.length > 0) {
console.log();
console.log(e.params.length > 1 ? 'Parameters:' : 'Parameter:');
console.log();
params(e.params);
}
if (e.returns) {
console.log();
e.returns.map(e => {
console.log(`Returns: ${type(e.type)} ${(e.description.type ? desc(e.description) : e.description)}`);
})
console.log();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Empty console.log?

}
if (e.examples.length > 0) {
console.log();
console.log(e.examples.length > 1 ? 'Examples:' : 'Example:');
Expand Down Expand Up @@ -336,4 +353,37 @@ const desc = d =>
)
.join(' ');

const type = t => {
switch (t.type) {
case 'NameExpression':
return t.name;
case 'OptionalType':
return type(t.expression);
case 'RestType':
return '...' + type(t.expression);
case 'TypeApplication':
return `${type(t.expression)}<${t.applications.map(a => type(a)).join(',')}>`;
case 'UnionType':
return `${t.elements.map(t => type(t)).join('|')}`;
}
};

const param = p => {
const name = p.name || '';
const t = p.type ? type(p.type) + ' - ' : '';
const d = (p.description ? desc(p.description) : p.description) || '';
const dft = p.default ? `(optional, default ${p.default})` : '';

return `${name} - ${t}${d} ${dft}`;
};

const params = p => {
p.map(p => {
console.log('* ' + param(p));
if (p.properties) {
console.log(p.properties.map(p => ` * ${param(p)}`).join('\n'));
}
});
}

const isTaikoFunc = keyword => keyword.split('(')[0] in funcs;