diff --git a/src/GrpcCurl/GrpcCurlApp.cs b/src/GrpcCurl/GrpcCurlApp.cs index 8fb256d..3d98e7b 100644 --- a/src/GrpcCurl/GrpcCurlApp.cs +++ b/src/GrpcCurl/GrpcCurlApp.cs @@ -101,10 +101,16 @@ public static async Task 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(); + if (!client.TryFindMethod(options.Service, options.Method, out var methodDescriptor)) { @@ -114,7 +120,7 @@ public static async Task Run(GrpcCurlOptions options) // Parse Input var input = new List>(); - if (options.Data is IEnumerable it) + if (data is IEnumerable it) { int index = 0; foreach (var item in it) @@ -131,13 +137,13 @@ public static async Task Run(GrpcCurlOptions options) index++; } } - else if (options.Data is IDictionary dict) + else if (data is IDictionary 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