Skip to content

Commit

Permalink
feat(cli): add --config to command line options
Browse files Browse the repository at this point in the history
azu committed Sep 7, 2015
1 parent 324767c commit ff57fda
Showing 4 changed files with 27 additions and 3 deletions.
20 changes: 18 additions & 2 deletions lib/config/config-loader.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,26 @@
// LICENSE : MIT
"use strict";
var rc = require('rc-loader');
var tryResolve = require("try-resolve");
// DEFAULT CONFIG FILE NAME
var CONFIG_FILENAME = "textlint";
var CONFIG_PACKAGE_PREFIX = "textlint-config-";
function isConfigModule(filePath) {
if (filePath == null) {
return false;
}
// scoped module package
return (filePath.charAt(0) === "@" || filePath.indexOf(CONFIG_PACKAGE_PREFIX) !== -1);
}
function load(configFilePath) {
var config = configFilePath ? {config: configFilePath} : null;
return rc(CONFIG_FILENAME, {}, config);
if (isConfigModule(configFilePath)) {
// config as a module - shared config
// FIXME: not tested function
return require(tryResolve.relative(configFilePath))
} else {
// auto or specify config file
var config = configFilePath ? {config: configFilePath} : null;
return rc(CONFIG_FILENAME, {}, config);
}
}
module.exports = load;
2 changes: 2 additions & 0 deletions lib/config/config.js
Original file line number Diff line number Diff line change
@@ -42,6 +42,8 @@ function Config(options) {
* @type {string|null}
*/
this.configFile = options.configFile;
// TODO: add `noUseConfig` option
// configFile is optional
var userConfig = loadConfig(this.configFile);
// rule names
var ruleKeys = userConfig.rules ? availableRuleKeys(userConfig.rules) : [];
7 changes: 7 additions & 0 deletions lib/options.js
Original file line number Diff line number Diff line change
@@ -14,6 +14,13 @@ module.exports = optionator({
type: "Boolean",
description: "Show help."
},
{
option: "config",
alias: "c",
type: "path::String",
description: "Use configuration from this file or sharable config.",
example: "--config /path/to/.textlintrc"
},
{
option: "rule",
type: "[path::String]",
1 change: 0 additions & 1 deletion lib/textlint-engine.js
Original file line number Diff line number Diff line change
@@ -5,7 +5,6 @@ var textLint = require("./textlint");
var fileTraverse = require("./util/traverse");
var Config = require("./config/config");
var createFormatter = require("textlint-formatter");
var fs = require("fs");
var tryResolve = require("try-resolve");
var path = require("path");
var debug = require("debug")("text:cli-engine");

0 comments on commit ff57fda

Please sign in to comment.