Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(version): support --version flag #138

Merged
merged 1 commit into from
Jun 20, 2018
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
Empty file modified src/printCmdRet.js
100755 → 100644
Empty file.
6 changes: 6 additions & 0 deletions src/shx.js
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ shell.help = help;

export function shx(argv) {
const parsedArgs = minimist(argv.slice(2), { stopEarly: true, boolean: true });
if (parsedArgs.version) {
const shxVersion = require('../package.json').version;
const shelljsVersion = require('shelljs/package.json').version;
console.log(`shx v${shxVersion} (using ShellJS v${shelljsVersion})`);
return EXIT_CODES.SUCCESS;
}
const [fnName, ...args] = parsedArgs._;
if (!fnName) {
console.error('Error: Missing ShellJS command name');
Expand Down
33 changes: 21 additions & 12 deletions test/specs/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,19 +115,20 @@ describe('cli', () => {
output.stderr.should.equal('');
});

it('allows --silent to change config.silent', () => {
const output = cli('--silent', 'ls', 'fakeFileName');
output.stdout.should.equal('');
output.stderr.should.equal('');
output.code.should.equal(2);
});
describe('global flags', () => {
it('supports --version', () => {
const output = cli('--version');
output.stdout.should.match(/shx v\S+ \(using ShellJS v\S+\)\n/);
output.stderr.should.equal('');
output.code.should.equal(0);
});

it('accepts stdin', () => {
mocks.stdin('foo\nbar\nfoobar');
const output = cli('grep', 'foo');
output.stdout.should.equal('foo\nfoobar\n');
output.stderr.should.equal('');
output.code.should.equal(0);
it('allows --silent to change config.silent', () => {
const output = cli('--silent', 'ls', 'fakeFileName');
output.stdout.should.equal('');
output.stderr.should.equal('');
output.code.should.equal(2);
});
});

describe('stdin', () => {
Expand All @@ -136,6 +137,14 @@ describe('cli', () => {
process.stdin.isTTY = oldTTY;
});

it('has basic support', () => {
mocks.stdin('foo\nbar\nfoobar');
const output = cli('grep', 'foo');
output.stdout.should.equal('foo\nfoobar\n');
output.stderr.should.equal('');
output.code.should.equal(0);
});

it('reads stdin for commands that accept stdin', () => {
process.stdin.isTTY = undefined;
shouldReadStdin(['cat']).should.equal(true);
Expand Down