Skip to content

Commit

Permalink
Fix grpc-curl stdin behavior on CI with tests
Browse files Browse the repository at this point in the history
  • Loading branch information
xoofx committed Jan 21, 2022
1 parent a179e57 commit 95a5249
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/GrpcCurl/GrpcCurlApp.cs
Expand Up @@ -101,10 +101,16 @@ public static async Task<int> Run(GrpcCurlOptions options)
});

// Parse input from stdin if data was not passed by command line
if (options.Data is null || Console.IsInputRedirected)
var data = options.Data;
if (data is null)
{
options.Data = ParseJson(await Console.In.ReadToEndAsync());
if (Console.IsInputRedirected)
{
data = ParseJson(await Console.In.ReadToEndAsync());
}
}
data ??= new Dictionary<string, object>();


if (!client.TryFindMethod(options.Service, options.Method, out var methodDescriptor))
{
Expand All @@ -114,7 +120,7 @@ public static async Task<int> Run(GrpcCurlOptions options)
// Parse Input
var input = new List<IDictionary<string, object>>();

if (options.Data is IEnumerable<object> it)
if (data is IEnumerable<object> it)
{
int index = 0;
foreach (var item in it)
Expand All @@ -131,13 +137,13 @@ public static async Task<int> Run(GrpcCurlOptions options)
index++;
}
}
else if (options.Data is IDictionary<string, object> dict)
else if (data is IDictionary<string, object> dict)
{
input.Add(dict);
}
else
{
throw new GrpcCurlException($"Invalid type `{options.Data?.GetType()?.FullName}` from the input. Expecting an object.");
throw new GrpcCurlException($"Invalid type `{data?.GetType()?.FullName}` from the input. Expecting an object.");
}

// Perform the async call
Expand Down

0 comments on commit 95a5249

Please sign in to comment.