├── .gitattributes ├── .gitignore ├── LICENSE ├── README.md ├── build.ps1 ├── build.yml ├── install.ps1 ├── install.yml └── src ├── cmd.UnitTests ├── CmdDSLTests.cs ├── CmdTests.cs ├── Commands │ ├── CmdCommandoTests.cs │ └── CommandoTests.cs ├── Runner │ ├── Arguments │ │ ├── ArgumentBuilderTests.cs │ │ ├── CmdArgumentBuilderTests.cs │ │ └── PowershellArgumentBuilderTests.cs │ └── Shells │ │ ├── CmdShellTests.cs │ │ ├── PowershellDSLTests.cs │ │ └── ShellTests.cs └── cmd.UnitTests.csproj ├── cmd.sln ├── cmd ├── Cmd.cs ├── Commands │ ├── CmdCommando.cs │ ├── Commando.cs │ ├── ICommando.cs │ └── PowershellCommando.cs ├── Properties │ └── AssemblyInfo.cs ├── Runner │ ├── Arguments │ │ ├── Argument.cs │ │ ├── ArgumentBuilder.cs │ │ ├── CmdArgumentBuilder.cs │ │ ├── IArgumentBuilder.cs │ │ └── PowershellArgumentBuilder.cs │ ├── IRunOptions.cs │ ├── IRunner.cs │ ├── RunOptions.cs │ └── Shells │ │ ├── CmdShell.cs │ │ ├── Posh.cs │ │ ├── ProcessRunner.cs │ │ └── Shell.cs └── cmd.csproj └── packages ├── Moq.4.0.10827 ├── License.txt ├── Moq.4.0.10827.nuspec ├── Moq.chm └── lib │ ├── NET35 │ ├── Moq.dll │ └── Moq.xml │ ├── NET40 │ ├── Moq.dll │ └── Moq.xml │ └── Silverlight4 │ ├── Castle.Core.dll │ ├── Moq.Silverlight.dll │ └── Moq.Silverlight.xml ├── NUnit.2.6.2 ├── NUnit.2.6.2.nupkg ├── NUnit.2.6.2.nuspec ├── lib │ ├── nunit.framework.dll │ └── nunit.framework.xml └── license.txt └── repositories.config /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | *.sln merge=union 7 | *.csproj merge=union 8 | *.vbproj merge=union 9 | *.fsproj merge=union 10 | *.dbproj merge=union 11 | 12 | # Standard to msysgit 13 | *.doc diff=astextplain 14 | *.DOC diff=astextplain 15 | *.docx diff=astextplain 16 | *.DOCX diff=astextplain 17 | *.dot diff=astextplain 18 | *.DOT diff=astextplain 19 | *.pdf diff=astextplain 20 | *.PDF diff=astextplain 21 | *.rtf diff=astextplain 22 | *.RTF diff=astextplain 23 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ################# 2 | ## Eclipse 3 | ################# 4 | 5 | *.pydevproject 6 | .project 7 | .metadata 8 | bin/ 9 | tmp/ 10 | *.tmp 11 | *.bak 12 | *.swp 13 | *~.nib 14 | local.properties 15 | .classpath 16 | .settings/ 17 | .loadpath 18 | 19 | # External tool builders 20 | .externalToolBuilders/ 21 | 22 | # Locally stored "Eclipse launch configurations" 23 | *.launch 24 | 25 | # CDT-specific 26 | .cproject 27 | 28 | # PDT-specific 29 | .buildpath 30 | 31 | 32 | ################# 33 | ## Visual Studio 34 | ################# 35 | 36 | ## Ignore Visual Studio temporary files, build results, and 37 | ## files generated by popular Visual Studio add-ons. 38 | 39 | # User-specific files 40 | *.suo 41 | *.user 42 | *.sln.docstates 43 | 44 | # Build results 45 | [Dd]ebug/ 46 | [Rr]elease/ 47 | *.nupkg 48 | *_i.c 49 | *_p.c 50 | *.ilk 51 | *.meta 52 | *.obj 53 | *.pch 54 | *.pdb 55 | *.pgc 56 | *.pgd 57 | *.rsp 58 | *.sbr 59 | *.tlb 60 | *.tli 61 | *.tlh 62 | *.tmp 63 | *.vspscc 64 | .builds 65 | *.dotCover 66 | 67 | ## TODO: If you have NuGet Package Restore enabled, uncomment this 68 | #packages/ 69 | 70 | # Visual C++ cache files 71 | ipch/ 72 | *.aps 73 | *.ncb 74 | *.opensdf 75 | *.sdf 76 | 77 | # Visual Studio profiler 78 | *.psess 79 | *.vsp 80 | 81 | # ReSharper is a .NET coding add-in 82 | _ReSharper* 83 | 84 | # Installshield output folder 85 | [Ee]xpress 86 | 87 | # DocProject is a documentation generator add-in 88 | DocProject/buildhelp/ 89 | DocProject/Help/*.HxT 90 | DocProject/Help/*.HxC 91 | DocProject/Help/*.hhc 92 | DocProject/Help/*.hhk 93 | DocProject/Help/*.hhp 94 | DocProject/Help/Html2 95 | DocProject/Help/html 96 | 97 | # Click-Once directory 98 | publish 99 | 100 | # Others 101 | [Bb]in 102 | [Oo]bj 103 | .vs/ 104 | sql 105 | TestResults 106 | *.Cache 107 | ClientBin 108 | stylecop.* 109 | ~$* 110 | *.dbmdl 111 | Generated_Code #added for RIA/Silverlight projects 112 | 113 | # Backup & report files from converting an old project file to a newer 114 | # Visual Studio version. Backup files are not needed, because we have git ;-) 115 | _UpgradeReport_Files/ 116 | Backup*/ 117 | UpgradeLog*.XML 118 | 119 | 120 | 121 | ############ 122 | ## Windows 123 | ############ 124 | 125 | # Windows image file caches 126 | Thumbs.db 127 | 128 | # Folder config file 129 | Desktop.ini 130 | 131 | 132 | ############# 133 | ## Python 134 | ############# 135 | 136 | *.py[co] 137 | 138 | # Packages 139 | *.egg 140 | *.egg-info 141 | dist 142 | build 143 | eggs 144 | parts 145 | bin 146 | var 147 | sdist 148 | develop-eggs 149 | .installed.cfg 150 | 151 | # Installer logs 152 | pip-log.txt 153 | 154 | # Unit test / coverage reports 155 | .coverage 156 | .tox 157 | 158 | #Translations 159 | *.mo 160 | 161 | #Mr Developer 162 | .mr.developer.cfg 163 | 164 | # Mac crap 165 | .DS_Store 166 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # cmd # 2 | 3 | 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# 4 | 5 | **How to get it?** 6 | 7 | Cmd is available through the Nuget Package Manager. 8 | 9 | Or, you can build it from source. 10 | 11 | **How to use it?** 12 | 13 | Create a dynamic instance of Cmd: 14 | 15 | ```csharp 16 | dynamic cmd = new Cmd(); 17 | ``` 18 | 19 | Now, you can call commands off cmd: 20 | 21 | ```csharp 22 | cmd.git.clone("http://github.com/manojlds/cmd"); 23 | ``` 24 | 25 | The above would be equivalent to `git clone http://github.com/manojlds/cmd`. 26 | 27 | You can pass flags by naming the arguments: 28 | 29 | ```csharp 30 | cmd.git.log(grep: "test"); 31 | ``` 32 | 33 | The above would be equivalent to `git log --grep test` 34 | 35 | Or: 36 | 37 | ```csharp 38 | cmd.git.branch(a: true); 39 | ``` 40 | 41 | which would be equivalent to `git branch -a` 42 | 43 | Note that single character flags are mapped as `-` and multi-character ones are mapped as `--` 44 | 45 | Also, non-string values are ignored and if there is no flag, the argument is not considered. 46 | 47 | You can call multiple commands off the same instance of cmd: 48 | 49 | ```csharp 50 | var gitOutput = cmd.git(); 51 | var svnOutput = cmd.svn(); 52 | ``` 53 | 54 | Note that the commands can be case sensitive, and as such `cmd.git` is not same as, say, `cmd.Git`. 55 | 56 | **How to set environment variables?** 57 | 58 | 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`: 59 | 60 | ```csharp 61 | cmd._Env(new Dictionary { { "GIT_DIR", @"C:\" } }); 62 | 63 | Note that this replaces existing variables with the new values. 64 | ``` 65 | 66 | **Shells** 67 | 68 | You can use cmd to run command on, well, cmd and Powershell. Choose the shell you want to use while creating cmd: 69 | 70 | ```csharp 71 | dynamic cmd = new Cmd(Shell.Cmd); 72 | dynamic posh = new Cmd(Shell.Powershell); 73 | cmd.dir(); 74 | ``` 75 | `cmd.dir()` is equivalent to `cmd /c dir` 76 | 77 | When using `Shell.Cmd`, flags are constructed using `/` instead of `-` and `--` 78 | 79 | Powershell support is still a work in progress. 80 | 81 | **What's ahead?** 82 | 83 | cmd is in a very nascent stage. More `sh` like goodness coming soon. 84 | -------------------------------------------------------------------------------- /build.ps1: -------------------------------------------------------------------------------- 1 | param( 2 | $tasks = @('Clean', 'Compile', 'UnitTests', 'NugetPackage'), 3 | $buildNumber = "1.0.0", 4 | $buildMode = "Release" 5 | ) 6 | 7 | $script:scriptDir = split-path $MyInvocation.MyCommand.Path -parent 8 | 9 | #Import-Module $script:scriptDir\BuildScripts\YDeliver.psm1 10 | Invoke-YBuild $tasks -buildVersion $buildNumber -config @{ "conventions" = @{ "buildMode" = $buildMode } } -------------------------------------------------------------------------------- /build.yml: -------------------------------------------------------------------------------- 1 | nugetSpecs: [cmd.nuspec] 2 | 3 | conventions: 4 | artifactsDir: "$rootDir/build" -------------------------------------------------------------------------------- /install.ps1: -------------------------------------------------------------------------------- 1 | param( 2 | $applications = @("cmd"), 3 | $buildNumber = "1.0.0", 4 | $artifactsDir = "$(pwd)\build" 5 | ) 6 | 7 | trap 8 | { 9 | Write-Error $_ 10 | exit 1 11 | } 12 | 13 | $script:scriptDir = split-path $MyInvocation.MyCommand.Path -parent 14 | 15 | #Import-Module $script:scriptDir\BuildScripts\YDeliver.psm1 16 | Invoke-YInstall $applications -buildVersion $buildNumber -config @{ "conventions" = @{ "artifactsDir" = $artifactsDir } } 17 | -------------------------------------------------------------------------------- /install.yml: -------------------------------------------------------------------------------- 1 | conventions: 2 | artifactsDir: "$rootDir/build" 3 | 4 | install: 5 | cmd: 6 | tasks: 7 | NugetPublish: 8 | config: 9 | #configuration needed to install the application 10 | packages: ["cmd.*.nupkg"] 11 | #source can be local directory path or nuget feed url or nuget source name 12 | source: "C:/packages" -------------------------------------------------------------------------------- /src/cmd.UnitTests/CmdDSLTests.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using Moq; 3 | using cmd.Commands; 4 | using cmd.Runner; 5 | using cmd.Runner.Shells; 6 | using Xunit; 7 | 8 | namespace cmd.UnitTests 9 | { 10 | public class CmdDslTests 11 | { 12 | private dynamic cmd; 13 | private Mock mockRunner; 14 | 15 | public CmdDslTests() 16 | { 17 | mockRunner = new Mock(); 18 | mockRunner.Setup(runner => runner.Run(It.IsAny())).Returns("result"); 19 | mockRunner.Setup(runner => runner.GetCommand()).Returns(new Commando(mockRunner.Object)); 20 | cmd = new Cmd(mockRunner.Object); 21 | } 22 | 23 | [Fact] 24 | public void ShouldBeAbleToCallArbitraryCommandOnCmd() 25 | { 26 | cmd.git(); 27 | } 28 | 29 | [Fact] 30 | public void ShouldBeAbleToCallArbitrarySubCommand() 31 | { 32 | var clone = cmd.git.clone; 33 | } 34 | 35 | [Fact] 36 | public void ShouldBeAbleToExecuteWithSubCommand() 37 | { 38 | cmd.git.Clone(); 39 | } 40 | 41 | [Fact] 42 | public void ShouldBeAbleToPassArgumentsToACommand() 43 | { 44 | cmd.Git.Clone("http://github.com/manojlds/cmd"); 45 | } 46 | 47 | [Fact] 48 | public void ShouldBeAbleToPassFlags() 49 | { 50 | cmd.Git.Pull(r: true); 51 | } 52 | 53 | [Fact] 54 | public void ShouldBeAbleToPassArgumentstoFlags() 55 | { 56 | cmd.Git.Checkout(b: "master"); 57 | } 58 | 59 | [Fact] 60 | public void ShouldBeAbleToPreBuildACommandAndThenExecuteIt() 61 | { 62 | var git = cmd.git; 63 | git.Clone(); 64 | } 65 | 66 | [Fact] 67 | public void ShouldBeAbleToBuildMultipleCommandOnCmd() 68 | { 69 | var git = cmd.git; 70 | var svn = cmd.svn; 71 | } 72 | 73 | [Fact] 74 | public void ShouldBeAbleToRunMultipleCommandOnCmd() 75 | { 76 | cmd.git(); 77 | cmd.svn(); 78 | } 79 | 80 | [Fact] 81 | public void ShouldBeAbleToChooseADifferentShell() 82 | { 83 | dynamic cmd = new Cmd(Shell.Cmd); 84 | } 85 | 86 | [Fact] 87 | public void ShouldBeAbleToSetEnvironmentVariables() 88 | { 89 | cmd._Env(new Dictionary { { "PATH", @"C:\" } }); 90 | } 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /src/cmd.UnitTests/CmdTests.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using Moq; 3 | using cmd.Commands; 4 | using cmd.Runner; 5 | using Xunit; 6 | 7 | namespace cmd.UnitTests 8 | { 9 | public class CmdTests 10 | { 11 | private dynamic cmd; 12 | private Mock mockRunner; 13 | 14 | public CmdTests() 15 | { 16 | mockRunner = new Mock(); 17 | mockRunner.Setup(runner => runner.GetCommand()).Returns(new Commando(mockRunner.Object)); 18 | cmd = new Cmd(mockRunner.Object); 19 | } 20 | 21 | [Fact] 22 | public void ShouldBeAbleToBuildACommandAsProperty() 23 | { 24 | var commando = cmd.git; 25 | 26 | Assert.NotNull(commando); 27 | } 28 | 29 | [Fact] 30 | public void ShouldCreateCommandWithRunner() 31 | { 32 | cmd.git(); 33 | 34 | mockRunner.Verify(runner => runner.Run(It.IsAny()), Times.Once()); 35 | } 36 | 37 | [Fact] 38 | public void ShouldBeAbleToBuildMultipleCommandsOnCmd() 39 | { 40 | mockRunner.Setup(runner => runner.GetCommand()).Returns(new Commando(mockRunner.Object)); 41 | var git = cmd.git; 42 | mockRunner.Setup(runner => runner.GetCommand()).Returns(new Commando(mockRunner.Object)); 43 | var svn = cmd.svn; 44 | 45 | Assert.NotEqual(svn, git); 46 | } 47 | 48 | [Fact] 49 | public void ShouldBeAbleToRunMultipleCommandsOnCmd() 50 | { 51 | mockRunner.Setup(runner => runner.GetCommand()).Returns(new Commando(mockRunner.Object)); 52 | cmd.git(); 53 | mockRunner.Setup(runner => runner.GetCommand()).Returns(new Commando(mockRunner.Object)); 54 | cmd.svn(); 55 | 56 | mockRunner.Verify(runner => runner.Run(It.Is(options => options.Command == "git")), Times.Once()); 57 | mockRunner.Verify(runner => runner.Run(It.Is(options => options.Command == "svn")), Times.Once()); 58 | } 59 | 60 | [Fact] 61 | public void ShouldBeAbleToSetEnvironmentVariablesOnCmd() 62 | { 63 | var environmentDictionary = new Dictionary { { "PATH", @"C:\" } }; 64 | cmd._Env(environmentDictionary); 65 | 66 | mockRunner.VerifySet(runner => runner.EnvironmentVariables = environmentDictionary); 67 | } 68 | } 69 | } -------------------------------------------------------------------------------- /src/cmd.UnitTests/Commands/CmdCommandoTests.cs: -------------------------------------------------------------------------------- 1 | using Moq; 2 | using cmd.Commands; 3 | using cmd.Runner; 4 | using Xunit; 5 | 6 | namespace cmd.UnitTests.Commands 7 | { 8 | public class CmdCommandoTests 9 | { 10 | private Mock mockRunner; 11 | private dynamic cmd; 12 | 13 | public CmdCommandoTests() 14 | { 15 | mockRunner = new Mock(); 16 | mockRunner.Setup(runner => runner.GetCommand()).Returns(new CmdCommando(mockRunner.Object)); 17 | cmd = new Cmd(mockRunner.Object); 18 | } 19 | 20 | [Fact] 21 | public void ShouldRunTheCommandAgainstCmd() 22 | { 23 | IRunOptions expectedRunOptions = null; 24 | mockRunner.Setup(runner => runner.Run(It.IsAny())).Callback(options => 25 | { 26 | expectedRunOptions 27 | = options; 28 | }); 29 | 30 | cmd.dir(); 31 | 32 | Assert.Equal("cmd", expectedRunOptions.Command); 33 | Assert.Equal("/c dir", expectedRunOptions.Arguments); 34 | } 35 | } 36 | } -------------------------------------------------------------------------------- /src/cmd.UnitTests/Commands/CommandoTests.cs: -------------------------------------------------------------------------------- 1 | using Moq; 2 | using cmd.Commands; 3 | using cmd.Runner; 4 | using cmd.Runner.Arguments; 5 | using Xunit; 6 | 7 | namespace cmd.UnitTests.Commands 8 | { 9 | public class CommandoTests 10 | { 11 | private Mock mockRunner; 12 | private dynamic cmd; 13 | 14 | public CommandoTests() 15 | { 16 | mockRunner = new Mock(); 17 | mockRunner.Setup(runner => runner.GetCommand()).Returns(new Commando(mockRunner.Object)); 18 | cmd = new Cmd(mockRunner.Object); 19 | } 20 | 21 | [Fact] 22 | public void ShouldBeAbleToBuildACommand() 23 | { 24 | var command = cmd.git; 25 | } 26 | 27 | [Fact] 28 | public void ShouldBeAbleToRunACommand() 29 | { 30 | cmd.git(); 31 | 32 | mockRunner.Verify(runner => 33 | runner.Run(It.Is(options => options.Command == "git" && options.Arguments == string.Empty)), Times.Once()); 34 | } 35 | 36 | [Fact] 37 | public void ShouldBeAbleToGetOutputFromCommand() 38 | { 39 | mockRunner.Setup(runner => runner.Run(It.IsAny())).Returns("out"); 40 | 41 | var output = cmd.git(); 42 | 43 | Assert.Equal("out", output); 44 | 45 | } 46 | 47 | [Fact] 48 | public void ShouldBeAbleToBuildSubCommands() 49 | { 50 | var command = cmd.git.clone; 51 | } 52 | 53 | [Fact] 54 | public void ShouldBeAbleToRunWithSubCommand() 55 | { 56 | IRunOptions expectedRunOptions = null; 57 | mockRunner.Setup(runner => runner.Run(It.IsAny())).Callback(options => 58 | { 59 | expectedRunOptions 60 | = options; 61 | }); 62 | 63 | cmd.git.clone(); 64 | 65 | Assert.NotNull(expectedRunOptions); 66 | Assert.Equal("git", expectedRunOptions.Command); 67 | Assert.Equal("clone", expectedRunOptions.Arguments); 68 | } 69 | 70 | [Fact] 71 | public void ShouldBeAbleToRunWithArgumentsOnCommand() 72 | { 73 | const string Argument = "--help"; 74 | IRunOptions expectedRunOptions = null; 75 | mockRunner.Setup(runner => runner.BuildArgument(It.IsAny())).Returns(Argument); 76 | mockRunner.Setup(runner => runner.Run(It.IsAny())).Callback(options => 77 | { 78 | expectedRunOptions 79 | = options; 80 | }); 81 | 82 | cmd.git(help: true); 83 | 84 | Assert.NotNull(expectedRunOptions); 85 | Assert.Equal("git", expectedRunOptions.Command); 86 | Assert.Equal(Argument, expectedRunOptions.Arguments); 87 | } 88 | 89 | [Fact] 90 | public void ShouldBeAbleToRunWithArgumentsOnSubCommand() 91 | { 92 | const string Argument = "https://github.com/manojlds/cmd"; 93 | IRunOptions expectedRunOptions = null; 94 | mockRunner.Setup(runner => runner.BuildArgument(It.IsAny())) 95 | .Returns(Argument); 96 | mockRunner.Setup(runner => runner.Run(It.IsAny())).Callback(options => 97 | { 98 | expectedRunOptions 99 | = options; 100 | }); 101 | 102 | cmd.git.clone(Argument); 103 | 104 | Assert.NotNull(expectedRunOptions); 105 | Assert.Equal("git", expectedRunOptions.Command); 106 | Assert.Equal(string.Concat("clone ", Argument), expectedRunOptions.Arguments); 107 | } 108 | 109 | [Fact(Skip = "Not implemented")] 110 | public void ShouldBeAbleToCallMultipleCommandsWithPreBuiltCommando() 111 | { 112 | IRunOptions branchRunOptions = null; 113 | mockRunner.Setup(runner => runner.Run(It.Is(options => options.Arguments.StartsWith("branch")))).Callback(options => 114 | { 115 | branchRunOptions 116 | = options; 117 | }); 118 | 119 | IRunOptions cloneRunOptions = null; 120 | mockRunner.Setup(runner => runner.Run(It.Is(options => options.Arguments.StartsWith("clone")))).Callback(options => 121 | { 122 | cloneRunOptions 123 | = options; 124 | }); 125 | 126 | var git = cmd.git; 127 | git.Clone(); 128 | git.branch(async: true); 129 | 130 | Assert.NotNull(branchRunOptions); 131 | Assert.NotNull(cloneRunOptions); 132 | } 133 | } 134 | } 135 | -------------------------------------------------------------------------------- /src/cmd.UnitTests/Runner/Arguments/ArgumentBuilderTests.cs: -------------------------------------------------------------------------------- 1 | using cmd.Runner.Arguments; 2 | using Xunit; 3 | 4 | namespace cmd.UnitTests.Runner.Arguments 5 | { 6 | public class ArgumentBuilderTests 7 | { 8 | private IArgumentBuilder argumentBuilder; 9 | 10 | public ArgumentBuilderTests() 11 | { 12 | argumentBuilder = new ArgumentBuilder(); 13 | } 14 | 15 | [Fact] 16 | public void ShouldSetFlagWithSingleHyphenIfOneCharacterFlag() 17 | { 18 | var argument = new Argument("f", null); 19 | 20 | var builtArgument = argumentBuilder.Build(argument); 21 | 22 | Assert.Equal("-f", builtArgument); 23 | } 24 | 25 | [Fact] 26 | public void ShouldSetFlagWithDoubleHyphenIfMultisCharacterFlag() 27 | { 28 | var argument = new Argument("f1", null); 29 | 30 | var builtArgument = argumentBuilder.Build(argument); 31 | 32 | Assert.Equal("--f1", builtArgument); 33 | } 34 | 35 | [Fact] 36 | public void ShouldOnlyUseValueIfNoFlagSpecifiedForArgument() 37 | { 38 | var argument = new Argument(null, "val"); 39 | 40 | var builtArgument = argumentBuilder.Build(argument); 41 | 42 | Assert.Equal("val", builtArgument); 43 | } 44 | 45 | [Fact] 46 | public void ShouldOnlyUseTheFlagIfValueIsNotAString() 47 | { 48 | var argument = new Argument("flag", true); 49 | 50 | var builtArgument = argumentBuilder.Build(argument); 51 | 52 | Assert.Equal("--flag", builtArgument); 53 | } 54 | 55 | [Fact] 56 | public void ShouldUseBothFlagAndValueIfValueIsString() 57 | { 58 | var argument = new Argument("flag", "val"); 59 | 60 | var builtArgument = argumentBuilder.Build(argument); 61 | 62 | Assert.Equal("--flag val", builtArgument); 63 | } 64 | 65 | [Fact] 66 | public void ShouldBeNullIfFlagAndValueAreNull() 67 | { 68 | var argument = new Argument(null, null); 69 | 70 | var builtArgument = argumentBuilder.Build(argument); 71 | 72 | Assert.Null(builtArgument); 73 | } 74 | 75 | [Fact] 76 | public void ShouldBeNullIfFlagIsNullAndValueIsNotString() 77 | { 78 | var argument = new Argument(null, new object()); 79 | 80 | var builtArgument = argumentBuilder.Build(argument); 81 | 82 | Assert.Null(builtArgument); 83 | } 84 | } 85 | } -------------------------------------------------------------------------------- /src/cmd.UnitTests/Runner/Arguments/CmdArgumentBuilderTests.cs: -------------------------------------------------------------------------------- 1 | using cmd.Runner.Arguments; 2 | using Xunit; 3 | 4 | namespace cmd.UnitTests.Runner.Arguments 5 | { 6 | public class CmdArgumentBuilderTests 7 | { 8 | private IArgumentBuilder argumentBuilder; 9 | 10 | public CmdArgumentBuilderTests() 11 | { 12 | argumentBuilder = new CmdArgumentBuilder(); 13 | } 14 | 15 | [Fact] 16 | public void ShouldSetFlagWithForwardSlash() 17 | { 18 | var argument = new Argument("f", null); 19 | 20 | var builtArgument = argumentBuilder.Build(argument); 21 | 22 | Assert.Equal("/f", builtArgument); 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /src/cmd.UnitTests/Runner/Arguments/PowershellArgumentBuilderTests.cs: -------------------------------------------------------------------------------- 1 | using cmd.Runner.Arguments; 2 | using Xunit; 3 | 4 | namespace cmd.UnitTests.Runner.Arguments 5 | { 6 | public class PowershellArgumentBuilderTests 7 | { 8 | private IArgumentBuilder argumentBuilder; 9 | 10 | public PowershellArgumentBuilderTests() 11 | { 12 | argumentBuilder = new PowershellArgumentBuilder(); 13 | } 14 | 15 | [Fact] 16 | public void ShouldSetSwitchFlag() 17 | { 18 | var argument = new Argument("Force", null); 19 | 20 | var builtArgument = argumentBuilder.Build(argument); 21 | 22 | Assert.Equal("-Force", builtArgument); 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /src/cmd.UnitTests/Runner/Shells/CmdShellTests.cs: -------------------------------------------------------------------------------- 1 | namespace cmd.UnitTests.Runner.Shells 2 | { 3 | public class CmdShellTests 4 | { 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /src/cmd.UnitTests/Runner/Shells/PowershellDSLTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using Moq; 6 | using cmd.Commands; 7 | using cmd.Runner; 8 | using Xunit; 9 | 10 | namespace cmd.UnitTests.Runner.Shells 11 | { 12 | public class PowershellDSLTests 13 | { 14 | private dynamic cmd; 15 | private Mock mockRunner; 16 | 17 | public PowershellDSLTests() 18 | { 19 | mockRunner = new Mock(); 20 | mockRunner.Setup(runner => runner.Run(It.IsAny())).Returns("result"); 21 | mockRunner.Setup(runner => runner.GetCommand()).Returns(new Commando(mockRunner.Object)); 22 | cmd = new Cmd(mockRunner.Object); 23 | } 24 | 25 | [Fact] 26 | public void ShouldInvokeACmdlet() 27 | { 28 | cmd.Write.Host(); 29 | } 30 | 31 | [Fact] 32 | public void ShouldInvokeACmdletWithArgument() 33 | { 34 | cmd.Write.Host("test"); 35 | } 36 | 37 | [Fact] 38 | public void ShouldInvokeACmdletWithParameter() 39 | { 40 | cmd.Write.Host(Object: "test"); 41 | } 42 | 43 | [Fact] 44 | public void ShouldInvokeACmdletWithSwitchFlag() 45 | { 46 | cmd.Write.Host(NoNewLine: true); 47 | } 48 | } 49 | } -------------------------------------------------------------------------------- /src/cmd.UnitTests/Runner/Shells/ShellTests.cs: -------------------------------------------------------------------------------- 1 | using cmd.Runner.Shells; 2 | using Xunit; 3 | 4 | namespace cmd.UnitTests.Runner.Shells 5 | { 6 | public class ShellTests 7 | { 8 | [Fact] 9 | public void ShouldReturnAProcessRunnerAsDEfaul() 10 | { 11 | Assert.IsAssignableFrom(Shell.Default); 12 | } 13 | 14 | [Fact] 15 | public void ShouldReturnACmdShellRunner() 16 | { 17 | Assert.IsAssignableFrom(Shell.Cmd); 18 | } 19 | 20 | [Fact] 21 | public void ShouldReturnAPowerShellRunner() 22 | { 23 | Assert.IsAssignableFrom(Shell.Powershell); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/cmd.UnitTests/cmd.UnitTests.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp2.0 5 | 6 | false 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /src/cmd.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.26730.10 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "cmd", "cmd\cmd.csproj", "{DC8C0061-E246-4A23-84F6-1066F4FC99E5}" 7 | EndProject 8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "cmd.UnitTests", "cmd.UnitTests\cmd.UnitTests.csproj", "{6BFC548E-281A-45CB-90E3-B3D757B03D49}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|Any CPU = Debug|Any CPU 13 | Release|Any CPU = Release|Any CPU 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {DC8C0061-E246-4A23-84F6-1066F4FC99E5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 17 | {DC8C0061-E246-4A23-84F6-1066F4FC99E5}.Debug|Any CPU.Build.0 = Debug|Any CPU 18 | {DC8C0061-E246-4A23-84F6-1066F4FC99E5}.Release|Any CPU.ActiveCfg = Release|Any CPU 19 | {DC8C0061-E246-4A23-84F6-1066F4FC99E5}.Release|Any CPU.Build.0 = Release|Any CPU 20 | {6BFC548E-281A-45CB-90E3-B3D757B03D49}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 21 | {6BFC548E-281A-45CB-90E3-B3D757B03D49}.Debug|Any CPU.Build.0 = Debug|Any CPU 22 | {6BFC548E-281A-45CB-90E3-B3D757B03D49}.Release|Any CPU.ActiveCfg = Release|Any CPU 23 | {6BFC548E-281A-45CB-90E3-B3D757B03D49}.Release|Any CPU.Build.0 = Release|Any CPU 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {168435AD-4301-404C-9E13-C00FD04FFB6A} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /src/cmd/Cmd.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Dynamic; 3 | using cmd.Runner; 4 | using cmd.Runner.Shells; 5 | 6 | namespace cmd 7 | { 8 | public class Cmd : DynamicObject 9 | { 10 | private IRunner Runner { get; set; } 11 | 12 | public Cmd(IRunner runner = null) 13 | { 14 | Runner = runner ?? Shell.Default; 15 | } 16 | 17 | public override bool TryGetMember(GetMemberBinder binder, out object result) 18 | { 19 | var commando = Runner.GetCommand(); 20 | commando.AddCommand(binder.Name); 21 | result = commando; 22 | return true; 23 | } 24 | 25 | public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, out object result) 26 | { 27 | result = null; 28 | if (binder.Name == "_Env") 29 | { 30 | if (args.Length != 1) return false; 31 | 32 | Runner.EnvironmentVariables = (Dictionary)args[0]; 33 | return true; 34 | } 35 | 36 | return false; 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/cmd/Commands/CmdCommando.cs: -------------------------------------------------------------------------------- 1 | using cmd.Runner; 2 | 3 | namespace cmd.Commands 4 | { 5 | internal class CmdCommando : Commando 6 | { 7 | public CmdCommando(IRunner runner) : base(runner) 8 | { 9 | commands.Add("cmd"); 10 | commands.Add("/c"); 11 | } 12 | } 13 | } -------------------------------------------------------------------------------- /src/cmd/Commands/Commando.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Dynamic; 3 | using System.Linq; 4 | using cmd.Runner; 5 | using cmd.Runner.Arguments; 6 | using cmd.Runner.Shells; 7 | 8 | namespace cmd.Commands 9 | { 10 | internal class Commando : DynamicObject, ICommando 11 | { 12 | protected readonly List commands = new List(); 13 | protected readonly List arguments = new List(); 14 | 15 | protected IRunner Runner { get; set; } 16 | 17 | public Commando(IRunner runner = null) 18 | { 19 | Runner = runner ?? new ProcessRunner(); 20 | } 21 | 22 | public virtual string Command 23 | { 24 | get { return commands.First(); } 25 | } 26 | 27 | public string Arguments 28 | { 29 | get { 30 | return string.Join(" ", commands.Skip(1) 31 | .Concat(arguments.Select(argument => Runner.BuildArgument(argument)) 32 | .Where(s => !string.IsNullOrEmpty(s)))); 33 | } 34 | } 35 | 36 | public void AddCommand(string command) 37 | { 38 | commands.Add(command); 39 | } 40 | 41 | public override bool TryGetMember(GetMemberBinder binder, out object result) 42 | { 43 | AddCommand(binder.Name); 44 | result = this; 45 | return true; 46 | } 47 | 48 | public override bool TryInvoke(InvokeBinder binder, object[] args, out object result) 49 | { 50 | var names = binder.CallInfo.ArgumentNames; 51 | var numberOfArguments = binder.CallInfo.ArgumentCount; 52 | var numberOfNames = names.Count; 53 | 54 | var allNames = Enumerable.Repeat(null, numberOfArguments - numberOfNames).Concat(names); 55 | arguments.AddRange(allNames.Zip(args, (flag, value) => new Argument(flag, value))); 56 | 57 | var runOptions = new RunOptions(this); 58 | result = Runner.Run(runOptions); 59 | return true; 60 | } 61 | } 62 | } -------------------------------------------------------------------------------- /src/cmd/Commands/ICommando.cs: -------------------------------------------------------------------------------- 1 | namespace cmd.Commands 2 | { 3 | public interface ICommando 4 | { 5 | string Command { get; } 6 | string Arguments { get; } 7 | void AddCommand(string command); 8 | } 9 | } -------------------------------------------------------------------------------- /src/cmd/Commands/PowershellCommando.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Dynamic; 3 | using System.Runtime.Serialization.Formatters.Binary; 4 | 5 | namespace cmd.Commands 6 | { 7 | public class PowershellCommando : DynamicObject, ICommando 8 | { 9 | public string Command { get; private set; } 10 | public string Arguments { get; private set; } 11 | public void AddCommand(string command) 12 | { 13 | throw new System.NotImplementedException(); 14 | } 15 | } 16 | 17 | } -------------------------------------------------------------------------------- /src/cmd/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | 4 | [assembly: AssemblyCopyright("Copyright © 2012")] 5 | [assembly: AssemblyTrademark("")] 6 | [assembly: AssemblyCulture("")] 7 | [assembly: InternalsVisibleTo("cmd.UnitTests")] -------------------------------------------------------------------------------- /src/cmd/Runner/Arguments/Argument.cs: -------------------------------------------------------------------------------- 1 | namespace cmd.Runner.Arguments 2 | { 3 | public class Argument 4 | { 5 | public Argument(string flag, object value) 6 | { 7 | Flag = flag; 8 | string tmp = value as string; 9 | if (tmp != null) 10 | { 11 | Value = System.Environment.ExpandEnvironmentVariables(tmp); 12 | } 13 | 14 | } 15 | 16 | public Argument(object value) : this(null, value) 17 | { 18 | } 19 | 20 | public string Flag { get; private set; } 21 | 22 | public string Value { get; private set; } 23 | } 24 | } -------------------------------------------------------------------------------- /src/cmd/Runner/Arguments/ArgumentBuilder.cs: -------------------------------------------------------------------------------- 1 | namespace cmd.Runner.Arguments 2 | { 3 | internal class ArgumentBuilder : IArgumentBuilder 4 | { 5 | public string Build(Argument argument) 6 | { 7 | var flag = BuildFlag(argument); 8 | 9 | if (string.IsNullOrEmpty(flag) && string.IsNullOrEmpty(argument.Value)) return null; 10 | if (string.IsNullOrEmpty(flag)) return argument.Value; 11 | return string.IsNullOrEmpty(argument.Value) ? flag : string.Format("{0} {1}", flag, argument.Value); 12 | } 13 | 14 | protected virtual string BuildFlag(Argument argument) 15 | { 16 | if (argument.Flag == null) return null; 17 | var prefix = argument.Flag.Length == 1 ? "-" : "--"; 18 | return string.Format("{0}{1}", prefix, argument.Flag); 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /src/cmd/Runner/Arguments/CmdArgumentBuilder.cs: -------------------------------------------------------------------------------- 1 | namespace cmd.Runner.Arguments 2 | { 3 | internal class CmdArgumentBuilder : ArgumentBuilder 4 | { 5 | protected override string BuildFlag(Argument argument) 6 | { 7 | return argument.Flag == null ? null : string.Format("/{0}", argument.Flag); 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/cmd/Runner/Arguments/IArgumentBuilder.cs: -------------------------------------------------------------------------------- 1 | namespace cmd.Runner.Arguments 2 | { 3 | internal interface IArgumentBuilder 4 | { 5 | string Build(Argument argument); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /src/cmd/Runner/Arguments/PowershellArgumentBuilder.cs: -------------------------------------------------------------------------------- 1 | namespace cmd.Runner.Arguments 2 | { 3 | internal class PowershellArgumentBuilder : ArgumentBuilder 4 | { 5 | protected override string BuildFlag(Argument argument) 6 | { 7 | return argument.Flag == null ? null : string.Format("-{0}", argument.Flag); 8 | } 9 | } 10 | } -------------------------------------------------------------------------------- /src/cmd/Runner/IRunOptions.cs: -------------------------------------------------------------------------------- 1 | namespace cmd.Runner 2 | { 3 | public interface IRunOptions 4 | { 5 | string Command { get; set; } 6 | string Arguments { get; set; } 7 | } 8 | } -------------------------------------------------------------------------------- /src/cmd/Runner/IRunner.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using cmd.Commands; 3 | 4 | namespace cmd.Runner 5 | { 6 | public interface IRunner 7 | { 8 | string Run(IRunOptions runOptions); 9 | string BuildArgument(Arguments.Argument argument); 10 | IDictionary EnvironmentVariables { get; set; } 11 | ICommando GetCommand(); 12 | } 13 | } -------------------------------------------------------------------------------- /src/cmd/Runner/RunOptions.cs: -------------------------------------------------------------------------------- 1 | using cmd.Commands; 2 | 3 | namespace cmd.Runner 4 | { 5 | internal class RunOptions : IRunOptions 6 | { 7 | public RunOptions(ICommando commando) 8 | { 9 | Command = commando.Command; 10 | Arguments = commando.Arguments; 11 | } 12 | 13 | public string Command { get; set; } 14 | public string Arguments { get; set; } 15 | } 16 | } -------------------------------------------------------------------------------- /src/cmd/Runner/Shells/CmdShell.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using cmd.Commands; 3 | using cmd.Runner.Arguments; 4 | 5 | namespace cmd.Runner.Shells 6 | { 7 | internal class CmdShell : ProcessRunner 8 | { 9 | private readonly Lazy argumentBuilder = new Lazy(() => new CmdArgumentBuilder()); 10 | 11 | protected override IArgumentBuilder ArgumentBuilder 12 | { 13 | get { return argumentBuilder.Value; } 14 | } 15 | 16 | public override ICommando GetCommand() 17 | { 18 | return new CmdCommando(this); 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /src/cmd/Runner/Shells/Posh.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using cmd.Commands; 3 | using cmd.Runner.Arguments; 4 | 5 | namespace cmd.Runner.Shells 6 | { 7 | internal class Posh : IRunner 8 | { 9 | public string Run(IRunOptions runOptions) 10 | { 11 | return new ProcessRunner().Run(runOptions); 12 | } 13 | 14 | public string BuildArgument(Argument argument) 15 | { 16 | throw new System.NotImplementedException(); 17 | } 18 | 19 | public IDictionary EnvironmentVariables { get; set; } 20 | 21 | public ICommando GetCommand() 22 | { 23 | throw new System.NotImplementedException(); 24 | } 25 | 26 | public IArgumentBuilder ArgumentBuilder { get; protected set; } 27 | } 28 | } -------------------------------------------------------------------------------- /src/cmd/Runner/Shells/ProcessRunner.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics; 4 | using cmd.Commands; 5 | using cmd.Runner.Arguments; 6 | 7 | namespace cmd.Runner.Shells 8 | { 9 | internal class ProcessRunner : IRunner 10 | { 11 | private readonly Lazy _argumentBuilder = new Lazy(() => new ArgumentBuilder()); 12 | 13 | protected virtual IArgumentBuilder ArgumentBuilder 14 | { 15 | get { return _argumentBuilder.Value; } 16 | } 17 | 18 | public string BuildArgument(Argument argument) 19 | { 20 | return ArgumentBuilder.Build(argument); 21 | } 22 | 23 | public IDictionary EnvironmentVariables { get; set; } 24 | 25 | public virtual ICommando GetCommand() 26 | { 27 | return new Commando(this); 28 | } 29 | 30 | public virtual string Run(IRunOptions runOptions) 31 | { 32 | var process = new Process 33 | { 34 | StartInfo = 35 | { 36 | FileName = runOptions.Command, 37 | Arguments = runOptions.Arguments, 38 | UseShellExecute = false, 39 | RedirectStandardOutput = true, 40 | } 41 | }; 42 | PopulateEnvironment(process); 43 | 44 | process.Start(); 45 | var output = process.StandardOutput.ReadToEnd(); 46 | process.WaitForExit(); 47 | 48 | return output; 49 | } 50 | 51 | private void PopulateEnvironment(Process process) 52 | { 53 | foreach (var variable in EnvironmentVariables) 54 | { 55 | process.StartInfo.EnvironmentVariables[variable.Key] = variable.Value; 56 | } 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/cmd/Runner/Shells/Shell.cs: -------------------------------------------------------------------------------- 1 | namespace cmd.Runner.Shells 2 | { 3 | public abstract class Shell 4 | { 5 | public static IRunner Default = new ProcessRunner(); 6 | public static IRunner Cmd = new CmdShell(); 7 | public static IRunner Powershell = new Posh(); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/cmd/cmd.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0;net40 5 | cmd 6 | 0.3.0 7 | manojlds 8 | manojlds 9 | C# library to run external programs in a saner manner 10 | Inititial preview 11 | cmd external program process commandline exec 12 | https://github.com/manojlds/cmd 13 | https://github.com/manojlds/cmd 14 | https://github.com/manojlds/cmd 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /src/packages/Moq.4.0.10827/License.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD 2 | http://code.google.com/p/moq/ 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, 6 | with or without modification, are permitted provided 7 | that the following conditions are met: 8 | 9 | * Redistributions of source code must retain the 10 | above copyright notice, this list of conditions and 11 | the following disclaimer. 12 | 13 | * Redistributions in binary form must reproduce 14 | the above copyright notice, this list of conditions 15 | and the following disclaimer in the documentation 16 | and/or other materials provided with the distribution. 17 | 18 | * Neither the name of Clarius Consulting, Manas Technology Solutions or InSTEDD nor the 19 | names of its contributors may be used to endorse 20 | or promote products derived from this software 21 | without specific prior written permission. 22 | 23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 24 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 25 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 26 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 28 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 30 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 31 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 32 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 33 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 34 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 35 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 36 | SUCH DAMAGE. 37 | 38 | [This is the BSD license, see 39 | http://www.opensource.org/licenses/bsd-license.php] -------------------------------------------------------------------------------- /src/packages/Moq.4.0.10827/Moq.4.0.10827.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Moq 5 | 4.0.10827 6 | Moq 7 | Daniel Cazzulino 8 | Daniel Cazzulino 9 | http://www.opensource.org/licenses/bsd-license.php 10 | http://moq.me/ 11 | http://code.google.com/p/moq/logo?cct=1288040343 12 | false 13 | The simplest mocking library for .NET 3.5/4.0 and Silverlight with deep C# 3.0 integration. 14 | The simplest mocking library for .NET 3.5/4.0 and Silverlight with deep C# 3.0 integration. 15 | Copyright (c) 2007. Clarius Consulting, Manas Technology Solutions, InSTEDD 16 | tdd mocking mocks unittesting 17 | 18 | -------------------------------------------------------------------------------- /src/packages/Moq.4.0.10827/Moq.chm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manojlds/cmd/877d9ac62123ab4f2a57114760f778fa24b316d6/src/packages/Moq.4.0.10827/Moq.chm -------------------------------------------------------------------------------- /src/packages/Moq.4.0.10827/lib/NET35/Moq.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manojlds/cmd/877d9ac62123ab4f2a57114760f778fa24b316d6/src/packages/Moq.4.0.10827/lib/NET35/Moq.dll -------------------------------------------------------------------------------- /src/packages/Moq.4.0.10827/lib/NET40/Moq.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manojlds/cmd/877d9ac62123ab4f2a57114760f778fa24b316d6/src/packages/Moq.4.0.10827/lib/NET40/Moq.dll -------------------------------------------------------------------------------- /src/packages/Moq.4.0.10827/lib/Silverlight4/Castle.Core.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manojlds/cmd/877d9ac62123ab4f2a57114760f778fa24b316d6/src/packages/Moq.4.0.10827/lib/Silverlight4/Castle.Core.dll -------------------------------------------------------------------------------- /src/packages/Moq.4.0.10827/lib/Silverlight4/Moq.Silverlight.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manojlds/cmd/877d9ac62123ab4f2a57114760f778fa24b316d6/src/packages/Moq.4.0.10827/lib/Silverlight4/Moq.Silverlight.dll -------------------------------------------------------------------------------- /src/packages/NUnit.2.6.2/NUnit.2.6.2.nupkg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manojlds/cmd/877d9ac62123ab4f2a57114760f778fa24b316d6/src/packages/NUnit.2.6.2/NUnit.2.6.2.nupkg -------------------------------------------------------------------------------- /src/packages/NUnit.2.6.2/NUnit.2.6.2.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | NUnit 5 | 2.6.2 6 | NUnit 7 | Charlie Poole 8 | Charlie Poole 9 | http://nunit.org/nuget/license.html 10 | http://nunit.org/ 11 | http://nunit.org/nuget/nunit_32x32.png 12 | false 13 | NUnit features a fluent assert syntax, parameterized, generic and theory tests and is user-extensible. A number of runners, both from the NUnit project and by third parties, are able to execute NUnit tests. 14 | 15 | Version 2.6 is the seventh major release of this well-known and well-tested programming tool. 16 | 17 | This package includes only the framework assembly. You will need to install the NUnit.Runners package unless you are using a third-party runner. 18 | NUnit is a unit-testing framework for all .Net languages with a strong TDD focus. 19 | Version 2.6 is the seventh major release of NUnit. 20 | 21 | Unlike earlier versions, this package includes only the framework assembly. You will need to install the NUnit.Runners package unless you are using a third-party runner. 22 | 23 | The nunit.mocks assembly is now provided by the NUnit.Mocks package. The pnunit.framework assembly is provided by the pNUnit package. 24 | en-US 25 | test testing tdd framework fluent assert theory plugin addin 26 | 27 | -------------------------------------------------------------------------------- /src/packages/NUnit.2.6.2/lib/nunit.framework.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manojlds/cmd/877d9ac62123ab4f2a57114760f778fa24b316d6/src/packages/NUnit.2.6.2/lib/nunit.framework.dll -------------------------------------------------------------------------------- /src/packages/NUnit.2.6.2/license.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manojlds/cmd/877d9ac62123ab4f2a57114760f778fa24b316d6/src/packages/NUnit.2.6.2/license.txt -------------------------------------------------------------------------------- /src/packages/repositories.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | --------------------------------------------------------------------------------