{"id":13415128,"url":"https://github.com/manojlds/cmd","last_synced_at":"2025-04-04T10:05:35.881Z","repository":{"id":5462803,"uuid":"6657995","full_name":"manojlds/cmd","owner":"manojlds","description":"C# library to run external programs in a simpler way. Demonstration of \"dynamic\" features of C#.","archived":false,"fork":false,"pushed_at":"2020-05-18T17:25:35.000Z","size":1286,"stargazers_count":354,"open_issues_count":4,"forks_count":48,"subscribers_count":37,"default_branch":"master","last_synced_at":"2024-10-11T12:09:16.351Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/manojlds.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-11-12T18:08:26.000Z","updated_at":"2024-09-21T14:50:41.000Z","dependencies_parsed_at":"2022-08-03T16:15:19.861Z","dependency_job_id":null,"html_url":"https://github.com/manojlds/cmd","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/manojlds%2Fcmd","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/manojlds%2Fcmd/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/manojlds%2Fcmd/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/manojlds%2Fcmd/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/manojlds","download_url":"https://codeload.github.com/manojlds/cmd/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247156520,"owners_count":20893199,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-30T21:00:43.767Z","updated_at":"2025-04-04T10:05:35.851Z","avatar_url":"https://github.com/manojlds.png","language":"C#","readme":"# cmd #\n\nA 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#\n\n**How to get it?**\n\nCmd is available through the Nuget Package Manager.\n\nOr, you can build it from source.\n\n**How to use it?**\n\nCreate a dynamic instance of Cmd:\n\n```csharp\ndynamic cmd = new Cmd();\n```\n\nNow, you can call commands off cmd:\n\n```csharp\ncmd.git.clone(\"http://github.com/manojlds/cmd\");\n```\n\nThe above would be equivalent to `git clone http://github.com/manojlds/cmd`.\n\nYou can pass flags by naming the arguments:\n\n```csharp\ncmd.git.log(grep: \"test\");\n```\n\nThe above would be equivalent to `git log --grep test`\n\nOr:\n\n```csharp\ncmd.git.branch(a: true);\n```\n\nwhich would be equivalent to `git branch -a`\n\nNote that single character flags are mapped as `-\u003cflag\u003e` and multi-character ones are mapped as `--\u003cflag\u003e`\n\nAlso, non-string values are ignored and if there is no flag, the argument is not considered.\n\nYou can call multiple commands off the same instance of cmd:\n\n```csharp\nvar gitOutput = cmd.git();\nvar svnOutput = cmd.svn();\n```\n\nNote that the commands can be case sensitive, and as such `cmd.git` is not same as, say, `cmd.Git`.\n\n**How to set environment variables?**\n\nEnvironment 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\u003cstring, string\u003e`:\n\n```csharp\ncmd._Env(new Dictionary\u003cstring, string\u003e { { \"GIT_DIR\", @\"C:\\\" } });\n\nNote that this replaces existing variables with the new values.\n```\n\n**Shells**\n\nYou can use cmd to run command on, well, cmd and Powershell. Choose the shell you want to use while creating cmd:\n\n```csharp\ndynamic cmd = new Cmd(Shell.Cmd);\ndynamic posh = new Cmd(Shell.Powershell);\ncmd.dir();\n```\n`cmd.dir()` is equivalent to `cmd /c dir`\n\nWhen using `Shell.Cmd`, flags are constructed using `/` instead of `-` and `--`\n\nPowershell support is still a work in progress.\n\n**What's ahead?**\n\ncmd is in a very nascent stage. More `sh` like goodness coming soon.\n","funding_links":[],"categories":["DLR","C# #","C#","C\\#"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmanojlds%2Fcmd","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmanojlds%2Fcmd","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmanojlds%2Fcmd/lists"}