Skip to content

Commit

Permalink
fix(spawn): support string argument
Browse files Browse the repository at this point in the history
  • Loading branch information
curbengh committed Jul 23, 2020
1 parent cd6dcfd commit a2905ed
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,13 @@ Option | Description | Default
`encoding` | Sets the encoding of the output string | `utf8`

``` js
spawn('cat', 'test.txt').then(function(content){
spawn('cat', 'test.txt').then((content) => {
console.log(content);
});

// $ cd "/target/folder"
// $ cat "foo.txt" "bar.txt"
spawn('cat', ['foo.txt', 'bar.txt'], { cwd: '/target/folder' }).then((content) => {
console.log(content);
});
```
Expand Down
2 changes: 2 additions & 0 deletions lib/spawn.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ const CacheStream = require('./cache_stream');
function promiseSpawn(command, args = [], options) {
if (!command) throw new TypeError('command is required!');

if (typeof args === 'string') args = [args];

if (!options && !Array.isArray(args)) {
options = args;
args = [];
Expand Down
2 changes: 2 additions & 0 deletions test/spawn.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ describe('spawn', () => {

it('default', () => spawn(catCommand, [fixturePath]).should.become(fixture));

it('default - string', () => spawn(catCommand, fixturePath).should.become(fixture));

it('command is required', () => {
spawn.should.throw('command is required!');
});
Expand Down

0 comments on commit a2905ed

Please sign in to comment.