Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for "-f -" #1

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ Currently it indexes all functions, both public and private.
## Usage

$ bin/javascript-ctags -?
javascript-ctags [-?] [-t tagfile] [fileglob]
javascript-ctags [-?] [-t/-f tagfile] [fileglob]
--help, -h, -? show this
--tagfile, -t The generated tagfile (default tags)
--tagfile, -t, -f The generated tagfile (default tags), use - for STDOUT
fileglob A glob pattern (supports **/*.js), (default *.js)


Expand Down
10 changes: 9 additions & 1 deletion lib/javascript_ctags.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,16 @@ function parse(files) {
}

function writeFile(filename, tags) {
fs.writeFileSync(filename, tags.join('\n'));
var contents = tags.join("\n");
if(filename == "-") {
console.log(contents);
} else {
fs.writeFileSync(filename, contents);
}
}



module.exports = parseAndGenerate;
module.exports.files = files;
module.exports.writeFile = writeFile;
5 changes: 3 additions & 2 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ function parseArgs(args) {
};
var shortcuts = {
t: '--tagfile',
f: '--tagfile',
h: '--help',
'?': '--help'
};
Expand All @@ -30,9 +31,9 @@ function parseArgs(args) {
}

function usage() {
console.log('javascript-ctags [-?] [-t tagfile] [fileglob]');
console.log('javascript-ctags [-?] [-t or -f tagfile] [fileglob]');
console.log('--help, -h, -?\t show this');
console.log('--tagfile, -t\t The generated tagfile (default tags)');
console.log('--tagfile, -t, -f\t The generated tagfile (default tags), use - for STDOUT');
console.log(' fileglob\t A glob pattern (supports **/*.js), (default *.js)');
}

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
},
"devDependencies": {
"mocha": "~1.7.0",
"chai": "~1.3.0"
"chai": "~1.3.0",
"sinon": "~1.7"
},
"bin": { "javascript-ctags": "./bin/javascript-ctags" }
}
30 changes: 30 additions & 0 deletions test/javascript_ctags_spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
"use strict";

require('mocha');
var sinon = require('sinon');
var expect = require('chai').expect;
var fs = require('fs');

var javascriptCtags = require('../lib/javascript_ctags');

Expand All @@ -13,4 +15,32 @@ describe('main', function() {
expect(files).to.have.length(5);
});
});

describe("#writeFile", function(){
var consoleSpy,
fsSpy,
tags = [];

beforeEach(function() {
consoleSpy = sinon.spy(console, 'log');
fsSpy = sinon.spy(fs, 'writeFileSync');
});

afterEach(function() {
console.log.restore();
fs.writeFileSync.restore();
});

it("writes contents to console if filename is -", function(){
javascriptCtags.writeFile("-", tags);
expect(consoleSpy.called).to.equal(true);
expect(fsSpy.called).to.equal(false);
});

it("writes contents to given file", function(){
javascriptCtags.writeFile("tags", tags);
expect(fsSpy.called).to.equal(true);
expect(consoleSpy.called).to.equal(false);
});
});
});