Permalink
Browse files

thread opts around

  • Loading branch information...
1 parent c5ef441 commit ce9ce9b4ce111d4cee8fa0aaf5239f21e0fc038d @substack committed Oct 3, 2012
Showing with 21 additions and 8 deletions.
  1. +21 −8 index.js
View
29 index.js
@@ -3,8 +3,21 @@ var through = require('through');
var split = require('event-stream').split;
var run = require('comandante');
-exports = module.exports = function (ref) {
- return {
+exports = module.exports = function (ref, opts) {
+ if (ref && typeof ref === 'object') {
+ opts = ref;
+ return {
+ list : function (ref, file) { return readDir(ref, file, opts) },
+ read : function (ref, file) { return readFile(ref, file, opts) },
+ }
+ }
+ else if (opts) {
+ return {
+ list : function (file) { return readDir(ref, file, opts) },
+ read : function (file) { return readFile(ref, file, opts) },
+ }
+ }
+ else return {
list : readDir.bind(null, ref),
read : readFile.bind(null, ref),
};
@@ -13,16 +26,16 @@ exports = module.exports = function (ref) {
exports.list = readDir;
exports.read = readFile;
-function show (ref, file) {
+function show (ref, file, opts) {
if (file === '.') file = './';
- return run('git', [ 'show', ref + ':' + file ]);
+ return run('git', [ 'show', ref + ':' + file ], opts);
}
-function readFile (ref, file) {
- return show(ref, file);
+function readFile (ref, file, opts) {
+ return show(ref, file, opts);
}
-function readDir (ref, dir) {
+function readDir (ref, dir, opts) {
var num = 0;
var tr = through(function (line) {
if (num === 0) {
@@ -42,5 +55,5 @@ function readDir (ref, dir) {
num ++;
});
- return show(ref, dir).pipe(split()).pipe(tr);
+ return show(ref, dir, opts).pipe(split()).pipe(tr);
}

0 comments on commit ce9ce9b

Please sign in to comment.