node-serialport-bindings-cpp/bin/list.js
Francis Gulotta 2ed7b119d0 Test flushing data
- [unix] small changes to flushing data during port open and setup to prevent bad data
- [all] mock binding flush now works
- cleanup on mock-binding pending reads
- add `serialport-repl` as a bin and npm command
2017-07-09 21:25:02 -04:00

42 lines
1,019 B
JavaScript
Executable file

#!/usr/bin/env node
'use strict';
const serialport = require('../');
const version = require('../package.json').version;
const args = require('commander');
args
.version(version)
.description('List available serial ports')
.option('-f, --format <type>', 'Format the output as text, json, or jsonline. default: text', /^(text|json|jsonline)$/i, 'text')
.parse(process.argv);
const formatters = {
text(err, ports) {
if (err) {
console.error(err);
process.exit(1);
}
ports.forEach((port) => {
console.log(`${port.comName}\t${port.pnpId || ''}\t${port.manufacturer || ''}`);
});
},
json(err, ports) {
if (err) {
console.error(JSON.stringify(err));
process.exit(1);
}
console.log(JSON.stringify(ports));
},
jsonline(err, ports) {
if (err) {
console.error(JSON.stringify(err));
process.exit(1);
}
ports.forEach((port) => {
console.log(JSON.stringify(port));
});
}
};
serialport.list(formatters[args.format]);