Skip to content

Commit a16afdc

Browse files
James TsaiJames Tsai
authored andcommitted
refactor: read pipe when creating note
1 parent e2958e8 commit a16afdc

File tree

5 files changed

+97
-52
lines changed

5 files changed

+97
-52
lines changed

package-lock.json

Lines changed: 77 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
"bugs": "https://github.com/hackmdio/hackmd-cli/issues",
99
"dependencies": {
1010
"@hackmd/api": "^2.0.0-pre.0",
11-
"@oclif/command": "^1.5.19",
12-
"@oclif/config": "^1.13.3",
1311
"@oclif/core": "^1.3.6",
1412
"@oclif/plugin-help": "^2.2.3",
1513
"@oclif/plugin-version": "^1.0.4",

src/commands/notes/create.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,20 @@ import { CommentPermissionType, CreateNoteOptions, NotePermissionRole } from '@h
22
import {CliUx, Command, Flags} from '@oclif/core'
33

44
import {APIClient} from '../../api'
5+
import readStdin from '../../read-stdin-stream'
56

67
export default class Create extends Command {
78
static description = 'Create a note'
89

910
static examples = [
10-
`notes create --content='# A new note' --readPermission=owner --writePermission=owner --commentPermission=disabled
11-
ID Title User Path Team Path
11+
`notes create --content='# A new note' --readPermission=owner --writePermission=owner --commentPermission=disabled`,
12+
13+
`ID Title User Path Team Path
1214
────────────────────── ──────────────────────────────── ────────────────────── ────────
13-
raUuSTetT5uQbqQfLnz9lA A new note gvfz2UB5THiKABQJQnLs6Q null `
15+
raUuSTetT5uQbqQfLnz9lA A new note gvfz2UB5THiKABQJQnLs6Q null`,
16+
17+
`Or you can pipe content via Unix pipeline:`,
18+
`cat README.md | hackmd-cli notes create`
1419
]
1520

1621
static flags = {
@@ -25,9 +30,12 @@ raUuSTetT5uQbqQfLnz9lA A new note gvfz2UB5THiKABQJQnLs6Q
2530

2631
async run() {
2732
const {flags} = await this.parse(Create)
33+
const pipeString = await readStdin()
34+
if (pipeString) return
35+
2836
const options: CreateNoteOptions = {
2937
title: flags.title,
30-
content: flags.content,
38+
content: pipeString || flags.content,
3139
readPermission: flags.readPermission as NotePermissionRole,
3240
writePermission: flags.writePermission as NotePermissionRole,
3341
commentPermission: flags.commentPermission as CommentPermissionType

src/commands/team-notes/create.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { CommentPermissionType, CreateNoteOptions, NotePermissionRole } from '@h
22
import {CliUx, Command, Flags} from '@oclif/core'
33

44
import {APIClient} from '../../api'
5+
import readStdin from '../../read-stdin-stream'
56

67
export default class Create extends Command {
78
static description = 'Create a team note'
@@ -10,7 +11,10 @@ export default class Create extends Command {
1011
`team-notes:create --teamPath=CLI-test --content='# A new note' --readPermission=owner --writePermission=owner --commentPermission=disabled
1112
ID Title User Path Team Path
1213
────────────────────── ──────────────────────────────── ────────────────────── ────────
13-
raUuSTetT5uQbqQfLnz9lA A new note gvfz2UB5THiKABQJQnLs6Q null `
14+
raUuSTetT5uQbqQfLnz9lA A new note gvfz2UB5THiKABQJQnLs6Q null `,
15+
16+
`Or you can pipe content via Unix pipeline:`,
17+
`cat README.md | hackmd-cli notes create --teamPath=CLI-test`
1418
]
1519

1620
static flags = {
@@ -26,10 +30,12 @@ raUuSTetT5uQbqQfLnz9lA A new note gvfz2UB5THiKABQJQnLs6Q n
2630

2731
async run() {
2832
const {flags} = await this.parse(Create)
33+
const pipeString = await readStdin()
34+
2935
const {teamPath} = flags
3036
const options: CreateNoteOptions = {
3137
title: flags.title,
32-
content: flags.content,
38+
content: pipeString || flags.content,
3339
readPermission: flags.readPermission as NotePermissionRole,
3440
writePermission: flags.writePermission as NotePermissionRole,
3541
commentPermission: flags.commentPermission as CommentPermissionType

src/index.ts

Lines changed: 0 additions & 34 deletions
This file was deleted.

0 commit comments

Comments
 (0)