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

fixes tests #794

Merged
merged 1 commit into from
May 2, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ exports.Option = Option;

function Option(flags, description) {
this.flags = flags;
this.required = ~flags.indexOf('<');
this.optional = ~flags.indexOf('[');
this.bool = !~flags.indexOf('-no-');
this.required = flags.indexOf('<') >= 0;
this.optional = flags.indexOf('[') >= 0;
this.bool = flags.indexOf('-no-') === -1;
flags = flags.split(/[ ,|]+/);
if (flags.length > 1 && !/^[[<]/.test(flags[1])) this.short = flags.shift();
this.long = flags.shift();
Expand Down
4 changes: 2 additions & 2 deletions test/test.command.name.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ program

program.parse(['node', 'test']);

program.name.should.be.a.Function;
program.name.should.be.a.Function();
program.name().should.equal('test');
program.commands[0].name().should.equal('mycommand');
program.commands[1].name().should.equal('help');
Expand All @@ -21,4 +21,4 @@ output[0].should.containEql([
' mycommand [options] this is my command'
].join('\n'));

sinon.restore();
sinon.restore();
2 changes: 1 addition & 1 deletion test/test.command.name.set.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ sinon.stub(process.stdout, 'write');

program.name('foobar').description('This is a test.');

program.name.should.be.a.Function;
program.name.should.be.a.Function();
program.name().should.equal('foobar');
program.description().should.equal('This is a test.');

Expand Down
2 changes: 1 addition & 1 deletion test/test.literal.args.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ program
.option('-b, --bar', 'add some bar');

program.parse(['node', 'test', '--foo', '--', '--bar', 'baz']);
program.foo.should.be.true;
program.foo.should.be.true();
should.equal(undefined, program.bar);
program.args.should.eql(['--bar', 'baz']);

Expand Down
2 changes: 1 addition & 1 deletion test/test.options.args.optional.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ program
.option('-c, --cheese [type]', 'optionally specify the type of cheese');

program.parse(['node', 'test', '--cheese']);
program.cheese.should.be.true;
program.cheese.should.be.true();
4 changes: 2 additions & 2 deletions test/test.options.bool.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ program
.option('-c, --no-cheese', 'remove cheese');

program.parse(['node', 'test', '--pepper']);
program.pepper.should.be.true;
program.cheese.should.be.true;
program.pepper.should.be.true();
program.cheese.should.be.true();
2 changes: 1 addition & 1 deletion test/test.options.bool.no.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ program

program.parse(['node', 'test', '--no-cheese']);
should.equal(undefined, program.pepper);
program.cheese.should.be.false;
program.cheese.should.be.false();
4 changes: 2 additions & 2 deletions test/test.options.bool.small.combined.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ program
.option('-c, --no-cheese', 'remove cheese');

program.parse(['node', 'test', '-pc']);
program.pepper.should.be.true;
program.cheese.should.be.false;
program.pepper.should.be.true();
program.cheese.should.be.false();
4 changes: 2 additions & 2 deletions test/test.options.bool.small.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ program
.option('-c, --no-cheese', 'remove cheese');

program.parse(['node', 'test', '-p', '-c']);
program.pepper.should.be.true;
program.cheese.should.be.false;
program.pepper.should.be.true();
program.cheese.should.be.false();
23 changes: 12 additions & 11 deletions test/test.options.commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ program

program.parse(['node', 'test', '--config', 'conf']);
program.config.should.equal("conf");
program.commands[0].should.not.have.property.setup_mode;
program.commands[1].should.not.have.property.exec_mode;
program.commands[0].should.not.have.property('setup_mode');
program.commands[1].should.not.have.property('exec_mode');
envValue.should.equal("");
cmdValue.should.equal("");

program.parse(['node', 'test', '--config', 'conf1', 'setup', '--setup_mode', 'mode3', 'env1']);
program.parse(['node', 'test', '--config', 'conf1', 'setup', '--setup_mode', 'mode2', 'env1']);
program.config.should.equal("conf1");
program.commands[0].setup_mode.should.equal("mode3");
program.commands[0].should.not.have.property.host;
program.commands[0].setup_mode.should.equal("mode2");
program.commands[0].should.not.have.property('host');
envValue.should.equal("env1");

program.parse(['node', 'test', '--config', 'conf2', 'setup', '--setup_mode', 'mode3', '-o', 'host1', 'env2']);
Expand All @@ -72,24 +72,25 @@ envValue.should.equal("env3");
program.parse(['node', 'test', '--config', 'conf4', 'exec', '--exec_mode', 'mode1', 'exec1']);
program.config.should.equal("conf4");
program.commands[1].exec_mode.should.equal("mode1");
program.commands[1].should.not.have.property.target;
program.commands[1].should.not.have.property('target');
cmdValue.should.equal("exec1");

program.parse(['node', 'test', '--config', 'conf5', 'exec', '-e', 'mode2', 'exec2']);
program.config.should.equal("conf5");
program.commands[1].exec_mode.should.equal("mode2");
cmdValue.should.equal("exec2");

program.parse(['node', 'test', '--config', 'conf6', 'exec', '--target', 'target1', '-e', 'mode2', 'exec3']);
program.parse(['node', 'test', '--config', 'conf6', 'exec', '--target', 'target1', '-e', 'mode6', 'exec3']);
program.config.should.equal("conf6");
program.commands[1].exec_mode.should.equal("mode2");
program.commands[1].exec_mode.should.equal("mode6");
program.commands[1].target.should.equal("target1");
cmdValue.should.equal("exec3");

delete program.commands[1].target;
program.parse(['node', 'test', '--config', 'conf7', 'ex', '-e', 'mode3', 'exec4']);
program.config.should.equal("conf7");
program.commands[1].exec_mode.should.equal("mode3");
program.commands[1].should.not.have.property.target;
program.commands[1].should.not.have.property('target');
cmdValue.should.equal("exec4");

// Make sure we still catch errors with required values for options
Expand Down Expand Up @@ -120,5 +121,5 @@ catch (ex) {
}

process.exit = oldProcessExit;
exceptionOccurred.should.be.true;
customHelp.should.be.true;
exceptionOccurred.should.be.true();
customHelp.should.be.true();
12 changes: 6 additions & 6 deletions test/test.options.func.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ program
.option('-q, --quux <quux>', 'add some quux');

program.parse(['node', 'test', '--foo', '--bar', '--no-magic', '--camel-case', '--quux', 'value']);
program.opts.should.be.a.Function;
program.opts.should.be.a.Function();

var opts = program.opts();
opts.should.be.an.Object;
opts.should.be.an.Object();
opts.version.should.equal('0.0.1');
opts.foo.should.be.true;
opts.bar.should.be.true;
opts.magic.should.be.false;
opts.camelCase.should.be.true;
opts.foo.should.be.true();
opts.bar.should.be.true();
opts.magic.should.be.false();
opts.camelCase.should.be.true();
opts.quux.should.equal('value');
2 changes: 1 addition & 1 deletion test/test.options.large-only.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ program
.option('--verbose', 'do stuff');

program.parse(['node', 'test', '--verbose']);
program.verbose.should.be.true;
program.verbose.should.be.true();