diff --git a/cli.js b/cli.js index f4df290..3bb8087 100755 --- a/cli.js +++ b/cli.js @@ -9,12 +9,12 @@ const fileType = require('file-type'); const cli = meow(` Usage $ open-cli [--wait] [--background] [-- [args]] - $ cat | open-cli [--ext] [--wait] [--background] [-- [args]] + $ cat | open-cli [--extension] [--wait] [--background] [-- [args]] Options --wait Wait for the app to exit --background Do not bring the app to the foreground (macOS only) - --ext File extension for when stdin file type can't be detected + --extension File extension for when stdin file type can't be detected Examples $ open-cli https://sindresorhus.com @@ -22,7 +22,7 @@ const cli = meow(` $ open-cli https://sindresorhus.com -- 'google chrome' --incognito $ open-cli unicorn.png $ cat unicorn.png | open-cli - $ echo '

Unicorns!

' | open-cli --ext=html + $ echo '

Unicorns!

' | open-cli --extension=html `, { flags: { wait: { @@ -33,7 +33,7 @@ const cli = meow(` type: 'boolean', default: false }, - ext: { + extension: { type: 'string' } } @@ -48,13 +48,13 @@ if (!input && process.stdin.isTTY) { process.exit(1); } -if (input) { - open(input, cli.flags); -} else { - (async () => { +(async () => { + if (input) { + await open(input, cli.flags); + } else { const stdin = await getStdin.buffer(); const type = fileType(stdin); - const ext = cli.flags.ext || (type && type.ext) || 'txt'; - open(tempWrite.sync(stdin, `open.${ext}`), cli.flags); - })(); -} + const extension = cli.flags.extension || (type && type.ext) || 'txt'; + await open(tempWrite.sync(stdin, `open.${extension}`), cli.flags); + } +})(); diff --git a/readme.md b/readme.md index 53d1468..fca0235 100644 --- a/readme.md +++ b/readme.md @@ -17,12 +17,12 @@ $ open-cli --help Usage $ open-cli [--wait] [--background] [-- [args]] - $ cat | open-cli [--ext] [--wait] [--background] [-- [args]] + $ cat | open-cli [--extension] [--wait] [--background] [-- [args]] Options --wait Wait for the app to exit --background Do not bring the app to the foreground (macOS only) - --ext File extension for when stdin file type can't be detected + --extension File extension for when stdin file type can't be detected Examples $ open-cli https://sindresorhus.com @@ -30,7 +30,7 @@ $ open-cli --help $ open-cli https://sindresorhus.com -- 'google chrome' --incognito $ open-cli unicorn.png $ cat unicorn.png | open-cli - $ echo '

Unicorns!

' | open-cli --ext=html + $ echo '

Unicorns!

' | open-cli --extension=html ``` The [following file types](https://github.com/sindresorhus/file-type#supported-file-types) are automagically detected when using stdin mode.