diff --git a/lib/cli/etcher.js b/lib/cli/etcher.js index 1e5e9327..d4f5c26d 100644 --- a/lib/cli/etcher.js +++ b/lib/cli/etcher.js @@ -64,13 +64,15 @@ form.run([ }, function(state) { if (options.robot) { - log.toStdout([ - 'progress', - state.type, - Math.floor(state.percentage) + '%', - state.eta + 's', - Math.floor(state.speed) - ].join(' ')); + log.toStdout(JSON.stringify({ + command: 'progress', + data: { + type: state.type, + percentage: Math.floor(state.percentage), + eta: state.eta, + speed: Math.floor(state.speed) + } + })); } else { progressBars[state.type].update(state); } @@ -79,7 +81,13 @@ form.run([ }).then(function(results) { if (options.robot) { - log.toStdout(`done ${results.passedValidation} ${results.sourceChecksum}`); + log.toStdout(JSON.stringify({ + command: 'done', + data: { + passedValidation: results.passedValidation, + sourceChecksum: results.sourceChecksum + } + })); } else { if (results.passedValidation) { console.log('Your flash is complete!'); @@ -98,7 +106,12 @@ form.run([ }).catch(function(error) { if (options.robot) { - log.toStderr(error.message); + log.toStderr(JSON.stringify({ + command: 'error', + data: { + message: error.message + } + })); } else { utils.printError(error); } diff --git a/lib/src/child-writer/utils.js b/lib/src/child-writer/utils.js index d5c5cdaf..d993447c 100644 --- a/lib/src/child-writer/utils.js +++ b/lib/src/child-writer/utils.js @@ -137,45 +137,3 @@ exports.getTemporaryLogFilePath = function() { return logFilePath; }); }; - -/** - * @summary Parse an output line from the Etcher CLI - * @function - * @public - * - * @description - * This function parses an output line for when the CLI - * was called with the `--robot` argument. - * - * @param {String} line - line - * @returns {(Object|Undefined)} parsed output - * - * @example - * const data = utils.parseEtcherCLIRobotLine('progress write 50% 0.5s 400'); - */ -exports.parseEtcherCLIRobotLine = function(line) { - const data = line.split(' '); - const command = _.first(data); - - if (command === 'progress') { - return { - command: command, - data: { - type: _.nth(data, 1), - percentage: _.parseInt(_.nth(data, 2)), - eta: _.parseInt(_.nth(data, 3)), - speed: _.parseInt(_.nth(data, 4)) - } - }; - } - - if (command === 'done') { - return { - command: command, - data: { - passedValidation: _.nth(data, 1) === 'true', - sourceChecksum: _.nth(data, 2) - } - }; - } -}; diff --git a/lib/src/child-writer/writer-proxy.js b/lib/src/child-writer/writer-proxy.js index 8f9b1b84..191bd683 100644 --- a/lib/src/child-writer/writer-proxy.js +++ b/lib/src/child-writer/writer-proxy.js @@ -72,11 +72,7 @@ return isElevated().then(function(elevated) { }); tail.on('line', function(line) { - const data = utils.parseEtcherCLIRobotLine(line); - - if (data) { - process.send(data); - } + process.send(JSON.parse(line)); }); }