Comparing version 0.2.0 to 0.2.1
@@ -6,2 +6,12 @@ #!/usr/bin/env node | ||
var _minimist = require('minimist'); | ||
var _minimist2 = _interopRequireDefault(_minimist); | ||
var _config = require('./config'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var parsedArgs = (0, _minimist2.default)(process.argv.slice(2), { stopEarly: true, boolean: true }); | ||
// `input` is null if we're running from a TTY, or a string of all stdin if | ||
@@ -28,6 +38,3 @@ // running from the right-hand side of a pipe | ||
// ShellJS doesn't support input streams, so we have to collect all input first | ||
if (process.stdin.isTTY) { | ||
// There's no stdin, so we can immediately invoke the ShellJS function | ||
run(null); | ||
} else { | ||
if ((0, _config.shouldReadStdin)(parsedArgs._)) { | ||
(function () { | ||
@@ -43,2 +50,5 @@ // Read all stdin first, and then pass that onto ShellJS | ||
})(); | ||
} else { | ||
// There's no stdin, so we can immediately invoke the ShellJS function | ||
run(null); | ||
} |
@@ -6,2 +6,10 @@ 'use strict'; | ||
}); | ||
exports.shouldReadStdin = exports.SHELLJS_PIPE_INFO = exports.CONFIG_FILE = exports.CMD_BLACKLIST = exports.EXIT_CODES = undefined; | ||
var _minimist = require('minimist'); | ||
var _minimist2 = _interopRequireDefault(_minimist); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var EXIT_CODES = exports.EXIT_CODES = { | ||
@@ -15,2 +23,32 @@ SHX_ERROR: 27, // https://xkcd.com/221/ | ||
var CONFIG_FILE = exports.CONFIG_FILE = '.shxrc.json'; | ||
var CONFIG_FILE = exports.CONFIG_FILE = '.shxrc.json'; | ||
var SHELLJS_PIPE_INFO = exports.SHELLJS_PIPE_INFO = { | ||
cat: { minArgs: 1 }, | ||
grep: { minArgs: 2 }, | ||
head: { minArgs: 1 }, | ||
sed: { minArgs: 2 }, | ||
sort: { minArgs: 1 }, | ||
tail: { minArgs: 1 }, | ||
uniq: { minArgs: 1 } | ||
}; | ||
// All valid options | ||
var allOptionsList = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'.split(''); | ||
var shouldReadStdin = exports.shouldReadStdin = function shouldReadStdin(args) { | ||
var cmd = args[0]; | ||
var cmdInfo = SHELLJS_PIPE_INFO[cmd]; | ||
var parsedArgs = (0, _minimist2.default)(args.slice(1), { | ||
stopEarly: true, | ||
boolean: allOptionsList }); | ||
var requiredNumArgs = cmdInfo ? cmdInfo.minArgs : -1; | ||
// If a non-boolean option is passed in, incrememnt the required argument | ||
// count (this is the case for `-n` for `head` and `tail`) | ||
if (parsedArgs.n && (cmd === 'head' || cmd === 'tail')) { | ||
requiredNumArgs++; | ||
} | ||
return Boolean(!process.stdin.isTTY && parsedArgs._.length < requiredNumArgs); | ||
}; |
@@ -48,8 +48,6 @@ #!/usr/bin/env node | ||
var _parsedArgs$_ = _toArray(parsedArgs._); | ||
var _parsedArgs$_ = _toArray(parsedArgs._), | ||
fnName = _parsedArgs$_[0], | ||
args = _parsedArgs$_.slice(1); | ||
var fnName = _parsedArgs$_[0]; | ||
var args = _parsedArgs$_.slice(1); | ||
if (!fnName) { | ||
@@ -56,0 +54,0 @@ console.error('Error: Missing ShellJS command name'); |
{ | ||
"name": "shx", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"description": "Portable Shell Commands for Node", | ||
@@ -5,0 +5,0 @@ "bin": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
21150
215
0