Add option to specify where to look for .editorconfig files.
Adds a --config|c option which takes a directory in which the search for .editorconfig files will start. When --config|c is used together with explicit filenames of files to format, .editorconfig is searched only in --config directory, and not in directories where files are. Fixes #240.
This commit is contained in:
parent
049b151bac
commit
afd5799eb1
|
@ -16,7 +16,7 @@ else
|
||||||
import std.stdio : stdout, stdin, stderr, writeln, File;
|
import std.stdio : stdout, stdin, stderr, writeln, File;
|
||||||
import dfmt.config : Config;
|
import dfmt.config : Config;
|
||||||
import dfmt.formatter : format;
|
import dfmt.formatter : format;
|
||||||
import std.path : buildPath, expandTilde;
|
import std.path : buildPath, dirName, expandTilde;
|
||||||
import dfmt.editorconfig : getConfigFor;
|
import dfmt.editorconfig : getConfigFor;
|
||||||
import std.getopt : getopt, GetOptException;
|
import std.getopt : getopt, GetOptException;
|
||||||
|
|
||||||
|
@ -27,6 +27,7 @@ else
|
||||||
optConfig.pattern = "*.d";
|
optConfig.pattern = "*.d";
|
||||||
bool showHelp;
|
bool showHelp;
|
||||||
bool showVersion;
|
bool showVersion;
|
||||||
|
string explicitConfigDir;
|
||||||
|
|
||||||
void handleBooleans(string option, string value)
|
void handleBooleans(string option, string value)
|
||||||
{
|
{
|
||||||
|
@ -68,6 +69,7 @@ else
|
||||||
"version", &showVersion,
|
"version", &showVersion,
|
||||||
"align_switch_statements", &handleBooleans,
|
"align_switch_statements", &handleBooleans,
|
||||||
"brace_style", &optConfig.dfmt_brace_style,
|
"brace_style", &optConfig.dfmt_brace_style,
|
||||||
|
"config|c", &explicitConfigDir,
|
||||||
"end_of_line", &optConfig.end_of_line,
|
"end_of_line", &optConfig.end_of_line,
|
||||||
"help|h", &showHelp,
|
"help|h", &showHelp,
|
||||||
"indent_size", &optConfig.indent_size,
|
"indent_size", &optConfig.indent_size,
|
||||||
|
@ -127,11 +129,31 @@ else
|
||||||
|
|
||||||
ubyte[] buffer;
|
ubyte[] buffer;
|
||||||
|
|
||||||
|
Config explicitConfig;
|
||||||
|
if (explicitConfigDir)
|
||||||
|
{
|
||||||
|
import std.path : exists, isDir;
|
||||||
|
|
||||||
|
if (!exists(explicitConfigDir) || !isDir(explicitConfigDir))
|
||||||
|
{
|
||||||
|
stderr.writeln("--config_dir|c must specify existing directory path");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
explicitConfig = getConfigFor!Config(explicitConfigDir);
|
||||||
|
explicitConfig.pattern = "*.d";
|
||||||
|
}
|
||||||
|
|
||||||
if (readFromStdin)
|
if (readFromStdin)
|
||||||
{
|
{
|
||||||
|
import std.file : getcwd;
|
||||||
|
|
||||||
Config config;
|
Config config;
|
||||||
config.initializeWithDefaults();
|
config.initializeWithDefaults();
|
||||||
config.merge(optConfig, null);
|
if (explicitConfigDir != "")
|
||||||
|
{
|
||||||
|
config.merge(explicitConfig, buildPath(explicitConfigDir, "dummy.d"));
|
||||||
|
}
|
||||||
|
config.merge(optConfig, buildPath(getcwd(), "dummy.d"));
|
||||||
if (!config.isValid())
|
if (!config.isValid())
|
||||||
return 1;
|
return 1;
|
||||||
ubyte[4096] inputBuffer;
|
ubyte[4096] inputBuffer;
|
||||||
|
@ -165,9 +187,16 @@ else
|
||||||
}
|
}
|
||||||
Config config;
|
Config config;
|
||||||
config.initializeWithDefaults();
|
config.initializeWithDefaults();
|
||||||
|
if (explicitConfigDir != "")
|
||||||
|
{
|
||||||
|
config.merge(explicitConfig, buildPath(explicitConfigDir, "dummy.d"));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
Config fileConfig = getConfigFor!Config(path);
|
Config fileConfig = getConfigFor!Config(path);
|
||||||
fileConfig.pattern = "*.d";
|
fileConfig.pattern = "*.d";
|
||||||
config.merge(fileConfig, path);
|
config.merge(fileConfig, path);
|
||||||
|
}
|
||||||
config.merge(optConfig, path);
|
config.merge(optConfig, path);
|
||||||
if (!config.isValid())
|
if (!config.isValid())
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -207,6 +236,7 @@ https://github.com/Hackerpilot/dfmt
|
||||||
Options:
|
Options:
|
||||||
--help, -h Print this help message
|
--help, -h Print this help message
|
||||||
--inplace, -i Edit files in place
|
--inplace, -i Edit files in place
|
||||||
|
--config_dir, -c Path to directory to load .editconfig file from.
|
||||||
--version Print the version number and then exit
|
--version Print the version number and then exit
|
||||||
|
|
||||||
Formatting Options:
|
Formatting Options:
|
||||||
|
|
Loading…
Reference in New Issue