Skip to content

Commit

Permalink
Rename --ext flag to --extension
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed May 13, 2019
1 parent e9ad82c commit a6a6e3a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
24 changes: 12 additions & 12 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@ const fileType = require('file-type');
const cli = meow(`
Usage
$ open-cli <file|url> [--wait] [--background] [-- <app> [args]]
$ cat <file> | open-cli [--ext] [--wait] [--background] [-- <app> [args]]
$ cat <file> | open-cli [--extension] [--wait] [--background] [-- <app> [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
$ open-cli https://sindresorhus.com -- firefox
$ open-cli https://sindresorhus.com -- 'google chrome' --incognito
$ open-cli unicorn.png
$ cat unicorn.png | open-cli
$ echo '<h1>Unicorns!</h1>' | open-cli --ext=html
$ echo '<h1>Unicorns!</h1>' | open-cli --extension=html
`, {
flags: {
wait: {
Expand All @@ -33,7 +33,7 @@ const cli = meow(`
type: 'boolean',
default: false
},
ext: {
extension: {
type: 'string'
}
}
Expand All @@ -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);
}
})();
6 changes: 3 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,20 @@ $ open-cli --help
Usage
$ open-cli <file|url> [--wait] [--background] [-- <app> [args]]
$ cat <file> | open-cli [--ext] [--wait] [--background] [-- <app> [args]]
$ cat <file> | open-cli [--extension] [--wait] [--background] [-- <app> [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
$ open-cli https://sindresorhus.com -- firefox
$ open-cli https://sindresorhus.com -- 'google chrome' --incognito
$ open-cli unicorn.png
$ cat unicorn.png | open-cli
$ echo '<h1>Unicorns!</h1>' | open-cli --ext=html
$ echo '<h1>Unicorns!</h1>' | open-cli --extension=html
```

The [following file types](https://github.com/sindresorhus/file-type#supported-file-types) are automagically detected when using stdin mode.
Expand Down

0 comments on commit a6a6e3a

Please sign in to comment.