Skip to content

Commit

Permalink
Merge branch 'master' of github.com:tessel/t2-cli into jon-wifi-off
Browse files Browse the repository at this point in the history
# By Rick Waldron (9) and others
# Via Rick Waldron (7) and others
* 'master' of github.com:tessel/t2-cli: (21 commits)
  Add appveyor badge to readme
  Instead of rethrowing errors, log them. Fixes gh-449
  Fix jscs error: dont use future reserved words as identifiers
  Updating grunt-jscs
  fix(access-point): removes template literals cause jsbeautify
  Tweak status messages
  replaces new Errors with strings
  fix(access-point): creates boilerplate for new access point when required
  Adds check step to AP setup. Needs AP _new_ iface.
  fix(ap/wifi): working implementation
  refactor(access-point): simpler, cleaner tests and source code
  tests(access-point): initial implementation
  feat(access-point): adds ability to enable/disable AP
  fix: working access point configuration
  fix(ap): now able to configure ap setup
  feat(ap): initial access point creation implementation
  When single flag is present, do not traverse upward for package.json. Fixes gh-442
  Ensure that bundling errors make are surfaced. Fixes gh-441
  Adding linux driver install
  only set key if requested
  ...

Conflicts:
	lib/controller.js
  • Loading branch information
rwaldron committed Nov 17, 2015
2 parents 4fcc670 + f5ef11d commit 379de29
Show file tree
Hide file tree
Showing 27 changed files with 1,143 additions and 277 deletions.
2 changes: 2 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ module.exports = function(grunt) {
'lib/**/*.js',
'test/**/*.js',
'Gruntfile.js',
'!test/unit/fixtures/syntax-error/**/*.js',

// This is commented out because there are
// too many errors to address. I went through
Expand All @@ -36,6 +37,7 @@ module.exports = function(grunt) {
'lib/**/*.js',
'test/**/*.js',
'Gruntfile.js',
'!test/unit/fixtures/syntax-error/**/*.js',
// 'resources/**/*.js',
],
options: {
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ Join the [conversation on Slack](https://tessel-slack.herokuapp.com/), our proje

[![Slack](http://tessel-slack.herokuapp.com/badge.svg)](https://tessel-slack.herokuapp.com/)

[![Build Status](https://travis-ci.org/tessel/t2-cli.svg?branch=master)](https://travis-ci.org/tessel/t2-cli)
[![Travis-CI Build Status](https://travis-ci.org/tessel/t2-cli.svg?branch=master)](https://travis-ci.org/tessel/t2-cli)
[![Appveyor Build status](https://ci.appveyor.com/api/projects/status/9a6l5gwswuhqgk99?svg=true)](https://ci.appveyor.com/project/rwaldron/t2-cli)

See docs on T2 CLI usage [on the t2-docs repo](https://github.com/tessel/t2-docs/blob/master/cli.md).

Expand Down
68 changes: 56 additions & 12 deletions bin/tessel-2.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ var key = require('../lib/key');
var init = require('../lib/init');
var logs = require('../lib/logs');
var Tessel = require('../lib/tessel/tessel');
var drivers = require('./tessel-install-drivers');

function makeCommand(commandName) {
return parser.command(commandName)
Expand Down Expand Up @@ -48,6 +49,17 @@ function callControllerCallback(methodName) {
};
}

parser.command('install-drivers')
.callback(function() {
require('./tessel-install-drivers');
var ret = drivers.install();
if (ret !== 0) {
module.exports.closeFailedCommand(ret);
} else {
module.exports.closeSuccessfulCommand(ret);
}
});

parser.command('provision')
.callback(callControllerCallback('provisionTessel'))
.option('force', {
Expand Down Expand Up @@ -278,6 +290,36 @@ makeCommand('version')
.callback(callControllerCallback('tesselFirmwareVerion'))
.help('Display Tessel\'s current firmware version');

makeCommand('ap')
.option('ssid', {
abbr: 'n',
help: 'Name of the network.'
})
.option('pass', {
abbr: 'p',
help: 'Password to access network.'
})
.option('security', {
abbr: 's',
help: 'Encryption to use on network (i.e. wep, psk, psk2, wpa, wpa2).'
})
.option('trigger', {
position: 1,
help: 'Trigger, i.e. on OR off, the access point'
})
.help('Configure the Tessel as an access point')
.callback(function(opts) {
if (opts.trigger) {
if (opts.trigger === 'on') {
callControllerWith('enableAccessPoint', opts);
} else {
callControllerWith('disableAccessPoint', opts);
}
} else {
callControllerWith('createAccessPoint', opts);
}
});


module.exports = function(args) {
parser.parse(args);
Expand All @@ -288,20 +330,22 @@ module.exports.closeSuccessfulCommand = function() {
};

// Allow options to be partially applied
module.exports.closeFailedCommand = function(opts, err) {
if (!err) {
err = opts;
opts = {};
}
if (err instanceof Error) {
throw err;
module.exports.closeFailedCommand = function(status, options) {
var code = 1;

options = options || {};

if (status instanceof Error) {
logs.err(status.toString());
} else {
// Print a stern warning by default
opts.type = opts.type || 'warn';
logs[opts.type](err);
if (status !== undefined) {
// Print a stern warning by default
options.type = options.type || 'warn';
logs[options.type](status);
}
}
// NOTE: Exit code is non-zero
process.exit(1);

process.exit(options.code || status.code || code);
};


Expand Down
41 changes: 41 additions & 0 deletions bin/tessel-install-drivers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/env node

var fs = require('fs');
var logs = require('../lib/logs');
var child_process = require('child_process');

module.exports.install = function() {
if (process.platform === 'linux') {
var rules_name = '85-tessel.rules';
var dest = '/etc/udev/rules.d/' + rules_name;
var rules = fs.readFileSync(__dirname + '/../resources/' + rules_name);

try {
fs.writeFileSync(dest, rules);
} catch (e) {
if (e.code === 'EACCES') {
logs.info('Could not write to ' + dest);
logs.info('Run `sudo t2 install-drivers`');
return -1;
} else {
throw e;
}
}
logs.info('udev rules installed to ' + dest);


var udevadm = child_process.spawn('udevadm', ['control', '--reload-rules']);
udevadm.on('close', function(code) {
if (code !== 0) {
logs.error('Error reloading udev');
return code;
} else {
logs.info('Done. Unplug and re-plug Tessel to update permissions.');
return code;
}
});
} else {
logs.info('No driver installation necessary.');
}

};
Loading

0 comments on commit 379de29

Please sign in to comment.