Skip to content

Commit

Permalink
Add CLI -c --config to set the path to the configuration file.
Browse files Browse the repository at this point in the history
  • Loading branch information
rottmann committed May 8, 2015
1 parent f1b5682 commit ec022b7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
3 changes: 3 additions & 0 deletions bin/apidoc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ var argv = nomnom
.option('template', { abbr: 't', 'default': path.join(__dirname, '../template/'),
help: 'Use template for output files.' })

.option('config', { abbr: 'c', 'default': './', help: 'Path to config file (apidoc.json)' })

.option('verbose', { abbr: 'v', flag: true, 'default': false, help: 'Verbose debug output.' })

.option('help', { abbr: 'h', flag: true, help: 'Show this help information.' })
Expand Down Expand Up @@ -87,6 +89,7 @@ var options = {
src : argv['input'],
dest : argv['output'],
template : argv['template'],
config : argv['config'],
verbose : argv['verbose'],
debug : argv['debug'],
parse : argv['parse'],
Expand Down
11 changes: 5 additions & 6 deletions lib/package_info.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ PackageInfo.prototype.get = function() {
_.extend(result, this._getHeaderFooter(result));

if (Object.keys(apidocJson).length === 0 && ! packageJson.apidoc)
app.log.warn('Please create an apidoc.json.');
app.log.warn('Please create an apidoc.json configuration file.');

return result;
};
Expand All @@ -60,17 +60,16 @@ PackageInfo.prototype.get = function() {
*/
PackageInfo.prototype._readPackageData = function(filename) {
var result = {};
//var jsonFilename = path.join(app.options.src, filename);
var dir = this._resolveSrcPath();
var jsonFilename = path.join(dir, filename);

// read from source dir
// Read from source dir
if ( ! fs.existsSync(jsonFilename)) {
// read vom current dir
jsonFilename = './' + filename;
// Read from config dir (default './')
jsonFilename = path.join(app.options.config, filename);
}
if ( ! fs.existsSync(jsonFilename)) {
app.log.debug(filename + ' not found!');
app.log.debug(jsonFilename + ' not found!');
} else {
try {
result = JSON.parse( fs.readFileSync(jsonFilename, 'utf8') );
Expand Down

0 comments on commit ec022b7

Please sign in to comment.