Skip to content

Commit

Permalink
feat: add stdin flag
Browse files Browse the repository at this point in the history
Signed-off-by: Jakub Freisler <jakub@frsource.org>
  • Loading branch information
FRSgit committed Feb 4, 2023
1 parent 27dbeb4 commit 7574b49
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ frs-replace <regex> <replacement> [options]
|&#8209;i, &#8209;&#8209;input | string or string[] | *-* | Path to files or [fast-glob](https://github.com/mrmlnc/fast-glob) pattern pointing to files to be read & replaced from. If multiple files specified results will be joined using `outputJoinString` option's value) |
| &#8209;&#8209;i-read-opts | string or object | utf8 | Options which are passed directly to the [readFileSync method](https://nodejs.org/api/fs.html#fs_fs_readfilesync_path_options) when reading input file |
| &#8209;&#8209;i-glob-opts | object | *undefined* | Options which are passed directly to the [fast-glob package](https://github.com/mrmlnc/fast-glob#options-1) when resolving glob patterns |
| &#8209;&#8209;stdin | boolean | *true* | Wait for stdin input (should be set to *false* when used in non-interactive terminals) |
| &#8209;o, &#8209;&#8209;output | string | *-* | Output file name/path (replaces the file if it already exists and creates any intermediate directories if they don't already exist) |
| &#8209;&#8209;o-write-opts | string or object | utf8 | Passed as options argument of [write's .sync](https://www.npmjs.com/package/write#sync) |
| &#8209;&#8209;o-join-str | string | \n | Used when joining multiple files, passed directly to [javascript join](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/join#Syntax) |
Expand Down
8 changes: 6 additions & 2 deletions bin/cli.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env node
const replaceSync = require('../sync')

require('get-stdin')().then((stdin) => {
(~process.argv.indexOf('--no-stdin') ? Promise.resolve() : require('get-stdin')()).then((stdin) => {
const isPiped = !!stdin

if (isPiped) {
Expand Down Expand Up @@ -48,7 +48,6 @@ require('get-stdin')().then((stdin) => {
.choices('f', ['', 'g', 'm', 'i', 'gm', 'gi', 'mi', 'mg', 'ig', 'im', 'gmi', 'gim', 'mig', 'mgi', 'igm', 'img'])
.default('f', 'g')
.coerce('f', arg => arg.trim())

.option('i', { demandOption: !isContentPresent && !isHelpPresent })
.alias('i', 'input')
.describe('i', 'Path to files or fast-glob pattern pointing to files to read & replace from')
Expand All @@ -63,6 +62,11 @@ require('get-stdin')().then((stdin) => {
.describe('i-glob-opts', 'Passed to fast-glob.sync when resolving glob patterns')
.implies('i-glob-opts', 'i')

.option('stdin')
.describe('stdin', 'Wait for stdin input (should be set to false when used in non-interactive terminals)')
.boolean('stdin')
.default('stdin', true)

.option('c', { demandOption: isContentPresent })
.alias('c', 'content')
.describe('c', 'Content to be replaced (takes precedence over stream & file input)')
Expand Down

0 comments on commit 7574b49

Please sign in to comment.