-
Notifications
You must be signed in to change notification settings - Fork 101
/
translations.ts
49 lines (41 loc) · 1.87 KB
/
translations.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import { APIOrganizationCommand, OutputItemOrListConfig, outputItemOrList } from '@smartthings/cli-lib'
import { LocaleReference, PreferenceLocalization } from '@smartthings/core-sdk'
import { chooseDevicePreference } from '../../lib/commands/devicepreferences-util'
import { tableFieldDefinitions } from '../../lib/commands/devicepreferences/translations-util'
export default class DevicePreferencesTranslationsCommand extends APIOrganizationCommand<typeof DevicePreferencesTranslationsCommand.flags> {
static description = 'get translated device preference values in a desired locale'
static flags = {
...APIOrganizationCommand.flags,
...outputItemOrList.flags,
}
static args = [
{ name: 'preferenceId', description: 'device preference id or index' },
{ name: 'tag', description: 'the locale tag' },
]
static examples = [
{
description: 'answer a series of questions to choose device preference and list locales',
command: 'smartthings devicepreferences:translation',
},
{
description: 'list locales for a specific device preference ID',
command: 'smartthings devicepreferences:translations motionSensitivity',
},
{
description: 'specify device preference ID and locale to get translated device preference values',
command: 'smartthings devicepreferences:translations motionSensitivity ko',
},
]
async run(): Promise<void> {
const preferenceId = await chooseDevicePreference(this, this.args.preferenceId)
const config: OutputItemOrListConfig<PreferenceLocalization, LocaleReference> = {
primaryKeyName: 'tag',
sortKeyName: 'tag',
listTableFieldDefinitions: ['tag'],
tableFieldDefinitions,
}
await outputItemOrList<PreferenceLocalization, LocaleReference>(this, config, this.args.tag,
() => this.client.devicePreferences.listTranslations(preferenceId),
tag => this.client.devicePreferences.getTranslations(preferenceId, tag))
}
}