Skip to content

A Swiss Army knife for developers.

Added piping support to DevToys.CLI

Etienne Baudouxa6becc22c456
diff --git a/src/app/dev/DevToys.Business/ViewModels/MainWindowViewModel.cs b/src/app/dev/DevToys.Business/ViewModels/MainWindowViewModel.cs
index 175d26549..e51eb1747 100644
--- a/src/app/dev/DevToys.Business/ViewModels/MainWindowViewModel.cs
+++ b/src/app/dev/DevToys.Business/ViewModels/MainWindowViewModel.cs
@@ -213,7 +213,7 @@ internal sealed partial class MainWindowViewModel : ObservableRecipient
try
{
- var cancellationTokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(2));
+ using var cancellationTokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(2));
INotifyPropertyChanged? selectedMenuBeforeSmartDetection = SelectedMenuItem;
Guard.IsNotNull(selectedMenuBeforeSmartDetection);
diff --git a/src/app/dev/DevToys.Core/Debugger/DebuggerHelper.cs b/src/app/dev/DevToys.Core/Debugger/DebuggerHelper.cs
index 83fe2c1fd..0690c2a4d 100644
--- a/src/app/dev/DevToys.Core/Debugger/DebuggerHelper.cs
+++ b/src/app/dev/DevToys.Core/Debugger/DebuggerHelper.cs
@@ -6,7 +6,7 @@ public static class DebuggerHelper
{
#if DEBUG
limit ??= TimeSpan.FromSeconds(60);
- var source = new CancellationTokenSource(limit.Value);
+ using var source = new CancellationTokenSource(limit.Value);
Console.WriteLine($"◉ Waiting {limit.Value.TotalSeconds} secs for debugger (PID: {Process.GetCurrentProcess().Id})...");
diff --git a/src/app/dev/platforms/desktop/DevToys.CLI/Program.cs b/src/app/dev/platforms/desktop/DevToys.CLI/Program.cs
index fa4f2bec7..ddf525dce 100644
--- a/src/app/dev/platforms/desktop/DevToys.CLI/Program.cs
+++ b/src/app/dev/platforms/desktop/DevToys.CLI/Program.cs
@@ -94,6 +94,23 @@ internal partial class Program
}
}
+ // Read the pipeline input, if any.
+ if (Console.IsInputRedirected)
+ {
+ string pipelineInput = await Console.In.ReadToEndAsync(CancellationToken.None);
+
+ // Remove the last new line, if any.
+ if (pipelineInput.EndsWith(Environment.NewLine))
+ {
+ pipelineInput = pipelineInput.Substring(0, pipelineInput.Length - Environment.NewLine.Length);
+ }
+
+ // Remove the BOM character, if any.
+ pipelineInput = pipelineInput.Trim(new char[] { '\uFEFF', '\u200B' });
+
+ args = args.Append(pipelineInput).ToArray();
+ }
+
// Parse the command prompt arguments and run the appropriate command, if possible.
int exitCode = await rootCommand.InvokeAsync(args);
Environment.ExitCode = exitCode;