fixing issue with args passed to Functions.Generator

This commit is contained in:
Brett Samblanet 2020-08-31 14:17:33 -07:00 коммит произвёл Naren Soni
Родитель 51b895eba5
Коммит 6d820090d6
2 изменённых файлов: 52 добавлений и 11 удалений

Просмотреть файл

@ -21,9 +21,7 @@ namespace Microsoft.NET.Sdk.Functions.Console
}
else
{
var assemblyPath = args[0].Trim();
var outputPath = args[1].Trim();
var functionsInDependencies = bool.Parse(args[2].Trim());
ParseArgs(args, out string assemblyPath, out string outputPath, out bool functionsInDependencies, out IEnumerable<string> excludedFunctionNames);
var assemblyDir = Path.GetDirectoryName(assemblyPath);
#if NETCOREAPP2_1
@ -37,13 +35,6 @@ namespace Microsoft.NET.Sdk.Functions.Console
return Assembly.LoadFrom(Path.Combine(assemblyDir, e.Name + ".dll"));
};
#endif
IEnumerable<string> excludedFunctionNames = Enumerable.Empty<string>();
if (args.Length > 2)
{
var excludedFunctionNamesArg = args[2].Trim();
excludedFunctionNames = excludedFunctionNamesArg.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
}
var converter = new FunctionJsonConverter(logger, assemblyPath, outputPath, functionsInDependencies, excludedFunctionNames);
if (!converter.TryRun())
@ -52,5 +43,20 @@ namespace Microsoft.NET.Sdk.Functions.Console
}
}
}
internal static void ParseArgs(string[] args, out string assemblyPath, out string outputPath, out bool functionsInDependencies, out IEnumerable<string> excludedFunctionNames)
{
assemblyPath = args[0].Trim();
outputPath = args[1].Trim();
functionsInDependencies = bool.Parse(args[2].Trim());
excludedFunctionNames = Enumerable.Empty<string>();
if (args.Length > 3)
{
var excludedFunctionNamesArg = args[3].Trim();
excludedFunctionNames = excludedFunctionNamesArg.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
}
}
}
}

Просмотреть файл

@ -0,0 +1,35 @@
using System.Collections.Generic;
using Microsoft.NET.Sdk.Functions.Console;
using Xunit;
namespace Microsoft.NET.Sdk.Functions.Test
{
public class ArgumentsTests
{
[Fact]
public void NoExcludedFunctions()
{
var args = new[] { @"assemblyPath", "outputPath", "true" };
Program.ParseArgs(args, out string assemblyPath, out string outputPath, out bool functionsInDependencies, out IEnumerable<string> excludedFunctionNames);
Assert.Equal("assemblyPath", assemblyPath);
Assert.Equal("outputPath", outputPath);
Assert.True(functionsInDependencies);
Assert.Empty(excludedFunctionNames);
}
[Fact]
public void ExcludedFunctions()
{
var args = new[] { @"assemblyPath", "outputPath", "false", "Function1;Function2" };
Program.ParseArgs(args, out string assemblyPath, out string outputPath, out bool functionsInDependencies, out IEnumerable<string> excludedFunctionNames);
Assert.Equal("assemblyPath", assemblyPath);
Assert.Equal("outputPath", outputPath);
Assert.False(functionsInDependencies);
Assert.Collection(excludedFunctionNames,
s => Assert.Equal("Function1", s),
s => Assert.Equal("Function2", s));
}
}
}