Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -742,6 +742,11 @@ return value to be an error message. If you need the last error message, use
the `.stderr` attribute from the last command's return value instead.


### errorCode()

Returns the error code from the last command.


### ShellString(str)

Examples:
Expand Down
3 changes: 3 additions & 0 deletions shell.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ exports.exit = process.exit;
//@include ./src/error.js
exports.error = require('./src/error');

//@include ./src/errorCode.js
exports.errorCode = require('./src/errorCode');

//@include ./src/common.js
exports.ShellString = common.ShellString;

Expand Down
10 changes: 10 additions & 0 deletions src/errorCode.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
var common = require('./common');

//@
//@ ### errorCode()
//@
//@ Returns the error code from the last command.
function errorCode() {
return common.state.errorCode;
}
module.exports = errorCode;
1 change: 1 addition & 0 deletions test/grep.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ test('no args', t => {
const result = shell.grep();
t.truthy(shell.error());
t.is(result.code, 2);
t.is(shell.errorCode(), 2);
});

test('too few args', t => {
Expand Down
1 change: 1 addition & 0 deletions test/ls.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ test('it\'s ok to use no arguments', t => {
const result = shell.ls();
t.falsy(shell.error());
t.is(result.code, 0);
t.is(shell.errorCode(), 0);
});

test('root directory', t => {
Expand Down