back to home

Tyrrrz / CliWrap

Library for interacting with command-line interfaces

4,912 stars
283 forks
2 issues
C#

AI Architecture Analysis

This repository is indexed by RepoMind. By analyzing Tyrrrz/CliWrap in our AI interface, you can instantly generate complete architecture diagrams, visualize control flows, and perform automated security audits across the entire codebase.

Our Agentic Context Augmented Generation (Agentic CAG) engine loads full source files into context on-demand, avoiding the fragmentation of traditional RAG systems. Ask questions about the architecture, dependencies, or specific features to see it in action.

Source files are only loaded when you start an analysis to optimize performance.

Embed this Badge

Showcase RepoMind's analysis directly in your repository's README.

[![Analyzed by RepoMind](https://img.shields.io/badge/Analyzed%20by-RepoMind-4F46E5?style=for-the-badge)](https://repomind.in/repo/Tyrrrz/CliWrap)
Preview:Analyzed by RepoMind

Repository Overview (README excerpt)

Crawler view

CliWrap Development of this project is entirely funded by the community. Consider donating to support! **CliWrap** is a library for interacting with command-line interfaces. It provides a convenient model for launching processes, redirecting input and output streams, awaiting completion, handling cancellation, and more. Terms of use [[?]](https://github.com/Tyrrrz/.github/blob/prime/docs/why-so-political.md) By using this project or its source code, for any purpose and in any shape or form, you grant your **implicit agreement** to all the following statements: • You **condemn Russia and its military aggression against Ukraine** • You **recognize that Russia is an occupant that unlawfully invaded a sovereign state** • You **support Ukraine's territorial integrity, including its claims over temporarily occupied territories of Crimea and Donbas** • You **reject false narratives perpetuated by Russian state propaganda** To learn more about the war and how you can help, click here. Glory to Ukraine! 🇺🇦 Install • 📦 NuGet: Features • Airtight abstraction over • Fluent configuration interface • Flexible support for piping • Fully asynchronous and cancellation-aware API • Graceful cancellation using interrupt signals • Designed with strict immutability in mind • Provides safety against typical deadlock scenarios • Tested on Windows, Linux, and macOS • Targets .NET Standard 2.0+, .NET Core 3.0+, .NET Framework 4.6.2+ • No external dependencies Usage Video guides You can watch one of these videos to learn how to use the library: • **OSS Power-Ups: CliWrap** by Oleksii Holub • **Stop using the Process class for CLI interactions in .NET** by Nick Chapsas Quick overview Similarly to a shell, **CliWrap**'s base unit of work is a **command** — an object that encapsulates instructions for running a process. To build a command, start by calling with the executable path, and then use the provided fluent interface to configure arguments, working directory, or other options. Once the command is configured, you can run it by calling : The code above spawns a child process with the configured command-line arguments and working directory, and then asynchronously waits for it to exit. After the task has completed, it resolves to a object that contains the process exit code and other relevant information. > [!WARNING] > **CliWrap** will throw an exception if the underlying process returns a non-zero exit code, as it usually indicates an error. > You can override this behavior by disabling result validation using . By default, the process's standard input, output and error streams are routed to **CliWrap**'s equivalent of a _null device_, which represents an empty source and a target that discards all data. You can change this by calling , , or to configure pipes for the corresponding streams: This example command is configured to decode the data written to the standard output and error streams as text, and append it to the corresponding buffers. Once the execution is complete, these buffers can be inspected to see what the process has printed to the console. Handling command output is a very common use case, so **CliWrap** offers a few high-level execution models to make these scenarios simpler. In particular, the same thing shown above can also be achieved more succinctly with the extension method: > [!WARNING] > Be mindful when using . > Programs can write arbitrary data (including binary) to the output and error streams, and storing it in-memory may be impractical. > For more advanced scenarios, **CliWrap** also provides other piping options, which are covered in the piping section. Command configuration The fluent interface provided by the command object allows you to configure various aspects of its execution. This section covers all available configuration methods and their usage. > [!NOTE] > is an immutable object — all configuration methods listed here create a new instance instead of modifying the existing one. Sets the command-line arguments passed to the child process. **Default**: empty. **Examples**: • Set arguments using an array: • Set arguments using a builder: > [!TIP] > The builder overload allows you to define custom extension methods for reusable argument patterns. > Learn more. • Set arguments directly: > [!WARNING] > Unless you absolutely have to, avoid setting command-line arguments directly from a string. > This method expects all arguments to be correctly escaped and formatted ahead of time — which can be cumbersome to do yourself. > Formatting errors may result in unexpected bugs and security vulnerabilities. > [!NOTE] > There are some obscure scenarios, where you may need to assemble the command-line arguments yourself. > In such cases, you can use the method to escape individual arguments manually. Sets the working directory of the child process. **Default**: current working directory, i.e. . **Example**: Sets additional environment variables exposed to the child process. **Default**: empty. **Examples**: • Set environment variables using a builder: • Set environment variables directly: > [!NOTE] > Environment variables configured using are applied on top of those inherited from the parent process. > If you need to remove an inherited variable, set the corresponding value to . Sets the system resource management policy for the child process. **Default**: default policy. **Examples**: • Set resource policy using a builder: • Set resource policy directly: > [!WARNING] > Resource policy options have varying support across different platforms. Sets domain, name and password of the user, under whom the child process should be started. **Default**: no credentials. **Examples**: • Set credentials using a builder: • Set credentials directly: > [!WARNING] > Running a process under a different username is supported across all platforms, but other options are only available on Windows. Sets the strategy for validating the result of an execution. **A…