Last active
August 29, 2015 14:17
-
-
Save ChrisMissal/7abc8ace31c93252b150 to your computer and use it in GitHub Desktop.
CLI Code Spike – Rethinking how I interact with the command line via C# a little bit. I have some spike code in which all these tests pass. Thoughts?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class CommandResolutionTests | |
{ | |
public void should_resolve_text_to_command() | |
{ | |
"samplecommand".Called<SampleCommand>(); | |
} | |
public void should_call_command_hello() | |
{ | |
"samplecommand hello".Called<SampleCommand>() | |
.Received().Hello(); | |
} | |
public void should_call_command_save_with_file() | |
{ | |
"samplecommand save --file=guybowling.png".Called<SampleCommand>() | |
.Received().Save(Arg.Is<SampleCommand.SaveArgs>(x => x.File == "guybowling.png")); | |
} | |
public void should_call_command_save_with_output() | |
{ | |
"samplecommand save --output=ProfilePic.png".Called<SampleCommand>() | |
.Received().Save(Arg.Is<SampleCommand.SaveArgs>(x => x.Output == "ProfilePic.png")); | |
} | |
} | |
public class SampleCommand | |
{ | |
public virtual string Hello() | |
{ | |
return @"Hello World"; | |
} | |
public virtual void Save(SaveArgs args) | |
{ | |
// do stuff | |
} | |
public class SaveArgs | |
{ | |
public string File { get; set; } | |
public string Output { get; set; } | |
} | |
} |
The idea command line parser solution will have a fluent WebAPI written in F#, running the generated commands through Mass Transit.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
So I got some good feedback that isn't here... I was informed to check out https://github.com/nessos/UnionArgParser, https://github.com/adamabdelhamed/PowerArgs, and https://github.com/DarthFubuMVC/fubucore.
https://twitter.com/jeremydmiller/status/578701601851998208
https://twitter.com/kevm/status/578721206838255616
https://twitter.com/abrussak/status/578748714581282816
https://twitter.com/ChetHusk/status/578758663814279168
Thanks for the feedback so far people!