mirror of
https://github.com/ershisan99/go-npm.git
synced 2025-12-17 12:33:27 +00:00
ADD unit tests, split and refactor source code
This commit is contained in:
28
src/cli.js
Normal file
28
src/cli.js
Normal 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);
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user