-
Notifications
You must be signed in to change notification settings - Fork 104
/
translations.ts
99 lines (90 loc) · 5.6 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import { Flags } from '@oclif/core'
import { DeviceProfileTranslations, LocaleReference } from '@smartthings/core-sdk'
import { APIOrganizationCommand, OutputItemOrListConfig, outputItemOrList } from '@smartthings/cli-lib'
import { chooseDeviceProfile } from '../../lib/commands/deviceprofiles-util'
import { buildTableOutput } from '../../lib/commands/deviceprofiles/translations-util'
export default class DeviceProfileTranslationsCommand extends APIOrganizationCommand<typeof DeviceProfileTranslationsCommand.flags> {
static description = 'get list of locales supported by the device profiles'
static flags = {
...APIOrganizationCommand.flags,
...outputItemOrList.flags,
verbose: Flags.boolean({
description: 'include list of locales in table output',
char: 'v',
}),
}
static args = [
{
name: 'id',
description: 'UUID or the number of the profile from list',
},
{
name: 'tag',
description: 'the locale tag or number of the tag from list',
},
]
static examples = [
'$ smartthings deviceprofiles:translations',
'┌────┬─────────────────────┬─────────────┬──────────────────────────────────────┐',
'│ # │ Name │ Status │ Id │',
'├────┼─────────────────────┼─────────────┼──────────────────────────────────────┤',
'│ 1 │ Test Switch │ DEVELOPMENT │ 58e73d0c-b5a5-4814-b344-c10f4ff357bb │',
'│ 2 │ Two Channel Outlet │ DEVELOPMENT │ 3acbf2fc-6be2-4be0-aeb5-44759cbd66c2 │',
'└────┴─────────────────────┴─────────────┴──────────────────────────────────────┘',
'? Select a Device Profile. 2',
'┌───┬─────┐',
'│ # │ Tag │',
'├───┼─────┤',
'│ 1 │ en │',
'│ 2 │ es │',
'└───┴─────┘',
'',
'$ smartthings deviceprofiles:translations -v',
'┌────┬─────────────────────┬─────────────┬──────────────────────────────────────┬─────────┐',
'│ # │ Name │ Status │ Id │ Locales │',
'├────┼─────────────────────┼─────────────┼──────────────────────────────────────┼─────────┤',
'│ 1 │ Test Switch │ DEVELOPMENT │ 58e73d0c-b5a5-4814-b344-c10f4ff357bb │ │',
'│ 2 │ Two Channel Outlet │ DEVELOPMENT │ 3acbf2fc-6be2-4be0-aeb5-44759cbd66c2 │ en, es │',
'└────┴─────────────────────┴─────────────┴──────────────────────────────────────┴─────────┘',
'? Select a Device Profile. 2',
'┌───┬─────┐',
'│ # │ Tag │',
'├───┼─────┤',
'│ 1 │ en │',
'│ 2 │ es │',
'└───┴─────┘',
'',
'$ smartthings deviceprofiles:translations 2',
'$ smartthings deviceprofiles:translations 3acbf2fc-6be2-4be0-aeb5-c10f4ff357bb',
'┌───┬─────┐',
'│ # │ Tag │',
'├───┼─────┤',
'│ 1 │ en │',
'│ 2 │ es │',
'└───┴─────┘',
'',
'$ smartthings deviceprofiles:translations 2 2',
'$ smartthings deviceprofiles:translations 2 en',
'$ smartthings deviceprofiles:translations 3acbf2fc-6be2-4be0-aeb5-44759cbd66c2 en',
'Tag: en',
'┌───────────┬────────────┬───────────────────────────────┐',
'│ Component │ Label │ Description │',
'├───────────┼────────────┼───────────────────────────────┤',
'│ main │ Main Power │ Controls power to all outlets │',
'│ outlet1 │ Outlet One │ Switchable outlet 1 power │',
'│ outlet2 │ Outlet two │ Switchable outlet 1 power │',
'└───────────┴────────────┴───────────────────────────────┘',
]
async run(): Promise<void> {
const deviceProfileId = await chooseDeviceProfile(this, this.args.id, { verbose: this.flags.verbose, allowIndex: true })
const config: OutputItemOrListConfig<DeviceProfileTranslations, LocaleReference> = {
primaryKeyName: 'tag',
sortKeyName: 'tag',
buildTableOutput: data => buildTableOutput(this.tableGenerator, data),
listTableFieldDefinitions: ['tag'],
}
await outputItemOrList(this, config, this.args.tag,
() => this.client.deviceProfiles.listLocales(deviceProfileId),
tag => this.client.deviceProfiles.getTranslations(deviceProfileId, tag))
}
}