| 41 | .split(''); |
| 42 | |
| 43 | export const shouldReadStdin = (args) => { |
| 44 | const cmd = args[0]; |
| 45 | const cmdInfo = SHELLJS_PIPE_INFO[cmd]; |
| 46 | const parsedArgs = minimist(args.slice(1), { |
| 47 | stopEarly: true, |
| 48 | boolean: allOptionsList, // treat all short options as booleans |
| 49 | }); |
| 50 | let requiredNumArgs = cmdInfo ? cmdInfo.minArgs : -1; |
| 51 | |
| 52 | // If a non-boolean option is passed in, increment the required argument |
| 53 | // count (this is the case for `-n` for `head` and `tail`) |
| 54 | if (parsedArgs.n && (cmd === 'head' || cmd === 'tail')) { |
| 55 | requiredNumArgs++; |
| 56 | } |
| 57 | |
| 58 | return Boolean(!process.stdin.isTTY && parsedArgs._.length < requiredNumArgs); |
| 59 | }; |