Skip to content

Commit

Permalink
Fixed some problems with commander and improved error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigogs committed Dec 19, 2017
1 parent aaa2432 commit 02260bb
Show file tree
Hide file tree
Showing 4 changed files with 764 additions and 122 deletions.
2 changes: 1 addition & 1 deletion bin/easyvpn
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ program
.option('-c, --country <name>', 'Country name')
.option('-q, --query', 'Enable country query')
.option('-p, --proxy <url>', 'Proxy url')
.option('-o, --options <options>', 'Openvpn options', list)
.option('-o, --openvpn_opts <openvpn_opts>', 'Openvpn options', list)
.parse(process.argv);

require('../index.js')(program);
8 changes: 6 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,20 @@ const startOpenvpn = (options = []) => {
logger.info('Starting openvpn...');
const openvpn = `"${which.sync('openvpn')}"`;
const proc = execa(openvpn, ['--config', `"${filePath}"`].concat(options), { shell: true });

proc.stdout.pipe(logger.stream);
proc.stderr.on('data', data => logger.error(data.toString()));
proc.on('close', code => logger.info(`child process exited with code ${code}`));

process.on('exit', () => proc.kill());
process.on('SIGINT', () => proc.kill());

return proc;
};

const execute = (options) => {
logger.info('Querying data...');

ListVPNs(options.proxy)
.then((vpns) => {
return new Promise((resolve, reject) => {
Expand All @@ -86,8 +90,8 @@ const execute = (options) => {
})
.then(filter(options.country))
.then(save)
.then(() => startOpenvpn(options.options))
.then(() => startOpenvpn(options.openvpn_opts))
.catch(logger.error);
};

module.exports = (country, query) => execute(country, query);
module.exports = options => execute(options);
Loading

0 comments on commit 02260bb

Please sign in to comment.