Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Address PR feedback
  • Loading branch information
kant2002 committed Jun 30, 2023
commit f04b01e40539d634b03622642c630dc97c2fbb5a
39 changes: 30 additions & 9 deletions src/BenchmarkDotNet/ConsoleArguments/ConfigParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,13 @@ public static (bool isSuccess, IConfig config, CommandLineOptions options) Parse
{
(bool isSuccess, IConfig config, CommandLineOptions options) result = default;

args = ExpandResponseFile(args).ToArray();
var (expandSuccess, expandedArgs) = ExpandResponseFile(args, logger);
if (!expandSuccess)
{
return (false, default, default);
}

args = expandedArgs;
using (var parser = CreateParser(logger))
{
parser
Expand All @@ -88,36 +94,51 @@ public static (bool isSuccess, IConfig config, CommandLineOptions options) Parse
return result;
}

private static IEnumerable<string> ExpandResponseFile(string[] args)
private static (bool Success, string[] ExpandedTokens) ExpandResponseFile(string[] args, ILogger logger)
{
List<string> result = new ();
foreach (var arg in args)
{
if (arg.StartsWith("@"))
{
var fileName = arg.Substring(1);
if (File.Exists(fileName))
try
{
var lines = File.ReadAllLines(fileName);
foreach (var line in lines)
if (File.Exists(fileName))
{
var lines = File.ReadAllLines(fileName);
foreach (var line in lines)
{
result.AddRange(ConsumeTokens(line));
}
}
else
{
foreach (var token in ConsumeTokens(line))
yield return token;
logger.WriteLineError($"Response file {fileName} does not exists.");
return (false, Array.Empty<string>());
}
}
catch (Exception ex)
{
logger.WriteLineError($"Failed to parse RSP file: {fileName}, {ex.Message}");
return (false, Array.Empty<string>());
}
}
else
{
if (arg.Contains(' '))
{
// Workaround for CommandLine library issue with parsing these kind of args.
yield return " " + arg;
result.Add(" " + arg);
}
else
{
yield return arg;
result.Add(arg);
}
}
}

return (true, result.ToArray());
}

private static IEnumerable<string> ConsumeTokens(string line)
Expand Down