static int VerifyArgumentsAndRun()
{
Arguments arguments = null;
try
{
var fileSystem = new FileSystem();
var argumentsWithoutExeName = GetArgumentsWithoutExeName();
try
{
arguments = ArgumentParser.ParseArguments(argumentsWithoutExeName);
}
catch (Exception exception)
{
Console.WriteLine("Failed to parse arguments: {0}", string.Join(" ", argumentsWithoutExeName));
if (!string.IsNullOrWhiteSpace(exception.Message))
{
Console.WriteLine();
Console.WriteLine(exception.Message);
Console.WriteLine();
}
HelpWriter.Write();
return 1;
}
if (arguments.IsHelp)
{
HelpWriter.Write();
return 0;
}
if (arguments.Diag)
{
arguments.NoCache = true;
arguments.Output = OutputType.BuildServer;
}
ConfigureLogging(arguments);
if (arguments.Diag)
{
Logger.WriteInfo("Dumping commit graph: ");
GitTools.LibGitExtensions.DumpGraph(arguments.TargetPath, Logger.WriteInfo, 100);
}
if (!Directory.Exists(arguments.TargetPath))
{
Logger.WriteWarning(string.Format("The working directory '{0}' does not exist.", arguments.TargetPath));
}
else
{
Logger.WriteInfo("Working directory: " + arguments.TargetPath);
}
VerifyConfiguration(arguments, fileSystem);
if (arguments.Init)
{
ConfigurationProvider.Init(arguments.TargetPath, fileSystem, new ConsoleAdapter());
return 0;
}
if (arguments.ShowConfig)
{
Console.WriteLine(ConfigurationProvider.GetEffectiveConfigAsString(arguments.TargetPath, fileSystem));
return 0;
}
if (!string.IsNullOrEmpty(arguments.Proj) || !string.IsNullOrEmpty(arguments.Exec))
{
arguments.Output = OutputType.BuildServer;
}
SpecifiedArgumentRunner.Run(arguments, fileSystem);
}
catch (WarningException exception)
{
var error = string.Format("An error occurred:\r\n{0}", exception.Message);
Logger.WriteWarning(error);
return 1;
}
catch (Exception exception)
{
var error = string.Format("An unexpected error occurred:\r\n{0}", exception);
Logger.WriteError(error);
if (arguments != null)
{
Logger.WriteInfo(string.Empty);
Logger.WriteInfo("Attempting to show the current git graph (please include in issue): ");
Logger.WriteInfo("Showing max of 100 commits");
try
{
GitTools.LibGitExtensions.DumpGraph(arguments.TargetPath, Logger.WriteInfo, 100);
}
catch (Exception dumpGraphException)
{
Logger.WriteError("Couldn't dump the git graph due to the following error: " + dumpGraphException);
}
}
return 1;
}
return 0;
}