-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathcreate.ts
More file actions
83 lines (74 loc) · 2.24 KB
/
create.ts
File metadata and controls
83 lines (74 loc) · 2.24 KB
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
import type {CreateUserFolderBody} from '@hackmd/api'
import {Flags, ux} from '@oclif/core'
import HackMDCommand from '../../command'
import {
folderColor,
folderDescription,
folderIcon,
folderName,
parentFolderId,
} from '../../flags'
export default class Create extends HackMDCommand {
static description = 'Create a folder'
static examples = [
`$ hackmd-cli folders create --name='docs' --parentFolderId=fc7a3d48-4a07-4cbf-bf4f-e65dd896e01c --description='Docs' --icon=1F600 --color=#4F46E5
ID Name Parent Folder ID Color Description Icon
──────────────────────────────────── ──── ──────────────────────────────────── ─────── ─────────── ─────
a1b2c3d4-e5f6-4a7b-8c9d-0e1f2a3b4c5d docs fc7a3d48-4a07-4cbf-bf4f-e65dd896e01c #4F46E5 Docs 1F600`,
]
static flags = {
color: folderColor,
description: folderDescription,
help: Flags.help({char: 'h'}),
icon: folderIcon,
name: folderName,
parentFolderId,
...ux.table.flags(),
}
async run() {
const {flags} = await this.parse(Create)
const {color, description, icon, name, parentFolderId} = flags
if (!name) {
this.error('Flag name could not be empty')
}
const payload: CreateUserFolderBody = {
color,
description,
icon,
name,
parentFolderId,
}
try {
const APIClient = await this.getAPIClient()
const folder = await APIClient.createFolder(payload)
ux.table(
[folder],
Object.fromEntries([
[
'id',
{
header: 'ID',
},
],
['name', {}],
[
'parentFolderId',
{
header: 'Parent Folder ID',
},
],
['color', {}],
['description', {}],
['icon', {}],
]),
{
printLine: this.log.bind(this),
...flags,
},
)
} catch (error) {
this.log('Create folder failed')
this.error(error as Error)
}
}
}