mqtt stuff added

This commit is contained in:
2018-05-16 10:44:10 +02:00
parent 74584cdbbe
commit c7eb46b346
499 changed files with 55775 additions and 19 deletions

25
node_modules/commist/.npmignore generated vendored Normal file
View File

@ -0,0 +1,25 @@
# Logs
logs
*.log
# Runtime data
pids
*.pid
*.seed
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release
# Dependency directory
# Deployed apps should consider commenting this line out:
# see https://npmjs.org/doc/faq.html#Should-I-check-my-node_modules-folder-into-git
node_modules

21
node_modules/commist/LICENSE generated vendored Normal file
View File

@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2014 Matteo Collina
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

56
node_modules/commist/README.md generated vendored Normal file
View File

@ -0,0 +1,56 @@
commist
=======
Build command line application with multiple commands the easy way.
To be used with [minimist](http://npm.im/minimist).
```js
var program = require('commist')()
, minimist = require('minimist')
, result
result = program
.register('abcd', function(args) {
console.log('just do', args)
})
.register('args', function(args) {
args = minimist(args)
console.log('just do', args)
})
.register('abcde code', function(args) {
console.log('doing something', args)
})
.register('another command', function(args) {
console.log('anothering', args)
})
.parse(process.argv.splice(2))
if (result) {
console.log('no command called, args', result)
}
```
When calling _commist_ programs, you can abbreviate down to three char
words. In the above example, these are valid commands:
```
node example.js abc
node example.js abc cod
node example.js anot comm
```
Moreover, little spelling mistakes are corrected too:
```
node example.js abcs cod
```
Acknowledgements
----------------
This project was kindly sponsored by [nearForm](http://nearform.com).
License
-------
MIT

24
node_modules/commist/example.js generated vendored Normal file
View File

@ -0,0 +1,24 @@
var program = require('./')()
, minimist = require('minimist')
, result
result = program
.register('abcd', function(args) {
console.log('just do', args)
})
.register('args', function(args) {
args = minimist(args)
console.log('just do', args)
})
.register('abcde code', function(args) {
console.log('doing something', args)
})
.register('another command', function(args) {
console.log('anothering', args)
})
.parse(process.argv.splice(2))
if (result) {
console.log('no command called, args', result)
}

123
node_modules/commist/index.js generated vendored Normal file
View File

@ -0,0 +1,123 @@
/*
The MIT License (MIT)
Copyright (c) 2014 Matteo Collina
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
'use strict';
var leven = require('leven')
function commist() {
var commands = []
function lookup(array) {
if (typeof array === 'string')
array = array.split(' ')
return commands.map(function(cmd) {
return cmd.match(array)
}).filter(function(match) {
return match.partsNotMatched === 0
}).sort(function(a, b) {
if (a.inputNotMatched > b.inputNotMatched)
return 1
if (a.inputNotMatched === b.inputNotMatched && a.totalDistance > b.totalDistance)
return 1
return -1
}).map(function(match) {
return match.cmd
})
}
function parse(args) {
var matching = lookup(args)
if (matching.length > 0) {
matching[0].call(args)
// return null if there is nothing left to do
return null
}
return args
}
function register(command, func) {
var matching = lookup(command)
matching.forEach(function(match) {
if (match.string === command)
throw new Error('command already registered: ' + command)
})
commands.push(new Command(command, func))
return this
}
return {
register: register
, parse: parse
, lookup: lookup
}
}
function Command(string, func) {
this.string = string
this.parts = string.split(' ')
this.length = this.parts.length
this.func = func
this.parts.forEach(function(part) {
if (part.length < 3)
throw new Error('command words must be at least 3 chars: ' + command)
})
}
Command.prototype.call = function call(argv) {
this.func(argv.slice(this.length))
}
Command.prototype.match = function match(string) {
return new CommandMatch(this, string)
}
function CommandMatch(cmd, array) {
this.cmd = cmd
this.distances = cmd.parts.map(function(elem, i) {
if (array[i] !== undefined)
return leven(elem, array[i])
else
return undefined
}).filter(function(distance, i) {
return distance !== undefined && distance < cmd.parts[i].length - 2
})
this.partsNotMatched = cmd.length - this.distances.length
this.inputNotMatched = array.length - this.distances.length
this.totalDistance = this.distances.reduce(function(acc, i) { return acc + i }, 0)
}
module.exports = commist

57
node_modules/commist/package.json generated vendored Normal file
View File

@ -0,0 +1,57 @@
{
"_from": "commist@^1.0.0",
"_id": "commist@1.0.0",
"_inBundle": false,
"_integrity": "sha1-wMNSUBz29S6RJOPvicmAbiAi6+8=",
"_location": "/commist",
"_phantomChildren": {},
"_requested": {
"type": "range",
"registry": true,
"raw": "commist@^1.0.0",
"name": "commist",
"escapedName": "commist",
"rawSpec": "^1.0.0",
"saveSpec": null,
"fetchSpec": "^1.0.0"
},
"_requiredBy": [
"/mqtt"
],
"_resolved": "https://registry.npmjs.org/commist/-/commist-1.0.0.tgz",
"_shasum": "c0c352501cf6f52e9124e3ef89c9806e2022ebef",
"_spec": "commist@^1.0.0",
"_where": "/home/wn/workspace-node/PiAlive/node_modules/mqtt",
"author": {
"name": "Matteo Collina",
"email": "hello@matteocollina.com"
},
"bugs": {
"url": "https://github.com/mcollina/commist/issues"
},
"bundleDependencies": false,
"dependencies": {
"leven": "^1.0.0",
"minimist": "^1.1.0"
},
"deprecated": false,
"description": "Build your commands on minimist!",
"devDependencies": {
"minimist": "^1.1.0",
"pre-commit": "0.0.9",
"tape": "^3.0.3"
},
"homepage": "https://github.com/mcollina/commist",
"license": "MIT",
"main": "index.js",
"name": "commist",
"pre-commit": "test",
"repository": {
"type": "git",
"url": "git+https://github.com/mcollina/commist.git"
},
"scripts": {
"test": "tap test.js"
},
"version": "1.0.0"
}

191
node_modules/commist/test.js generated vendored Normal file
View File

@ -0,0 +1,191 @@
var test = require('tape').test
, commist = require('./')
, minimist = require('minimist')
test('registering a command', function(t) {
t.plan(2)
var program = commist()
, result
program.register('hello', function(args) {
t.deepEqual(args, ['a', '-x', '23'])
})
result = program.parse(['hello', 'a', '-x', '23'])
t.notOk(result, 'must return null, the command have been handled')
})
test('registering two commands', function(t) {
t.plan(1)
var program = commist()
, result
program.register('hello', function(args) {
t.ok(false, 'must pick the right command')
})
program.register('world', function(args) {
t.deepEqual(args, ['a', '-x', '23'])
})
program.parse(['world', 'a', '-x', '23'])
})
test('registering two commands (bis)', function(t) {
t.plan(1)
var program = commist()
, result
program.register('hello', function(args) {
t.deepEqual(args, ['a', '-x', '23'])
})
program.register('world', function(args) {
t.ok(false, 'must pick the right command')
})
program.parse(['hello', 'a', '-x', '23'])
})
test('registering two words commands', function(t) {
t.plan(1)
var program = commist()
, result
program.register('hello', function(args) {
t.ok(false, 'must pick the right command')
})
program.register('hello world', function(args) {
t.deepEqual(args, ['a', '-x', '23'])
})
program.parse(['hello', 'world', 'a', '-x', '23'])
})
test('registering two words commands (bis)', function(t) {
t.plan(1)
var program = commist()
, result
program.register('hello', function(args) {
t.deepEqual(args, ['a', '-x', '23'])
})
program.register('hello world', function(args) {
t.ok(false, 'must pick the right command')
})
program.parse(['hello', 'a', '-x', '23'])
})
test('registering ambiguous commands throws exception', function(t) {
var program = commist()
, result
function noop() {}
program.register('hello', noop)
program.register('hello world', noop)
program.register('hello world matteo', noop)
try {
program.register('hello world', noop)
t.ok(false, 'must throw if double-registering the same command')
} catch(err) {
}
t.end()
})
test('looking up commands', function(t) {
var program = commist()
, result
function noop1() {}
function noop2() {}
function noop3() {}
program.register('hello', noop1)
program.register('hello world matteo', noop3)
program.register('hello world', noop2)
t.equal(program.lookup('hello')[0].func, noop1)
t.equal(program.lookup('hello world matteo')[0].func, noop3)
t.equal(program.lookup('hello world')[0].func, noop2)
t.end()
})
test('looking up commands with abbreviations', function(t) {
var program = commist()
, result
function noop1() {}
function noop2() {}
function noop3() {}
program.register('hello', noop1)
program.register('hello world matteo', noop3)
program.register('hello world', noop2)
t.equal(program.lookup('hel')[0].func, noop1)
t.equal(program.lookup('hel wor mat')[0].func, noop3)
t.equal(program.lookup('hel wor')[0].func, noop2)
t.end()
})
test('executing commands from abbreviations', function(t) {
t.plan(1)
var program = commist()
, result
program.register('hello', function(args) {
t.deepEqual(args, ['a', '-x', '23'])
})
program.register('hello world', function(args) {
t.ok(false, 'must pick the right command')
})
program.parse(['hel', 'a', '-x', '23'])
})
test('a command must be at least 3 chars', function(t) {
var program = commist()
, result
function noop1() {}
try {
program.register('h', noop1)
t.ok(false, 'not thrown')
} catch(err) {
}
t.end()
})
test('a command part must be at least 3 chars', function(t) {
var program = commist()
, result
function noop1() {}
try {
program.register('h b', noop1)
t.ok(false, 'not thrown')
} catch(err) {
}
t.end()
})