Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/manojlds/cmd
C# library to run external programs in a simpler way. Demonstration of "dynamic" features of C#.
https://github.com/manojlds/cmd
Last synced: 29 days ago
JSON representation
C# library to run external programs in a simpler way. Demonstration of "dynamic" features of C#.
- Host: GitHub
- URL: https://github.com/manojlds/cmd
- Owner: manojlds
- License: apache-2.0
- Created: 2012-11-12T18:08:26.000Z (about 12 years ago)
- Default Branch: master
- Last Pushed: 2020-05-18T17:25:35.000Z (over 4 years ago)
- Last Synced: 2024-10-11T12:09:16.351Z (2 months ago)
- Language: C#
- Homepage:
- Size: 1.23 MB
- Stars: 354
- Watchers: 37
- Forks: 48
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-csharp - cmd - C# library to run external programs in a simpler way. Demonstration of "dynamic" features of C#. (DLR)
- awesome-dotnet-cn - cmd - 用一种简单的方式来运行外部程序的C#库。阐述了C#的“动态”功能。 (DLR)
- awesome-dotnet - cmd - C# library to run external programs in a simpler way. Demonstration of "dynamic" features of C#. (DLR)
- awesome-dot-dev - cmd - C# library to run external programs in a simpler way. Demonstration of "dynamic" features of C#. (DLR)
- awsome-dotnet - cmd - C# library to run external programs in a simpler way. Demonstration of "dynamic" features of C#. (DLR)
- awesome-dotnet - cmd - C# library to run external programs in a simpler way. Demonstration of "dynamic" features of C#. (DLR)
README
# cmd #
A C# Library to run external programs / commands in a simpler way. It is inspired from the [sh](https://github.com/amoffat/sh) library for Python, and is intended to showcase the "dynamic" features of C#
**How to get it?**
Cmd is available through the Nuget Package Manager.
Or, you can build it from source.
**How to use it?**
Create a dynamic instance of Cmd:
```csharp
dynamic cmd = new Cmd();
```Now, you can call commands off cmd:
```csharp
cmd.git.clone("http://github.com/manojlds/cmd");
```The above would be equivalent to `git clone http://github.com/manojlds/cmd`.
You can pass flags by naming the arguments:
```csharp
cmd.git.log(grep: "test");
```The above would be equivalent to `git log --grep test`
Or:
```csharp
cmd.git.branch(a: true);
```which would be equivalent to `git branch -a`
Note that single character flags are mapped as `-` and multi-character ones are mapped as `--`
Also, non-string values are ignored and if there is no flag, the argument is not considered.
You can call multiple commands off the same instance of cmd:
```csharp
var gitOutput = cmd.git();
var svnOutput = cmd.svn();
```Note that the commands can be case sensitive, and as such `cmd.git` is not same as, say, `cmd.Git`.
**How to set environment variables?**
Environment variables can be set for the process by calling `._Env` method on an instance of Cmd and pass the set of environment variables with their values as a `Dictionary`:
```csharp
cmd._Env(new Dictionary { { "GIT_DIR", @"C:\" } });Note that this replaces existing variables with the new values.
```**Shells**
You can use cmd to run command on, well, cmd and Powershell. Choose the shell you want to use while creating cmd:
```csharp
dynamic cmd = new Cmd(Shell.Cmd);
dynamic posh = new Cmd(Shell.Powershell);
cmd.dir();
```
`cmd.dir()` is equivalent to `cmd /c dir`When using `Shell.Cmd`, flags are constructed using `/` instead of `-` and `--`
Powershell support is still a work in progress.
**What's ahead?**
cmd is in a very nascent stage. More `sh` like goodness coming soon.