(argv: ArgumentsCamelCase<CommandArgs>)
| 45 | .epilog(buildEpilog({ command })) |
| 46 | |
| 47 | const handler = async (argv: ArgumentsCamelCase<CommandArgs>): Promise<void> => { |
| 48 | const command = await smartThingsCommand(argv) |
| 49 | const listTableFieldDefinitions: TableFieldDefinition<ProfileWithName>[] = [ |
| 50 | 'name', |
| 51 | { label: 'Active', value: item => item.name === command.profileName ? 'true' : '' }, |
| 52 | ] |
| 53 | const tableFieldDefinitions: TableFieldDefinition<ProfileWithName>[] = [ |
| 54 | ...listTableFieldDefinitions, |
| 55 | { label: 'Definition', value: item => yaml.dump(item.profile) }, |
| 56 | ] |
| 57 | |
| 58 | const outputListConfig: OutputListConfig<ProfileWithName> = { |
| 59 | primaryKeyName: 'name', |
| 60 | sortKeyName: 'name', |
| 61 | listTableFieldDefinitions, |
| 62 | } as const |
| 63 | if (argv.verbose) { |
| 64 | listTableFieldDefinitions.push({ path: 'profile.token' }) |
| 65 | } |
| 66 | |
| 67 | const baseURLValue = (item: ProfileWithName): string | undefined => |
| 68 | (item.profile?.clientIdProvider as undefined | Record<string, string>)?.baseURL |
| 69 | const getConfig = async (name: string): Promise<ProfileWithName> => { |
| 70 | const config = command.cliConfig.mergedProfiles |
| 71 | return { name, profile: config[name] } |
| 72 | } |
| 73 | const listConfigs = async (): Promise<ProfileWithName[]> => { |
| 74 | const config = command.cliConfig.mergedProfiles |
| 75 | const list = Object.keys(config).map(it => { |
| 76 | return { name: it, profile: config[it] } |
| 77 | }) |
| 78 | // This is a little iffy since we could end up updating `listTableFieldDefinitions` |
| 79 | // more than once if `listConfigs` is called more than once but we don't. (We actively |
| 80 | // avoid calling it multiple times in functions we pass it too because they usually get |
| 81 | // passed functions that make API calls.) |
| 82 | if (argv.verbose && list.some(baseURLValue)) { |
| 83 | listTableFieldDefinitions.push({ label: 'API URL', value: baseURLValue }) |
| 84 | } |
| 85 | return list |
| 86 | } |
| 87 | |
| 88 | if (argv.name) { |
| 89 | const profileName = await stringTranslateToId(outputListConfig, argv.name, listConfigs) |
| 90 | await outputItem(command, { tableFieldDefinitions }, () => getConfig(profileName)) |
| 91 | } else { |
| 92 | const outputFormat = calculateOutputFormat(argv) |
| 93 | if (outputFormat === 'common') { |
| 94 | console.log('The CLI configuration file on your machine is:\n' + |
| 95 | ` ${join(command.configDir, 'config.yaml')}\n`) |
| 96 | await outputList(command, outputListConfig, listConfigs, { includeIndex: true }) |
| 97 | } else { |
| 98 | const outputFormatter = buildOutputFormatter(command.flags, command.cliConfig) |
| 99 | await writeOutput(outputFormatter(command.cliConfig.mergedProfiles), argv.output) |
| 100 | } |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | const cmd: CommandModule<object, CommandArgs> = { command, describe, builder, handler } |
nothing calls this directly
no test coverage detected