• Stars
    star
    352
  • Rank 120,622 (Top 3 %)
  • Language
    C#
  • License
    Apache License 2.0
  • Created about 12 years ago
  • Updated over 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

C# library to run external programs in a simpler way. Demonstration of "dynamic" features of C#.

cmd

A C# Library to run external programs / commands in a simpler way. It is inspired from the 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:

dynamic cmd = new Cmd();

Now, you can call commands off cmd:

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:

cmd.git.log(grep: "test");

The above would be equivalent to git log --grep test

Or:

cmd.git.branch(a: true);

which would be equivalent to git branch -a

Note that single character flags are mapped as -<flag> and multi-character ones are mapped as --<flag>

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:

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<string, string>:

cmd._Env(new Dictionary<string, string> { { "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:

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.

More Repositories

1

pslinq

LINQ (LINQ2Objects) for Powershell
C#
77
star
2

YDeliver

YDeliver is a (opinionated) build and deployment framework aimed at .NET projects.
PowerShell
49
star
3

gocd-docker

Docker build, run and push task plugin for GoCD
Java
38
star
4

ebs-snapshot-lambda

AWS lambda function to snapshot EBS volumes and purge old snapshots.
JavaScript
36
star
5

posz

z implementation for Powershell
PowerShell
32
star
6

redditps

Reddit provider for Powershell
C#
21
star
7

Pit

A git repository provider for Powershell
C#
14
star
8

Todo.ps1

A todo.txt implementation for Powershell
PowerShell
14
star
9

poshmarks

Implementation of bashmarks for Powershell
PowerShell
13
star
10

Toggler

Feature Toggling library for .NET.
C#
10
star
11

gocd-powershell-runner

A Powershell Task runner for gocd (http://www.go.cd)
Java
10
star
12

django-ansible

Ansible repo for a Nginx-gunicorn-postgres based Django stack
Ruby
8
star
13

thepill

Decision Trees with Neo4J
Kotlin
7
star
14

tinymce-image-caption

A simple plugin to add caption to images in tinymce4
JavaScript
6
star
15

hubot-gocd

Hubot script to report build status from GoCD (http://www.go.cd/)
CoffeeScript
5
star
16

EventBase

A single page app for events and conferences
JavaScript
4
star
17

django_ci_example

Sample django project for setting up CI
Python
4
star
18

cdposh

Implementation of cdpath for Powershell
PowerShell
3
star
19

powershell-docker

Powershell in Docker
3
star
20

chennai-devops

Ruby
2
star
21

rails_ci_example

Sample Rails application for CI with TeamCity
Ruby
2
star
22

sketch-ui

A skin over Twitter Bootstrap for UX Designers
CSS
2
star
23

lumenz

Lumenz
JavaScript
1
star
24

loksabha

Web app to display information about Lok Sabha
JavaScript
1
star