Skip to content

Commit

Permalink
fix: catch cli open shortcut errors (#342)
Browse files Browse the repository at this point in the history
Co-authored-by: Mix <mnixry@users.noreply.github.com>
Co-authored-by: Anthony Fu <anthonyfu117@hotmail.com>
  • Loading branch information
3 people committed Sep 13, 2021
1 parent d676950 commit 4c2b0c7
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions packages/slidev/node/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,18 +126,21 @@ cli.command(
const SHORTCUTS = [
{
name: 'r',
fullname: 'restart',
action() {
initServer()
},
},
{
name: 'o',
fullname: 'open',
action() {
openBrowser(`http://localhost:${port}`)
},
},
{
name: 'e',
fullname: 'edit',
action() {
exec(`code "${entry}"`)
},
Expand All @@ -149,9 +152,15 @@ cli.command(
process.stdin.setEncoding('utf8')
process.stdin.on('data', (data) => {
const str = data.toString().trim().toLowerCase()
const sh = SHORTCUTS.filter(item => item.name === str)[0]
if (sh)
sh.action()
const [sh] = SHORTCUTS.filter(item => item.name === str)
if (sh) {
try {
sh.action()
}
catch (err) {
console.error(`Failed to execute shortcut ${sh.fullname}`, err)
}
}
})
}

Expand Down

0 comments on commit 4c2b0c7

Please sign in to comment.