Skip to content

Commit

Permalink
fix merge conflicts and delint
Browse files Browse the repository at this point in the history
  • Loading branch information
Frijol committed Nov 24, 2015
2 parents b130921 + caa2afa commit ddd2094
Show file tree
Hide file tree
Showing 49 changed files with 2,225 additions and 628 deletions.
38 changes: 19 additions & 19 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,33 @@ module.exports = function(grunt) {
]
},
jshint: {
options: {
jshintrc: '.jshintrc'
all: {
options: {
jshintrc: '.jshintrc'
},
src: [
'bin/*',
'lib/**/*.js',
'Gruntfile.js',
]
},
all: [
'bin/*',
'lib/**/*.js',
'test/**/*.js',
'Gruntfile.js',

// This is commented out because there are
// too many errors to address. I went through
// half of them and still:
//
// >> 75 errors in 3 files
//
// There are a lot of undefined vars being used
// and without fully understanding these files, it's
// not worth the effort to fix them all.
// 'resources/**/*.js',
]
tests: {
options: {
jshintrc: 'test/.jshintrc'
},
src: [
'test/**/*.js',
'!test/unit/fixtures/syntax-error/**/*.js',
]
}
},
jscs: {
all: [
'bin/*',
'lib/**/*.js',
'test/**/*.js',
'Gruntfile.js',
'!test/unit/fixtures/syntax-error/**/*.js',
// 'resources/**/*.js',
],
options: {
Expand Down
17 changes: 4 additions & 13 deletions 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 Expand Up @@ -37,19 +38,9 @@ You may encounter the following error when executing `npm link` on windows:
This error occurs because of windows folder permissions. To resolve this make sure you are running cmd or powershell as an administrator and that the permissions on the node_modules folder is set to full control for the user.

### Updating
If this is your first time updating, you may have to run `t2 update -f`, otherwise just run `t2 update` to make sure you are running the most recent build of OpenWRT and firmware.
Just run `t2 update` to make sure you are running the most recent build of OpenWRT and firmware.

## Development Milestones
Help us build Tessel 2's CLI! The [issues section](https://github.com/tessel/t2-cli/issues) of this repo is full of small, fully outlined projects to add functionality.

The table below outlines the major milestones for the CLI prior to general release. **Feel free to contribute towards milestones that that aren't the highest priority! All contributions are welcome.**

[Milestones tracked here.](https://github.com/tessel/t2-cli/milestones)

| Milestone Name | Subtasks | Notes |
|---------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| 1. [Continuous Tesselation](https://github.com/tessel/t2-cli/milestones/Continuous%20Tesselation) | <ul><li>[Complete Unit Tests](https://github.com/tessel/t2-cli/issues/72)</li><li>[Hardware Integration Tests](https://github.com/tessel/t2-cli/issues/155)</li><li>[General Cleanup](https://github.com/tessel/t2-cli/issues/104)</li></ul> | We should focus on building the test infrastructure that will enable us to ensure a reliable CLI distribution. By the time these tasks are done, the code should be clean, well reviewed, and automatically tested with each PR. **Completion Goal: July 12, 2015** |
| 2. [Easy Updation](https://github.com/tessel/t2-cli/milestones/Easy%20Updation) | <ul><li>[ OpenWRT Updating](https://github.com/tessel/t2-cli/issues/81)</li><li>[Coprocessor Updating](https://github.com/tessel/t2-cli/issues/109)</li></ul> | By completing these tasks, it should be possible to have a one line call to update the OpenWRT and coprocessor firmware image on Tessel 2. **Completion Goal: July 26** |
| 3. [Complete Speculation](https://github.com/tessel/t2-cli/milestones/Complete%20Speculation) | <ul><li>Finish all issues listed under the ['spec-cli'](https://github.com/tessel/t2-cli/labels/spec-cli) label.</li></ul> | After the completion of these designed command line interactions should be finished and working according to the full specification. **Completion Goal: August 9** |
| 4. [Bonus Pointation](https://github.com/tessel/t2-cli/milestones/Bonus%20Pointation) | <ul><li>[Automatically pull in binary dependencies](https://github.com/tessel/t2-cli/issues/96)</li><li>[Rust code bundling and running (will need to also port module code)](https://github.com/tessel/t2-cli/issues/200)</li><li>[Python code bundling (will need to also port module code)](https://github.com/tessel/t2-cli/issues/201)</li></ul> | The goal of this milestone is to build on the core functionality with functional binary dependencies and Python/Rust support. **Completion Goal: August 16** |
| 5. [Finally Publication](https://github.com/tessel/t2-cli/milestones/Finally%20Publication) | <ul><li>[ Merge with the original Tessel CLI](https://github.com/tessel/t2-cli/issues/15)</li><li> Release on NPM!</li></ul> | After this milestone is complete, the CLI will be ready for all the T2 users to enjoy! **Completion Goal: August 23** |
The table [here](https://github.com/tessel/project/issues/106) outlines the major milestones for the CLI prior to general release. **Feel free to contribute towards milestones that that aren't the highest priority or bugs not on that list! All contributions are welcome.** |
135 changes: 100 additions & 35 deletions bin/tessel-2.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
#!/usr/bin/env node

// System Objects
var path = require('path');

// Third Party Dependencies
var parser = require('nomnom').script('t2');

// Internal
var controller = require('../lib/controller');
var key = require('../lib/key');
var init = require('../lib/init');
var key = require('../lib/key');
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 All @@ -20,7 +26,7 @@ function makeCommand(commandName) {
required: false,
metavar: 'PRIVATEKEY',
abbr: 'i',
default: Tessel.TESSEL_AUTH_KEY,
default: Tessel.LOCAL_AUTH_KEY,
help: 'SSH key for authorization with your Tessel'
})
.option('name', {
Expand All @@ -29,11 +35,16 @@ function makeCommand(commandName) {
})
.option('lan', {
flag: true,
help: 'Use LAN connection'
help: 'Use only a LAN connection'
})
.option('usb', {
flag: true,
help: 'Use USB connection'
help: 'Use only a USB connection'
})
.option('lan_prefer', {
flag: true,
default: false,
help: 'Prefer a LAN connection if it\'s available, otherwise use USB'
});
}

Expand All @@ -48,6 +59,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 @@ -77,7 +99,7 @@ makeCommand('restart')
})
.option('entryPoint', {
position: 1,
help: 'The program entry point file to deploy to Tessel.',
help: 'The entry point file to deploy to Tessel'
})
.option('type', {
default: 'ram',
Expand All @@ -93,7 +115,7 @@ makeCommand('run')
.option('entryPoint', {
position: 1,
required: true,
help: 'The program entry point file to deploy to Tessel.'
help: 'The entry point file to deploy to Tessel'
})
.option('single', {
flag: true,
Expand All @@ -107,17 +129,16 @@ makeCommand('run')
})
.option('slim', {
flag: true,
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. Program is run from "slimPath" file.'
help: 'Bundle only the required modules'
})
.option('slimPath', {
default: '__tessel_program__.js',
help: 'Specify the name of the --slim bundle file.'
default: 'build.js'
})
.option('full', {
// Overrides default lan_prefer because deploys require high bandwidth
.option('lan_prefer', {
flag: true,
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. Program is run from specified "entryPoint" file.'
default: true,
help: 'Prefer a LAN connection if it\'s available, otherwise use USB'
})
.help('Deploy a script to Tessel and run it with Node');

Expand All @@ -129,7 +150,7 @@ makeCommand('push')
.option('entryPoint', {
position: 1,
required: true,
help: 'The program entry point file to deploy to Tessel.'
help: 'The entry point file to deploy to Tessel'
})
.option('single', {
flag: true,
Expand All @@ -143,17 +164,10 @@ makeCommand('push')
})
.option('slim', {
flag: true,
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. Program is run from "slimPath" file.'
help: 'Bundle only the required modules'
})
.option('slimPath', {
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. Program is run from specified "entryPoint" file.'
default: 'build.js'
})
.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 Expand Up @@ -184,6 +198,11 @@ makeCommand('wifi')
// TODO: Refactor switch case into controller.wifi
if (opts.list) {
callControllerWith('printAvailableNetworks', opts);
} else if (opts.off || opts.on) {
if (opts.off) {
opts.on = false;
}
callControllerWith('setWiFiState', opts);
} else if (opts.ssid && opts.password) {
callControllerWith('connectToNetwork', opts);
} else {
Expand All @@ -205,6 +224,14 @@ makeCommand('wifi')
metavar: 'PASSWORD',
help: 'Set the password of the network to connect to'
})
.option('off', {
flag: true,
help: 'Disable the wireless network'
})
.option('on', {
flag: true,
help: 'Enable the wireless network'
})
.help('Configure the wireless connection');

parser.command('key')
Expand Down Expand Up @@ -265,6 +292,42 @@ 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);
}
});

makeCommand('root')
.callback(function(opts) {
callControllerWith('root', opts);
})
.help('Gain SSH root access to one of your authorized tessels');


module.exports = function(args) {
parser.parse(args);
Expand All @@ -275,20 +338,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
47 changes: 47 additions & 0 deletions bin/tessel-install-drivers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/env node

// System Objects
var child_process = require('child_process');
var fs = require('fs');

// Third Party Dependencies
// ...

// Internal
var logs = require('../lib/logs');

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.');
}

};

0 comments on commit ddd2094

Please sign in to comment.