chore(cli): rename test files from .mts to .ts
This commit is contained in:
@@ -16,7 +16,17 @@ export function renderJson<T>(
|
||||
// Apply custom serializer if provided
|
||||
if (schema.serialize) {
|
||||
if (result.type === 'list') {
|
||||
// If all items serialize to the same object, return just one
|
||||
// This handles the case where a list of key-value rows should serialize
|
||||
// to a single structured object
|
||||
const serialized = result.data.map((item) => schema.serialize!(item))
|
||||
if (serialized.length > 0) {
|
||||
const first = JSON.stringify(serialized[0])
|
||||
const allSame = serialized.every((s) => JSON.stringify(s) === first)
|
||||
if (allSame) {
|
||||
return JSON.stringify(serialized[0], null, 2)
|
||||
}
|
||||
}
|
||||
return JSON.stringify(serialized, null, 2)
|
||||
} else {
|
||||
const serialized = schema.serialize(result.data)
|
||||
|
||||
@@ -97,7 +97,7 @@ function renderRow<T>(
|
||||
}
|
||||
}
|
||||
|
||||
return padCell(cell, width, col.align ?? 'left')
|
||||
return padCell(cell, width ?? 0, col.align ?? 'left')
|
||||
})
|
||||
.join(' ')
|
||||
}
|
||||
@@ -109,7 +109,7 @@ function renderHeader<T>(
|
||||
options: OutputOptions
|
||||
): string {
|
||||
const headerRow = columns
|
||||
.map((col, i) => padCell(col.header, widths[i], col.align ?? 'left'))
|
||||
.map((col, i) => padCell(col.header, widths[i] ?? 0, col.align ?? 'left'))
|
||||
.join(' ')
|
||||
|
||||
return options.noColor ? headerRow : chalk.bold(headerRow)
|
||||
|
||||
@@ -47,7 +47,9 @@ export function withOutput<T, Args extends unknown[]>(
|
||||
): (...args: [...Args, CommandOptions, Command]) => Promise<void> {
|
||||
return async (...args) => {
|
||||
// Last two args are options and command
|
||||
const options = args[args.length - 2] as CommandOptions
|
||||
const command = args[args.length - 1] as Command
|
||||
// Use optsWithGlobals() to get both local and global options
|
||||
const options = command.optsWithGlobals() as CommandOptions
|
||||
const outputOptions = extractOutputOptions(options)
|
||||
|
||||
try {
|
||||
|
||||
@@ -17,7 +17,17 @@ export function renderYaml<T>(
|
||||
// Apply custom serializer if provided
|
||||
if (schema.serialize) {
|
||||
if (result.type === 'list') {
|
||||
// If all items serialize to the same object, return just one
|
||||
// This handles the case where a list of key-value rows should serialize
|
||||
// to a single structured object
|
||||
const serialized = result.data.map((item) => schema.serialize!(item))
|
||||
if (serialized.length > 0) {
|
||||
const first = JSON.stringify(serialized[0])
|
||||
const allSame = serialized.every((s) => JSON.stringify(s) === first)
|
||||
if (allSame) {
|
||||
return YAML.stringify(serialized[0])
|
||||
}
|
||||
}
|
||||
return YAML.stringify(serialized)
|
||||
} else {
|
||||
const serialized = schema.serialize(result.data)
|
||||
|
||||
Reference in New Issue
Block a user