maestro/app/classes/state/os/UpdateState.js
2020-04-15 09:11:10 -05:00

38 lines
1.0 KiB
JavaScript

const State = require('../State')
class UpdateState extends State {
static get services() {
return [...super.services, 'output']
}
constructor(host, config) {
if ( !host.packages ) {
throw new Error(`Cannot apply update state to host ${host.name}: missing package manager API.`)
}
super(host, config)
}
async apply() {
const packages = (await this._host.packages.list_updates()).map(x => x.name)
await this._host.packages.update(...packages)
}
async check() {
return (await this._host.packages.list_updates()).length === 0
}
async reverse() {
this.output.warn(`Update state does not currently support reversing package updates. (Host: ${this._host.name})`)
}
failure_message() {
return `Unable to update packages on host "${this._host.name}."`
}
check_message() {
return `There are package updates pending on the host "${this._host.name}."`
}
}
module.exports = exports = UpdateState