Add support for running routines via command line
This commit is contained in:
@@ -22,10 +22,14 @@ class Routine extends Injectable {
|
||||
this._type = type
|
||||
}
|
||||
|
||||
async execute() {
|
||||
async execute(with_logging = false) {
|
||||
const result = await this._build_result()
|
||||
|
||||
let step_no = 1
|
||||
for ( const step of result.steps ) {
|
||||
this.output.info(`(${step_no}/${result.steps.length}) ${step.step.display()}`, with_logging ? 0 : 10)
|
||||
step_no += 1
|
||||
|
||||
if ( this._type === 'checks' ) {
|
||||
step.status = (await step.step.check()) ? 'success' : 'fail'
|
||||
step.message = step.status === 'success' ? 'Check passed.' : step.step.check_message()
|
||||
@@ -41,6 +45,12 @@ class Routine extends Injectable {
|
||||
} else {
|
||||
throw new InvalidRoutineTypeError(this._type)
|
||||
}
|
||||
|
||||
if ( step.status === 'success' ) {
|
||||
this.output.success(` ${step.message}`, with_logging ? 0 : 10)
|
||||
} else {
|
||||
this.output.error(` ${step.message}`, with_logging ? 0 : 10)
|
||||
}
|
||||
}
|
||||
|
||||
result.overall_state = result.steps.every(x => x.status === 'success') ? 'success' : 'fail'
|
||||
@@ -50,7 +60,8 @@ class Routine extends Injectable {
|
||||
async _build_result() {
|
||||
const steps = []
|
||||
for ( const step_config of this._config.steps ) {
|
||||
const step = this.states.from_config(this._hosts[step_config.host], step_config)
|
||||
const host = this._hosts[step_config.host]
|
||||
const step = this.states.from_config(host, step_config)
|
||||
const result = new StepResult(this, step)
|
||||
steps.push(result)
|
||||
}
|
||||
|
||||
48
app/classes/routine/RunDirective.js
Normal file
48
app/classes/routine/RunDirective.js
Normal file
@@ -0,0 +1,48 @@
|
||||
const Directive = require('flitter-cli/Directive')
|
||||
const path = require('path')
|
||||
|
||||
class RunDirective extends Directive {
|
||||
static options() {
|
||||
return [
|
||||
'--hosts -h {host file} | path to the host definition file',
|
||||
'{routine file} | path to the routine definition file',
|
||||
]
|
||||
}
|
||||
|
||||
static name() {
|
||||
return 'run'
|
||||
}
|
||||
|
||||
static help() {
|
||||
return 'Run a specified routine'
|
||||
}
|
||||
|
||||
async handle(app, argv) {
|
||||
const routine_path = this.option('routine file')
|
||||
const host_path = this.option('hosts')
|
||||
|
||||
if ( !host_path )
|
||||
return this.error('Missing required parameter: --hosts')
|
||||
|
||||
let routine_conf
|
||||
let host_conf
|
||||
|
||||
try {
|
||||
routine_conf = require(path.resolve(routine_path))
|
||||
} catch (e) {
|
||||
this.error('Routine file is invalid.')
|
||||
return this.output.debug(e)
|
||||
}
|
||||
|
||||
try {
|
||||
host_conf = require(path.resolve(host_path))
|
||||
} catch (e) {
|
||||
this.error('Host definition file is invalid.')
|
||||
return this.output.debug(e)
|
||||
}
|
||||
|
||||
console.log({ routine_conf, host_conf })
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = exports = RunDirective
|
||||
Reference in New Issue
Block a user