MCPcopy Create free account
hub / github.com/SmartThingsCommunity/smartthings-cli / calculateOutputFormat

Function calculateOutputFormat

src/lib/command/output.ts:30–47  ·  view source on GitHub ↗
(flags: CalculateOutputFormatFlags, defaultIOFormat?: IOFormat)

Source from the content-addressed store, hash-verified

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' })
30export 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
49export type OutputFormatter<T extends object> = (data: T) => string
50

Callers 5

handlerFunction · 0.85
handlerFunction · 0.85
handlerFunction · 0.85
buildOutputFormatterFunction · 0.85
output.test.tsFile · 0.85

Calls 2

formatFromFilenameFunction · 0.85
stdoutIsTTYFunction · 0.85

Tested by

no test coverage detected