Skip to content

Commit

Permalink
logList is really printing tables (without borders).
Browse files Browse the repository at this point in the history
  • Loading branch information
szchenghuang committed Oct 14, 2024
1 parent 2b9ee8e commit c52228c
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 34 deletions.
15 changes: 4 additions & 11 deletions packages/cli/src/oclif/ZapierBaseCommand.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const { stdtermwidth } = require('@oclif/help/lib/screen');
const { renderList } = require('@oclif/help/lib/list');
const { Command } = require('@oclif/core');
const colors = require('colors/safe');

Expand Down Expand Up @@ -137,6 +135,9 @@ class ZapierBaseCommand extends Command {
headers = [],
emptyMessage = '',
formatOverride = '',
hasBorder = true,
showHeaders = true,
style = undefined,
} = {}) {
const formatter = formatOverride
? formatStyles[formatOverride]
Expand All @@ -149,18 +150,10 @@ class ZapierBaseCommand extends Command {
this.log(colors.gray(emptyMessage));
} else {
// data comes out of the formatter ready to be printed (and it's always in the type to match the format) so we don't need to do anything special with it
console.log(formatter(rows, headers));
console.log(formatter(rows, headers, showHeaders, hasBorder, style));
}
}

/**
* Print text in a list style.
* @param {string[][]} items
*/
logList(items) {
this.log(renderList(items, { spacer: '\n', maxWidth: stdtermwidth }));
}

/**
*
* @param {Object} opts options object (as expected for this.prompt())
Expand Down
40 changes: 24 additions & 16 deletions packages/cli/src/oclif/commands/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,24 +85,32 @@ class ValidateCommand extends BaseCommand {
const suggestionDisplay = checkResult.suggestions.display_label;

if (checkIssues.length) {
this.logList([
[
`- ${colors.bold(errorDisplay)}`,
'Issues that will prevent your integration from functioning ' +
'properly. They block you from pushing.',
this.logTable({
headers: [
['', 'type'],
['', 'description'],
],
[
`- ${colors.bold(warningDisplay)}`,
'To-dos that must be addressed before your integration can be ' +
'included in the App Directory. They block you from promoting and ' +
'publishing.',
rows: [
{
type: `- ${colors.bold(errorDisplay)}`,
description:
'Issues that will prevent your integration from functioning properly. They block you from pushing.',
},
{
type: `- ${colors.bold(warningDisplay)}`,
description:
'To-dos that must be addressed before your integration can be included in the App Directory. They block you from promoting and publishing.',
},
{
type: `- ${colors.bold(suggestionDisplay)}`,
description:
"Issues and recommendations that need human reviews by Zapier before publishing your integration. They don't block.",
},
],
[
`- ${colors.bold(suggestionDisplay)}`,
'Issues and recommendations that need human reviews by Zapier before ' +
"publishing your integration. They don't block.",
],
]);
hasBorder: false,
showHeaders: false,
style: { head: [], 'padding-left': 0, 'padding-right': 0 },
});
}
this.log();
}
Expand Down
43 changes: 43 additions & 0 deletions packages/cli/src/oclif/commands/versions.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const colors = require('colors/safe');

const BaseCommand = require('../ZapierBaseCommand');
const { buildFlags } = require('../buildFlags');

Expand All @@ -23,6 +25,47 @@ class VersionCommand extends BaseCommand {
'No versions to show. Try adding one with the `zapier push` command',
});

this.logTable({
headers: [],
rows: [
{
version: `- ${colors.bold('Errors')}`,
platform_version:
'Issues that will prevent your integration from functioning properly. They block you from pushing.',
},
{
version: `- ${colors.bold('Publishing Tasks')}`,
platform_version:
'To-dos that must be addressed before your integration can be included in the App Directory. They block you from promoting and publishing.',
},
{
version: `- ${colors.bold('Warnings')}`,
platform_version:
"Issues and recommendations that need human reviews by Zapier before publishing your integration. They don't block.",
},
],
hasBorder: false,
style: { head: [], 'padding-left': 0, 'padding-right': 0 },
});

this.logList([
[
`- ${colors.bold('Errors')}`,
'Issues that will prevent your integration from functioning properly. They block you from pushing.',
],
[
`- ${colors.bold('Publishing Tasks')}`,
'To-dos that must be addressed before your integration can be ' +
'included in the App Directory. They block you from promoting and ' +
'publishing.',
],
[
`- ${colors.bold('Warnings')}`,
'Issues and recommendations that need human reviews by Zapier before ' +
"publishing your integration. They don't block.",
],
]);

if (versions.map((v) => v.user_count).filter((c) => c === null).length) {
this.warn(
'Some user counts are still being calculated - run this command again in ~10 seconds (or longer if your integration has lots of users).'
Expand Down
37 changes: 30 additions & 7 deletions packages/cli/src/utils/display.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,33 @@ const ansiTrim = (s) =>
// '\u001b[90m',
]);

const CHARS = {
const TABLE_CHARS_DEFAULT = {
// 'top': '', 'top-mid': '', 'top-left': '', 'top-right': '',
// 'bottom': ' ', 'bottom-mid': ' ', 'bottom-left': ' ', 'bottom-right': ' '
};
const TABLE_CHARS_NONE = {
top: '',
'top-mid': '',
'top-left': '',
'top-right': '',
bottom: '',
'bottom-mid': '',
'bottom-left': '',
'bottom-right': '',
left: '',
'left-mid': '',
mid: '',
'mid-mid': '',
right: '',
'right-mid': '',
middle: ' ',
};

// Similar to makeTable, but prints the column headings in the left-hand column
// and the values in the right-hand column, in rows
const makeRowBasedTable = (rows, columnDefs, { includeIndex = true } = {}) => {
const tableOptions = {
chars: CHARS,
chars: TABLE_CHARS_DEFAULT,
style: {
compact: true,
},
Expand Down Expand Up @@ -141,13 +158,19 @@ const makeRowBasedTable = (rows, columnDefs, { includeIndex = true } = {}) => {
return strTable;
};

// Wraps the cli-table3 library. Rows is an array of objects, columnDefs
// Wraps the cli-table3 library. Rows is an array of objects, headers
// an ordered sub-array [[label, key, (optional_default)], ...].
const makeTable = (rows, columnDefs) => {
const makeTable = (
rows,
columnDefs,
showHeaders = true,
hasBorder = true,
style = undefined
) => {
const tableOptions = {
head: columnDefs.map(([label]) => label),
chars: CHARS,
style: {
head: showHeaders ? columnDefs.map(([label]) => label) : undefined,
chars: hasBorder ? TABLE_CHARS_DEFAULT : TABLE_CHARS_NONE,
style: style ?? {
compact: true,
head: ['bold'],
},
Expand Down

0 comments on commit c52228c

Please sign in to comment.