Skip to content

Commit

Permalink
Merge pull request #93 from tarrow/fixLoggingAndOutputDir
Browse files Browse the repository at this point in the history
Allow no outdir if dryrunning and ensure log file location
  • Loading branch information
Richard Smith-Unna committed May 1, 2016
2 parents bff5ef2 + 50164ef commit 2762a75
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions bin/getpapers.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,15 @@ log = new (winston.Logger)({
});
winston.addColors(loglevels.colors);



if (program.hasOwnProperty('logfile')) {
logstream = fs.createWriteStream(program.logfile.toString());
log.add(winston.transports.File, {
filename: program.logfile,
stream: logstream,
level: 'debug'
});
log.info('Saving logs to ./' + program.outdir + '/' + program.logfile);
log.info('Saving logs to ./' + program.logfile);
}

// check arguments
Expand All @@ -83,12 +86,6 @@ if (!program.query) {
process.exit(1);
}

if (!program.outdir) {
log.error('No output directory given. ' +
'You must provide the --outdir argument.');
process.exit(1);
}

log.info('Searching using ' + program.api + ' API');

// run
Expand All @@ -103,9 +100,16 @@ options.noexecute = program.noexecute;
if (options.noexecute) {
log.info('Running in no-execute mode, so nothing will be downloaded');
}
else {
if (!program.outdir) {
log.error('No output directory given. ' +
'You must provide the --outdir argument.');
process.exit(1);
}
mkdirp.sync(program.outdir);
process.chdir(program.outdir);
}

mkdirp.sync(program.outdir);
process.chdir(program.outdir);
var chosenapi = api(program.api);
var searchapi = new chosenapi(options);
searchapi.search(program.query);

0 comments on commit 2762a75

Please sign in to comment.