-
Notifications
You must be signed in to change notification settings - Fork 112
/
Copy pathupsert.ts
74 lines (66 loc) · 3.06 KB
/
upsert.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
import { CapabilityLocalization } from '@smartthings/core-sdk'
import { APIOrganizationCommand, inputAndOutputItem } from '@smartthings/cli-lib'
import { buildTableOutput } from '../translations'
import { capabilityIdInputArgs, chooseCapability } from '../../../lib/commands/capabilities-util'
export default class CapabilityTranslationsUpsertCommand extends APIOrganizationCommand<typeof CapabilityTranslationsUpsertCommand.flags> {
static description = 'create or update a capability translation' +
this.apiDocsURL('updateCapabilityLocalization', 'createCapabilityLocalization')
static flags = {
...APIOrganizationCommand.flags,
...inputAndOutputItem.flags,
}
static args = capabilityIdInputArgs
static examples = [
'$ smartthings capabilities:translations:upsert custom1.outputModulation 1 -i en.yaml ',
'tag: en\n' +
'label: Output Modulation\n' +
'attributes:\n' +
' outputModulation:\n' +
' label: Output Modulation\n' +
' displayTemplate: \'The {{attribute}} of {{device.label}} is {{value}}\'\n' +
' i18n:\n' +
' value:\n' +
' 50hz:\n' +
' label: 50 Hz\n' +
' 60hz:\n' +
' label: 60 Hz\n' +
'commands:\n' +
' setOutputModulation:\n' +
' label: Set Output Modulation\n' +
' arguments:\n' +
' outputModulation:\n' +
' label: Output Modulation',
'$ smartthings capabilities:translations:upsert -i en.yaml',
'┌───┬─────────────────────────────┬─────────┬──────────┐\n' +
'│ # │ Id │ Version │ Status │\n' +
'├───┼─────────────────────────────┼─────────┼──────────┤\n' +
'│ 1 │ custom1.outputModulation │ 1 │ proposed │\n' +
'│ 2 │ custom1.outputVoltage │ 1 │ proposed │\n' +
'└───┴─────────────────────────────┴─────────┴──────────┘',
'? Enter id or index 1',
'tag: en\n' +
'label: Output Modulation\n' +
'attributes:\n' +
' outputModulation:\n' +
' label: Output Modulation\n' +
' displayTemplate: \'The {{attribute}} of {{device.label}} is {{value}}\'\n' +
' i18n:\n' +
' value:\n' +
' 50hz:\n' +
' label: 50 Hz\n' +
' 60hz:\n' +
' label: 60 Hz\n' +
'commands:\n' +
' setOutputModulation:\n' +
' label: Set Output Modulation\n' +
' arguments:\n' +
' outputModulation:\n' +
' label: Output Modulation',
]
async run(): Promise<void> {
const id = await chooseCapability(this, this.args.id, this.args.version)
await inputAndOutputItem<CapabilityLocalization, CapabilityLocalization>(this,
{ buildTableOutput: data => buildTableOutput(this.tableGenerator, data) },
(_, translations) => this.client.capabilities.upsertTranslations(id.id, id.version, translations))
}
}