$ show Tyrrrz/CliWrap
CliWrap is a .NET library that provides an airtight, fluent abstraction over System.Diagnostics.Process for interacting with command-line interfaces. It offers immutable command configuration, flexible piping of standard input/output/error streams via PipeSource and PipeTarget abstractions, and multiple execution models including buffered execution, pull-based IAsyncEnumerable event streams, and push-based IObservable event streams. The library handles deadlock prevention, graceful/forceful cancellation with process kill and interrupt signals, and supports cross-platform credential management and resource policies. Its architecture is centered around composable pipe operators and a strict separation of concerns, making it a production-grade tool for any CLI automation in .NET. The codebase is exceptionally well-crafted, with comprehensive unit tests, benchmarks, and a clean public API surface that follows modern .NET conventions.
The LLM identified 5 files worth highlighting for reuse:
Defines the PipeSource abstract class representing the standard input stream source. Provides a Null pipe, factory methods for streams, files, bytes, strings, and command chaining, plus an anonymous delegate overload. The design is minimal, immutable, and easily extensible without touching library internals.
Defines the PipeTarget abstract class for standard output/error streams. Includes Null, stream, file, StringBuilder, delegate (sync/async/cancellable) pipe targets, and a Merge method for fan-out replication. The AggregatePipeTarget internally uses SimplexStream to distribute data to multiple consumers, handling backpressure and error propagation.
An internal in-memory stream that enables a single-writer/multiple-reader pattern for fan-out piping. Uses semaphores for coordination and supports cancellation. Notably handles end-of-stream latching and partial reads/writes. This is a non-trivial synchronization implementation that could be extracted as a standalone utility for producer-consumer scenarios.
A lightweight async channel using two semaphores and a mutable cell for single-item transmission. Enables the pull-based event stream execution model. The implementation is minimal and efficient, suitable for extracting as a general async synchronization primitive.
A fluent builder for constructing command-line argument strings with proper escaping (handling spaces, quotes, backslashes). Includes a static Escape method that replicates .NET's ProcessStartInfo argument logic. Demonstrates careful attention to cross-platform argument formatting and is reusable standalone.