-
Notifications
You must be signed in to change notification settings - Fork 104
/
delete.ts
63 lines (53 loc) · 2.88 KB
/
delete.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
import { LocaleReference } from '@smartthings/core-sdk'
import { APIOrganizationCommand, selectFromList, SelectFromListConfig } from '@smartthings/cli-lib'
import { chooseDeviceProfile } from '../../../lib/commands/deviceprofiles-util'
export default class DeviceProfileTranslationsDeleteCommand extends APIOrganizationCommand<typeof DeviceProfileTranslationsDeleteCommand.flags> {
static description = 'delete a device profile translation'
static flags = APIOrganizationCommand.flags
static args = [
{
name: 'id',
description: 'device profile UUID or number in the list',
},
{
name: 'tag',
description: 'the locale tag',
},
]
static examples = [
'$ smartthings deviceprofiles:translations:delete 3acbf2fc-6be2-4be0-aeb5-44759cbd66c2 en',
'Device profile "3acbf2fc-6be2-4be0-aeb5-44759cbd66c2" translation "en" deleted',
'',
'$ smartthings deviceprofiles:translations:delete',
'┌────┬─────────────────────┬─────────────┬──────────────────────────────────────┐',
'│ # │ Name │ Status │ Id │',
'├────┼─────────────────────┼─────────────┼──────────────────────────────────────┤',
'│ 1 │ Test Switch │ DEVELOPMENT │ 58e73d0c-b5a5-4814-b344-c10f4ff357bb │',
'│ 2 │ Two Channel Outlet │ DEVELOPMENT │ 3acbf2fc-6be2-4be0-aeb5-44759cbd66c2 │',
'└────┴─────────────────────┴─────────────┴──────────────────────────────────────┘',
'? Enter id or index 2',
'┌───┬─────┐',
'│ # │ Tag │',
'├───┼─────┤',
'│ 1 │ en │',
'│ 2 │ es │',
'└───┴─────┘',
'? Enter id or index 1',
'Device profile "3acbf2fc-6be2-4be0-aeb5-44759cbd66c2" translation "en" deleted',
]
async run(): Promise<void> {
const deviceProfileId = await chooseDeviceProfile(this, this.args.id)
const localeTagSelectConfig: SelectFromListConfig<LocaleReference> = {
primaryKeyName: 'tag',
sortKeyName: 'tag',
listTableFieldDefinitions: ['tag'],
}
const localeTag = await selectFromList(this, localeTagSelectConfig, {
preselectedId: this.args.tag,
listItems: () => this.client.deviceProfiles.listLocales(deviceProfileId),
promptMessage: 'Select a locale:',
})
await this.client.deviceProfiles.deleteTranslations(deviceProfileId, localeTag)
this.log(`Translation ${localeTag} deleted from device profile ${deviceProfileId}.`)
}
}