Uninstallation (#211)
This commit is contained in:
parent
a2de8dea0c
commit
81cdc766b6
|
@ -131,6 +131,28 @@ class Package {
|
|||
};
|
||||
}
|
||||
|
||||
|
||||
async uninstall(){
|
||||
logger.info(`Uninstalling ${this.language}-${this.version.raw}`);
|
||||
|
||||
logger.debug("Finding runtime")
|
||||
const runtime = runtime.get_latest_runtime_matching_language_version(this.language, this.version.raw);
|
||||
|
||||
logger.debug("Unregistering runtime")
|
||||
runtime.unregister();
|
||||
|
||||
logger.debug("Cleaning files from disk")
|
||||
await fs.rmdir(this.install_path, {recursive: true})
|
||||
|
||||
logger.info(`Uninstalled ${this.language}-${this.version.raw}`)
|
||||
|
||||
return {
|
||||
language: this.language,
|
||||
version: this.version.raw
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
|
|
|
@ -91,11 +91,33 @@ module.exports = {
|
|||
|
||||
// DELETE /packages/:language/:version
|
||||
async package_uninstall(req, res) {
|
||||
logger.debug('Request to install package');
|
||||
|
||||
const pkg = await get_package(req.params.language, req.params.version);
|
||||
|
||||
if (pkg == null) {
|
||||
return res
|
||||
.status(500)
|
||||
.status(404)
|
||||
.send({
|
||||
message: 'Not implemented'
|
||||
message: `Requested package ${req.params.language}-${req.params.version} does not exist`
|
||||
});
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await pkg.uninstall();
|
||||
|
||||
return res
|
||||
.status(200)
|
||||
.send(response);
|
||||
} catch(e) {
|
||||
logger.error(`Error while uninstalling package ${pkg.language}-${pkg.version}:`, e.message);
|
||||
|
||||
return res
|
||||
.status(500)
|
||||
.send({
|
||||
message: e.message
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
|
|
@ -63,6 +63,11 @@ class Runtime {
|
|||
toString() {
|
||||
return `${this.language}-${this.version.raw}`;
|
||||
}
|
||||
|
||||
unregister() {
|
||||
const index = runtimes.indexOf(this);
|
||||
runtimes.splice(index, 1); //Remove from runtimes list
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = runtimes;
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
const chalk = require('chalk');
|
||||
|
||||
exports.command = ['uninstall <language> <language-version>']
|
||||
exports.aliases = ['u']
|
||||
exports.describe = 'Installs the named package'
|
||||
|
||||
|
||||
const msg_format = {
|
||||
'color': p => `${p.language ? chalk.green.bold('✓') : chalk.red.bold('❌')} Uninstallation ${p.language ? "succeeded" : "failed: " + p.message}`,
|
||||
'monochrome': p => `Uninstallation ${p.language ? "succeeded" : "failed: " + p.message}`,
|
||||
'json': JSON.stringify
|
||||
|
||||
}
|
||||
|
||||
exports.handler = async function({axios, language, languageVersion}){
|
||||
try{
|
||||
const install = await axios.delete(`/packages/${language}/${languageVersion}`)
|
||||
|
||||
console.log(msg_format.color(install.data));
|
||||
}catch({response}){
|
||||
console.error(response.data.message)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue