Skip to content

Commit

Permalink
feat: use plain table in CI
Browse files Browse the repository at this point in the history
  • Loading branch information
mdonnalley committed Oct 28, 2024
1 parent 3d43683 commit 50d60c6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
getHeadings,
intersperse,
maybeStripAnsi,
shouldUsePlainTable,
sortData,
} from './utils.js'

Expand Down Expand Up @@ -488,7 +489,7 @@ class Output {
}
}

function renderTableInChunks<T extends Record<string, unknown>>(props: TableOptions<T>): void {
function renderPlainTable<T extends Record<string, unknown>>(props: TableOptions<T>): void {
const {columns, headings, processedData, title} = setup(props)

if (title) console.log(title)
Expand Down Expand Up @@ -542,8 +543,8 @@ function renderTableInChunks<T extends Record<string, unknown>>(props: TableOpti
*/
export function printTable<T extends Record<string, unknown>>(options: TableOptions<T>): void {
const limit = Number.parseInt(env.OCLIF_TABLE_LIMIT ?? env.SF_TABLE_LIMIT ?? '10000', 10) ?? 10_000
if (options.data.length >= limit) {
renderTableInChunks(options)
if (options.data.length >= limit || shouldUsePlainTable()) {
renderPlainTable(options)
return
}

Expand Down
15 changes: 15 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {camelCase, capitalCase, constantCase, kebabCase, pascalCase, sentenceCase, snakeCase} from 'change-case'
import {orderBy} from 'natural-orderby'
import {env} from 'node:process'
import stripAnsi from 'strip-ansi'

import {Column, ColumnProps, Config, Sort} from './types.js'
Expand Down Expand Up @@ -179,3 +180,17 @@ export function maybeStripAnsi<T extends Record<string, unknown>[]>(data: T, noS

return newData as T
}

function isTruthy(value: string | undefined): boolean {
return value !== '0' && value !== 'false'
}

// Inspired by https://github.com/sindresorhus/is-in-ci
export function shouldUsePlainTable(): boolean {
if (
isTruthy(env.CI) &&
('CI' in env || 'CONTINUOUS_INTEGRATION' in env || Object.keys(env).some((key) => key.startsWith('CI_')))
)
return true
return false
}

0 comments on commit 50d60c6

Please sign in to comment.