particle-cli
Version:
Simple Node commandline application for working with your Particle devices and using the Particle Cloud
43 lines (36 loc) • 1.37 kB
JavaScript
;
const CLICommandBase = require('./base');
const path = require('path');
const os = require('os');
const {
getEDLDevice,
getTachyonInfo, handleFlashError
} = require('../lib/tachyon-utils');
module.exports = class IdentifyTachyonCommand extends CLICommandBase {
constructor({ ui } = {}) {
super();
this.ui = ui || this.ui;
}
async identify() {
const device = await getEDLDevice({ ui: this.ui });
const outputLog = path.join(os.tmpdir(), `tachyon_${device.id}_identify_${Date.now()}.log`);
try {
const tachyonInfo = await getTachyonInfo({ outputLog, ui: this.ui, device });
this.printIdentification(tachyonInfo);
} catch (error) {
const { retry } = await handleFlashError({ error, ui: this.ui });
if (retry) {
return this.identify();
}
this.ui.stdout.write(`An error ocurred while trying to identify your tachyon ${os.EOL}`);
this.ui.stdout.write(`Error: ${error.message} ${os.EOL}`);
this.ui.stdout.write(`Verify your logs ${outputLog} for more information ${os.EOL}`);
}
}
printIdentification({ deviceId, region, manufacturingData, osVersion }) {
this.ui.stdout.write(`Device ID: ${deviceId}${os.EOL}`);
this.ui.stdout.write(`Region: ${region}${os.EOL}`);
this.ui.stdout.write(`Manufacturing data: ${manufacturingData}${os.EOL}`);
this.ui.stdout.write(`OS Version: ${osVersion}${os.EOL}`);
}
};