From 420063822ffdb0f682dd7ba7c6cd5743c31627e3 Mon Sep 17 00:00:00 2001 From: sharpshark28 Date: Sat, 21 Jan 2017 19:07:39 -0600 Subject: [PATCH] Optional file path for cli --- README.md | 6 ++++++ blabber.js | 16 +++++++++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 0a7e00b..1c972a0 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,12 @@ $ Generating Comic... $ [ Comic Generated @ comics/1.png ] ``` +### Additional Options + +``` +$ blabber --path ~/Pictures +``` + ## How to use it in other projects ### Generate base64Data diff --git a/blabber.js b/blabber.js index 8b83421..7b36c29 100755 --- a/blabber.js +++ b/blabber.js @@ -2,7 +2,15 @@ 'use strict'; const fs = require('fs'); +const path = require('path'); const prompt = require('prompt'); +const argv = require('yargs') +.usage('Usage: blabber [options]') +.option('path') +.help() +.version() +.wrap(process.stdout.columns) +.argv; const blabberComic = require('./'); prompt.start(); @@ -43,11 +51,13 @@ function generate(conversation) { blabberComic(conversation) .then(rawBase64 => rawBase64.replace(/^data:image\/png;base64,/, '')) .then(base64 => { - let filename = Math.floor(Date.now() + Math.random()) + '.png'; + let filePath = argv.path || './'; + let fileName = Math.floor(Date.now() + Math.random()) + '.png'; + let fileOutput = path.join(filePath, fileName); - fs.writeFile(filename, base64, 'base64', error => { + fs.writeFile(fileOutput, base64, 'base64', error => { if(error) throw error; - else console.log('[ Comic Generated @ ' + filename + ' ]'); + else console.log('[ Comic Generated @ ' + fileOutput + ' ]'); }); }) .catch(error => { console.error('Uhoh... something went wrong.', error); });