Skip to content
This repository has been archived by the owner on Dec 29, 2022. It is now read-only.

Commit

Permalink
Simplify shell.getCommand() method signature
Browse files Browse the repository at this point in the history
  • Loading branch information
lekkas committed Sep 29, 2016
1 parent 0533d53 commit ea185db
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
10 changes: 5 additions & 5 deletions lib/shell.coffee
Expand Up @@ -15,8 +15,9 @@ limitations under the License.
###

child_process = require('child_process')
_ = require('lodash')
os = require('os')
Promise = require('bluebird')
_ = require('lodash')
rindle = require('rindle')

###*
Expand Down Expand Up @@ -51,15 +52,14 @@ exports.getSubShellCommand = (command) ->
# stdin is inherited from the parent process.
#
# @param {String} command - command
# @param {Object} [options] - options
# @param {String} [options.cwd] - current working directory
# @param {String} cwd - current working directory
# @returns {Promise}
#
# @example
# shell.runCommand('echo hello').then ->
# console.log('Done!')
###
exports.runCommand = (command, options = {}) ->
exports.runCommand = Promise.method (command, cwd) ->
env = {}

if os.platform() is 'win32'
Expand All @@ -77,7 +77,7 @@ exports.runCommand = (command, options = {}) ->
spawn = child_process.spawn subShellCommand.program, subShellCommand.args,
stdio: 'inherit'
env: _.merge(env, process.env)
cwd: options.cwd
cwd: cwd

# This is an internal undocumented option that causes
# spawn to execute multiple word commands correctly
Expand Down
8 changes: 4 additions & 4 deletions tests/shell.spec.coffee
Expand Up @@ -60,7 +60,7 @@ describe 'Shell:', ->
@childProcessSpawnStub.restore()

it 'should be rejected with an error', ->
promise = shell.runCommand('echo foo')
promise = shell.runCommand('echo foo', '.')
m.chai.expect(promise).to.be.rejectedWith('spawn error')

describe 'given a spawn that closes with an error code', ->
Expand All @@ -79,7 +79,7 @@ describe 'Shell:', ->
@childProcessSpawnStub.restore()

it 'should be rejected with an error', ->
promise = shell.runCommand('echo foo')
promise = shell.runCommand('echo foo', '.')
m.chai.expect(promise).to.be.rejectedWith('Child process exited with code 1')

describe 'given a spawn that closes with a zero code', ->
Expand All @@ -98,7 +98,7 @@ describe 'Shell:', ->
@childProcessSpawnStub.restore()

it 'should be resolved', ->
promise = shell.runCommand('echo foo')
promise = shell.runCommand('echo foo', '.')
m.chai.expect(promise).to.eventually.be.undefined

describe 'given windows', ->
Expand All @@ -111,7 +111,7 @@ describe 'Shell:', ->
@osPlatformStub.restore()

it 'should call spawn with the correct arguments', ->
shell.runCommand('echo foo')
shell.runCommand('echo foo', '.')
args = @childProcessSpawnStub.firstCall.args
m.chai.expect(args[0]).to.equal('cmd.exe')
m.chai.expect(args[1]).to.deep.equal([ '/s', '/c', 'echo foo' ])
Expand Down

0 comments on commit ea185db

Please sign in to comment.