Skip to content

Commit

Permalink
Restores lost option presets and help texts. Renames lan_prefer => la…
Browse files Browse the repository at this point in the history
…nPrefer to match existing camel cased options
  • Loading branch information
rwaldron committed Nov 25, 2015
1 parent e2cf9f5 commit ead744c
Show file tree
Hide file tree
Showing 3 changed files with 153 additions and 34 deletions.
38 changes: 26 additions & 12 deletions bin/tessel-2.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ function makeCommand(commandName) {
flag: true,
help: 'Use only a USB connection'
})
.option('lan_prefer', {
.option('lanPrefer', {
flag: true,
default: false,
help: 'Prefer a LAN connection if it\'s available, otherwise use USB'
help: 'Prefer a LAN connection when available, otherwise use USB.'
});
}

Expand Down Expand Up @@ -109,13 +109,16 @@ makeCommand('restart')

makeCommand('run')
.callback(function(opts) {
opts.lanPrefer = true;
opts.push = false;
// Overridden in tarBundle if opts.full is `true`
opts.slim = true;
callControllerWith('deployScript', opts);
})
.option('entryPoint', {
position: 1,
required: true,
help: 'The entry point file to deploy to Tessel'
help: 'The program entry point file to deploy to Tessel'
})
.option('single', {
flag: true,
Expand All @@ -129,28 +132,32 @@ makeCommand('run')
})
.option('slim', {
flag: true,
help: 'Bundle only the required modules'
default: true,
help: 'Deploy a single "bundle" file that contains that contains only the required files, excluding any files matched by non-negated rules in .tesselignore and including any files matched by rules in .tesselinclude. Program is run from "slimPath" file (if not provided, a default name is given).',
})
.option('slimPath', {
default: 'build.js'
default: '__tessel_program__.js',
help: 'Specify the name of the --slim bundle file.',
})
// Overrides default lan_prefer because deploys require high bandwidth
.option('lan_prefer', {
.option('full', {
flag: true,
default: true,
help: 'Prefer a LAN connection if it\'s available, otherwise use USB'
default: false,
help: 'Deploy all files in project including those not used by the program, excluding any files matched by non-negated rules in .tesselignore and including any files matched by rules in .tesselinclude. Program is run from specified "entryPoint" file.'
})
.help('Deploy a script to Tessel and run it with Node');

makeCommand('push')
.callback(function(opts) {
opts.lanPrefer = true;
opts.push = true;
// Overridden in tarBundle if opts.full is `true`
opts.slim = true;
callControllerWith('deployScript', opts);
})
.option('entryPoint', {
position: 1,
required: true,
help: 'The entry point file to deploy to Tessel'
help: 'The program entry point file to deploy to Tessel'
})
.option('single', {
flag: true,
Expand All @@ -164,10 +171,17 @@ makeCommand('push')
})
.option('slim', {
flag: true,
help: 'Bundle only the required modules'
default: true,
help: 'Push a single "bundle" file that contains that contains only the required files, excluding any files matched by non-negated rules in .tesselignore and including any files matched by rules in .tesselinclude. Program is run from "slimPath" file (if not provided, a default name is given).'
})
.option('slimPath', {
default: 'index.js'
default: '__tessel_program__.js',
help: 'Specify the name of the --slim bundle file.'
})
.option('full', {
flag: true,
default: false,
help: 'Push all files in project including those not used by the program, excluding any files matched by non-negated rules in .tesselignore and including any files matched by rules in .tesselinclude. Program is run from specified "entryPoint" file.'
})
.help('Pushes the file/dir to Flash memory to be run anytime the Tessel is powered, runs the file immediately once the file is copied over');

Expand Down
127 changes: 116 additions & 11 deletions test/unit/bin-tessel-2.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ var defaults = {
string: '--usb',
},
key: Tessel.LOCAL_AUTH_KEY,
lan_prefer: {
lanPrefer: {
flag: true,
default: false,
help: 'Prefer a LAN connection if it\'s available, otherwise use USB'
Expand Down Expand Up @@ -97,9 +97,7 @@ exports['Tessel (cli: restart)'] = {
test.equal(this.restartScript.callCount, 1);
// We must wait for the command to complete
// or else the sandbox will be cleared too early
setImmediate(function() {
test.done();
});
setImmediate(test.done);
},

exitCodeOne: function(test) {
Expand Down Expand Up @@ -152,7 +150,7 @@ exports['Tessel (cli: update)'] = {
_: ['update'],
timeout: 5,
key: Tessel.LOCAL_AUTH_KEY,
lan_prefer: false
lanPrefer: false
});

cli(['update', '--list', ' ']);
Expand All @@ -175,9 +173,7 @@ exports['Tessel (cli: update)'] = {

// We must wait for the command to complete
// or else the sandbox will be cleared to early
setImmediate(function() {
test.done();
});
setImmediate(test.done);
},

exitCodeOne: function(test) {
Expand Down Expand Up @@ -227,9 +223,7 @@ exports['Tessel (cli: provision)'] = {

// We must wait for the command to complete
// or else the sandbox will be cleared to early
setImmediate(function() {
test.done();
});
setImmediate(test.done);
},

exitCodeOne: function(test) {
Expand Down Expand Up @@ -376,6 +370,117 @@ exports['Tessel (cli: root)'] = {

};

exports['Tessel (cli: run)'] = {
setUp: function(done) {
this.sandbox = sinon.sandbox.create();
this.warn = this.sandbox.stub(logs, 'warn');
this.info = this.sandbox.stub(logs, 'info');
this.deployScript = this.sandbox.stub(controller, 'deployScript').returns(Promise.resolve());
this.successfulCommand = this.sandbox.stub(cli, 'closeSuccessfulCommand');
done();
},

tearDown: function(done) {
this.sandbox.restore();
done();
},

defaultOptions: function(test) {
test.expect(5);

cli(['run', 'index.js']);

test.equal(this.deployScript.callCount, 1);

var args = this.deployScript.lastCall.args[0];

// These represent the minimum required properties
// and default values for `t2 run index.js`
test.ok(args.lanPrefer);
test.ok(args.slim);

test.ok(!args.full);
test.ok(!args.push);

setImmediate(test.done);
},

fullSetTrue_slimOverriddenLater: function(test) {
test.expect(5);

cli(['run', 'index.js', '--full=true']);

test.equal(this.deployScript.callCount, 1);

var args = this.deployScript.lastCall.args[0];

// opts.full will override opts.slim in `tarBundle`
// (See test/unit/deploy.js)
test.ok(args.full);
test.ok(args.lanPrefer);
test.ok(args.slim);

test.ok(!args.push);

setImmediate(test.done);
},
};

exports['Tessel (cli: push)'] = {
setUp: function(done) {
this.sandbox = sinon.sandbox.create();
this.warn = this.sandbox.stub(logs, 'warn');
this.info = this.sandbox.stub(logs, 'info');
this.deployScript = this.sandbox.stub(controller, 'deployScript').returns(Promise.resolve());
this.successfulCommand = this.sandbox.stub(cli, 'closeSuccessfulCommand');
done();
},

tearDown: function(done) {
this.sandbox.restore();
done();
},

defaultOptions: function(test) {
test.expect(5);

cli(['push', 'index.js']);

test.equal(this.deployScript.callCount, 1);

var args = this.deployScript.lastCall.args[0];

// These represent the minimum required properties
// and default values for `t2 push index.js`
test.ok(args.lanPrefer);
test.ok(args.slim);
test.ok(args.push);

test.ok(!args.full);

setImmediate(test.done);
},

fullSetTrue_slimOverriddenLater: function(test) {
test.expect(5);

cli(['push', 'index.js', '--full=true']);

test.equal(this.deployScript.callCount, 1);

var args = this.deployScript.lastCall.args[0];

// opts.full will override opts.slim in `tarBundle`
// (See test/unit/deploy.js)
test.ok(args.full);
test.ok(args.lanPrefer);
test.ok(args.push);
test.ok(args.slim);

setImmediate(test.done);
},
};

exports['closeFailedCommand'] = {
setUp: function(done) {
this.sandbox = sinon.sandbox.create();
Expand Down
22 changes: 11 additions & 11 deletions test/unit/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ exports['controller.update'] = {
this.tessel = TesselSimulator();

this.getTessel = this.sandbox.stub(Tessel, 'get', function(opts) {
this.tessel.setLANConnectionPreference(opts.lan_prefer);
this.tessel.setLANConnectionPreference(opts.lanPrefer);
return Promise.resolve(this.tessel);
}.bind(this));

Expand Down Expand Up @@ -124,7 +124,7 @@ exports['controller.update'] = {

var opts = {
version: '0.0.1',
lan_prefer: true
lanPrefer: true
};
controller.update(opts)
.then(function() {
Expand Down Expand Up @@ -158,7 +158,7 @@ exports['controller.update'] = {

var opts = {
version: '0.0.1',
lan_prefer: true
lanPrefer: true
};

controller.update(opts)
Expand Down Expand Up @@ -242,7 +242,7 @@ exports['controller.update'] = {
});

var opts = {
lan_prefer: true
lanPrefer: true
};
controller.update(opts)
.then(function() {
Expand Down Expand Up @@ -300,7 +300,7 @@ exports['controller.update'] = {
});

var opts = {
lan_prefer: true
lanPrefer: true
};
controller.update(opts)
.then(function() {
Expand Down Expand Up @@ -363,7 +363,7 @@ exports['controller.update'] = {
}.bind(this));

var opts = {
lan_prefer: true
lanPrefer: true
};
controller.update(opts)
.catch(function(err) {
Expand Down Expand Up @@ -416,7 +416,7 @@ exports['controller.update'] = {

var opts = {
force: true,
lan_prefer: true
lanPrefer: true
};

controller.update(opts)
Expand Down Expand Up @@ -473,7 +473,7 @@ exports['controller.update'] = {

var opts = {
version: 'latest',
lan_prefer: true
lanPrefer: true
};

controller.update(opts)
Expand Down Expand Up @@ -512,7 +512,7 @@ exports['controller.update'] = {

var opts = {
version: 'x.x.x',
lan_prefer: true
lanPrefer: true
};
controller.update(opts)
.catch(function(message) {
Expand Down Expand Up @@ -558,7 +558,7 @@ exports['controller.update'] = {
});

var opts = {
lan_prefer: true
lanPrefer: true
};
controller.update(opts)
.then(function() {
Expand Down Expand Up @@ -614,7 +614,7 @@ exports['controller.update'] = {
});

var opts = {
lan_prefer: true
lanPrefer: true
};
controller.update(opts)
.then(function() {
Expand Down

0 comments on commit ead744c

Please sign in to comment.