(flags: CalculateOutputFormatFlags, defaultIOFormat?: IOFormat)
| 28 | .option('json', { alias: 'j', describe: 'use JSON format of input and/or output', type: 'boolean', conflicts: 'yaml' }) |
| 29 | .option('yaml', { alias: 'y', describe: 'use YAML format of input and/or output', type: 'boolean', conflicts: 'json' }) |
| 30 | export const calculateOutputFormat = (flags: CalculateOutputFormatFlags, defaultIOFormat?: IOFormat): IOFormat => { |
| 31 | // flags get highest priority...check them first |
| 32 | if (flags.json) { |
| 33 | return 'json' |
| 34 | } |
| 35 | if (flags.yaml) { |
| 36 | return 'yaml' |
| 37 | } |
| 38 | // if we have an output filename, use that file's extension |
| 39 | if (flags.output) { |
| 40 | return formatFromFilename(flags.output) |
| 41 | } |
| 42 | if (defaultIOFormat) { |
| 43 | return defaultIOFormat |
| 44 | } |
| 45 | // if we're writing to the console, use user-friendly output, otherwise default to JSON |
| 46 | return stdoutIsTTY() ? 'common' : 'json' |
| 47 | } |
| 48 | |
| 49 | export type OutputFormatter<T extends object> = (data: T) => string |
| 50 |
no test coverage detected