mirror of
https://github.com/balena-io/etcher.git
synced 2025-04-24 07:17:18 +00:00
Implement Etcher CLI "robot" option (#360)
This option makes the Etcher CLI outputs state information in a way that can be easily parsed by a parent process spawning it. The format of the state output is: <type> <percentage>% <eta>s <speed> This can be easily parsed as follows: const output = line.split(' '); const state = { type: output[0], percentage: parseInt(output[1], 10), eta: parseInt(output[2], 10), speed: parseInt(output[3], 10) }; Signed-off-by: Juan Cruz Viotti <jviottidc@gmail.com>
This commit is contained in:
parent
f55100d09b
commit
86cbff940c
@ -63,6 +63,14 @@ module.exports = yargs
|
||||
return true;
|
||||
})
|
||||
|
||||
.check(function(argv) {
|
||||
if (argv.robot && !argv.drive) {
|
||||
throw new Error('Missing drive');
|
||||
}
|
||||
|
||||
return true;
|
||||
})
|
||||
|
||||
.options({
|
||||
help: {
|
||||
describe: 'show help',
|
||||
@ -79,6 +87,11 @@ module.exports = yargs
|
||||
string: true,
|
||||
alias: 'd'
|
||||
},
|
||||
robot: {
|
||||
describe: 'parse-able output without interactivity',
|
||||
boolean: true,
|
||||
alias: 'r'
|
||||
},
|
||||
yes: {
|
||||
describe: 'confirm non-interactively',
|
||||
boolean: true,
|
||||
|
@ -41,7 +41,7 @@ form.run([
|
||||
// If `options.yes` is `false`, pass `undefined`,
|
||||
// otherwise the question will not be asked because
|
||||
// `false` is a defined value.
|
||||
yes: options.yes || undefined
|
||||
yes: options.robot || options.yes || undefined
|
||||
|
||||
}
|
||||
}).then(function(answers) {
|
||||
@ -49,7 +49,7 @@ form.run([
|
||||
throw new Error('Aborted');
|
||||
}
|
||||
|
||||
var progressBar = new visuals.Progress('Burning');
|
||||
const progressBar = new visuals.Progress('Burning');
|
||||
|
||||
return writer.writeImage(options._[0], {
|
||||
device: answers.drive
|
||||
@ -57,11 +57,34 @@ form.run([
|
||||
unmountOnSuccess: false,
|
||||
validateWriteOnSuccess: false
|
||||
}, function(state) {
|
||||
return progressBar.update(state);
|
||||
|
||||
if (options.robot) {
|
||||
console.log([
|
||||
state.type,
|
||||
Math.floor(state.percentage) + '%',
|
||||
state.eta + 's',
|
||||
Math.floor(state.speed)
|
||||
].join(' '));
|
||||
} else {
|
||||
progressBar.update(state);
|
||||
}
|
||||
|
||||
});
|
||||
}).then(function() {
|
||||
console.log('Your flash is complete!');
|
||||
|
||||
if (options.robot) {
|
||||
console.log('done');
|
||||
} else {
|
||||
console.log('Your flash is complete!');
|
||||
}
|
||||
|
||||
}).catch(function(error) {
|
||||
utils.printError(error);
|
||||
|
||||
if (options.robot) {
|
||||
console.error(error.message);
|
||||
} else {
|
||||
utils.printError(error);
|
||||
}
|
||||
|
||||
process.exit(1);
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user