forked from shelljs/shelljs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShellString.js
More file actions
39 lines (38 loc) · 1.11 KB
/
Copy pathShellString.js
File metadata and controls
39 lines (38 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
var shell = require('..');
var plugin = require('./plugin');
//@
//@ ### ShellString(str)
//@
//@ Examples:
//@
//@ ```javascript
//@ var foo = ShellString('hello world');
//@ ```
//@
//@ Turns a regular string into a string-like object similar to what each
//@ command returns. This has special methods, like `.to()` and `.toEnd()
var ShellString = function (stdout, stderr, code) {
var that;
if (stdout instanceof Array) {
that = stdout;
that.stdout = stdout.join('\n');
if (stdout.length > 0) that.stdout += '\n';
} else {
that = new String(stdout);
that.stdout = stdout;
}
if (!stderr) {
stderr = plugin.state.stderr;
plugin.state.stderr = '';
}
if (!code) {
code = plugin.state.code;
plugin.state.code = 0;
}
that.stderr = stderr;
that.code = code;
that.to = function() {wrap('to', _to, {idx: 1}).apply(that.stdout, arguments); return that;};
that.toEnd = function() {wrap('toEnd', _toEnd, {idx: 1}).apply(that.stdout, arguments); return that;};
plugin.pipeCommands.forEach(({ name, func }) => that[name] = (...args) => func.apply(that.stdout, args));
return that;
};