ADD unit tests, split and refactor source code

This commit is contained in:
RecuencoJones
2019-03-25 20:38:29 +01:00
parent 6eaf5fc9af
commit 8257010937
18 changed files with 782 additions and 392 deletions

28
src/cli.js Normal file
View File

@@ -0,0 +1,28 @@
const actions = {
install: (callback) => require('./actions/install')(callback),
uninstall: (callback) => require('./actions/uninstall')(callback)
};
// Parse command line arguments and call the right action
module.exports = ({ argv, exit }) => {
if (argv && argv.length > 2) {
const cmd = argv[2];
if (!actions[cmd]) {
console.log('Invalid command to go-npm. `install` and `uninstall` are the only supported commands');
exit(1);
} else {
actions[cmd]((err) => {
if (err) {
console.error(err);
exit(1);
} else {
exit(0);
}
});
}
} else {
console.log('Invalid command to go-npm. `install` and `uninstall` are the only supported commands');
exit(1);
}
};