Skip to content

Commit fc95464

Browse files
authored
Merge pull request #58 from hackmdio/feature/export-command
feat: add export command
2 parents 540d994 + bfa9778 commit fc95464

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

src/commands/export.ts

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import {Flags} from '@oclif/core'
2+
3+
import HackMDCommand from '../command'
4+
import {noteId} from '../flags'
5+
6+
export default class Export extends HackMDCommand {
7+
static description = 'Export note content'
8+
9+
static examples = [
10+
`$ hackmd-cli export --noteId=kNFWV5E-Qz-QP7u6XnNvyQ
11+
# A note to be exported
12+
`,
13+
]
14+
15+
static flags = {
16+
help: Flags.help({char: 'h'}),
17+
noteId: noteId()
18+
}
19+
20+
async run() {
21+
const {flags} = await this.parse(Export)
22+
const {noteId} = flags
23+
24+
if (!noteId) {
25+
this.error('Flag noteId could not be empty')
26+
}
27+
28+
try {
29+
const APIClient = await this.getAPIClient()
30+
const note = await APIClient.getNote(noteId)
31+
this.log(note.content)
32+
} catch (e) {
33+
this.log('Export note content failed')
34+
this.error(e as Error)
35+
}
36+
}
37+
}

0 commit comments

Comments
 (0)