Add a temporary function that warns or patches the old INI section (#570)
* Add a temporary function that warns or patches the old INI section * fix tabs in help message
This commit is contained in:
parent
9fa8756233
commit
eb281030f5
|
@ -68,6 +68,7 @@ else
|
||||||
bool printVersion;
|
bool printVersion;
|
||||||
bool explore;
|
bool explore;
|
||||||
string errorFormat;
|
string errorFormat;
|
||||||
|
bool patchConfig;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -96,7 +97,8 @@ else
|
||||||
"muffinButton", &muffin,
|
"muffinButton", &muffin,
|
||||||
"explore", &explore,
|
"explore", &explore,
|
||||||
"skipTests", &skipTests,
|
"skipTests", &skipTests,
|
||||||
"errorFormat|f", &errorFormat);
|
"errorFormat|f", &errorFormat,
|
||||||
|
"patchConfig", &patchConfig);
|
||||||
//dfmt on
|
//dfmt on
|
||||||
}
|
}
|
||||||
catch (ConvException e)
|
catch (ConvException e)
|
||||||
|
@ -233,7 +235,11 @@ else
|
||||||
StaticAnalysisConfig config = defaultStaticAnalysisConfig();
|
StaticAnalysisConfig config = defaultStaticAnalysisConfig();
|
||||||
string s = configLocation is null ? getConfigurationLocation() : configLocation;
|
string s = configLocation is null ? getConfigurationLocation() : configLocation;
|
||||||
if (s.exists())
|
if (s.exists())
|
||||||
|
{
|
||||||
|
if (hasWrongIniFileSection(s, patchConfig))
|
||||||
|
return 0;
|
||||||
readINIFile(config, s);
|
readINIFile(config, s);
|
||||||
|
}
|
||||||
if (skipTests)
|
if (skipTests)
|
||||||
config.enabled2SkipTests;
|
config.enabled2SkipTests;
|
||||||
if (report)
|
if (report)
|
||||||
|
@ -387,7 +393,10 @@ Options:
|
||||||
Generates a default configuration file for the static analysis checks,
|
Generates a default configuration file for the static analysis checks,
|
||||||
|
|
||||||
--skipTests
|
--skipTests
|
||||||
Does not analyze in the unittests. Only works if --styleCheck.`,
|
Does not analyze in the unittests. Only works if --styleCheck.,
|
||||||
|
|
||||||
|
--patchConfig
|
||||||
|
Patches the configuration file passed as parameter for v0.5.0.`,
|
||||||
|
|
||||||
programName);
|
programName);
|
||||||
}
|
}
|
||||||
|
@ -463,3 +472,41 @@ string getConfigurationLocation()
|
||||||
|
|
||||||
return getDefaultConfigurationLocation();
|
return getDefaultConfigurationLocation();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// Patch the INI file to v0.5.0 format.
|
||||||
|
//TODO: remove this from v0.6.0
|
||||||
|
bool hasWrongIniFileSection(string confiFilename, bool patch)
|
||||||
|
{
|
||||||
|
import std.string : indexOf;
|
||||||
|
import std.array : replace;
|
||||||
|
|
||||||
|
bool result;
|
||||||
|
|
||||||
|
static immutable v1 = "analysis.config.StaticAnalysisConfig";
|
||||||
|
static immutable v2 = "dscanner.analysis.config.StaticAnalysisConfig";
|
||||||
|
|
||||||
|
char[] c = cast(char[]) readFile(confiFilename);
|
||||||
|
try if (const ptrdiff_t i = c.indexOf(v1))
|
||||||
|
{
|
||||||
|
if (!patch)
|
||||||
|
{
|
||||||
|
writeln("warning, the configuration file `", confiFilename, "` contains an outdated property");
|
||||||
|
writeln("change manually [", v1, "] to [", v2, "]" );
|
||||||
|
writeln("or restart D-Scanner with the `--patchConfig` option");
|
||||||
|
result = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
c = replace(c, v1, v2);
|
||||||
|
std.file.write(confiFilename, c);
|
||||||
|
writeln("the configuration file `", confiFilename, "` has been updated correctly");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
stderr.writeln("error encountered when trying to verify the INI file compatibility");
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue