Skip to content

Commit 6d6a8f9

Browse files
authored
Merge 90e8c8c into 79ae14d
2 parents 79ae14d + 90e8c8c commit 6d6a8f9

5 files changed

Lines changed: 20 additions & 0 deletions

File tree

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -742,6 +742,11 @@ return value to be an error message. If you need the last error message, use
742742
the `.stderr` attribute from the last command's return value instead.
743743

744744

745+
### errorCode()
746+
747+
Returns the error code from the last command.
748+
749+
745750
### ShellString(str)
746751

747752
Examples:

shell.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ exports.exit = process.exit;
3434
//@include ./src/error.js
3535
exports.error = require('./src/error');
3636

37+
//@include ./src/errorCode.js
38+
exports.errorCode = require('./src/errorCode');
39+
3740
//@include ./src/common.js
3841
exports.ShellString = common.ShellString;
3942

src/errorCode.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
var common = require('./common');
2+
3+
//@
4+
//@ ### errorCode()
5+
//@
6+
//@ Returns the error code from the last command.
7+
function errorCode() {
8+
return common.state.errorCode;
9+
}
10+
module.exports = errorCode;

test/grep.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ test('no args', t => {
2424
const result = shell.grep();
2525
t.truthy(shell.error());
2626
t.is(result.code, 2);
27+
t.is(shell.errorCode(), 2);
2728
});
2829

2930
test('too few args', t => {

test/ls.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ test('it\'s ok to use no arguments', t => {
4040
const result = shell.ls();
4141
t.falsy(shell.error());
4242
t.is(result.code, 0);
43+
t.is(shell.errorCode(), 0);
4344
});
4445

4546
test('root directory', t => {

0 commit comments

Comments
 (0)