Introduction

GoCommando is a small command line utility helper that does the boring work when creating command line utilities in .NET.
Source code and stuff is on Github.
Tell me more
Going commando is as simple as it is liberating – consider this (imaginary) command line utility:
[Banner(@"White Russian Utility Copyright (c) 2010 El Duderino ")] public class Program : ICommando { [PositionalArgument] public string BeverageRecipient { get; set; } [NamedArgument("vodka", "v")] public double AmountOfVodka { get; set; } [NamedArgument("kahlua", "k")] public double AmountOfKahlua { get; set; } [NamedArgument("lukewarm", "lw")] public bool AvoidRefrigeratedIngredients { get; set; } public static void Main(string [] args) { Go.Run<Program>(args); } public void Run() { Console.WriteLine("Making white russian for {0}...", BeverageRecipient); Console.WriteLine("Add {0:0.0} ml of vodka...", AmountOfVodka); Console.WriteLine("Add {0:0.0} ml of Kahlua...", AmountOfKahlua); if (AvoidRefrigeratedIngredients) { Console.WriteLine("Serve lukewarm!"); } Console.WriteLine("Far out, man..."); } } |
allowing a potential usage scenario like this:
C:\DrinkUtils>wr.exe "His Dudeness" -vodka:125 -kahlua:125 -lw White Russian Utility Copyright (c) 2010 El Duderino Making white russian for His Dudeness... Add 125.0 ml of vodka... Add 125.0 ml of Kahlua... Serve lukewarm! Far out, man... |
What was that?
Positional argument: PositionalArgumentAttribute is used to bind the first couple of arguments (if any). As soon as the command line has a named argument, further arguments are assumed to be named.
Positional arguments are bound in the order they appear in the class declaration.
Named argument: NamedArgumentAttribute is used to bind command lines on the form /name:value to a property. Named arguments can have a full name and a shorthand (full name is for n00bs, shorthand is definitely more 1337).
Banner: BannerAttribute is an (optional) attribute that can be used to specify the initial output from the program.
bool: Properties of type bool are assumed to be named value-less flag-type parameters – i.e. either you specify /name on the command line (yielding a value of true), or you don’t (guess what the value is then?)…
…and there’s more!
Description: DescriptionAttribute is used to specify a textual description that will be output when automagically generating a help text for the utility.
Examples: ExampleAttribute can be used to specify one or more examples on acceptable values for that particular parameter.
E.g. like so:
[PositionalArgument] [Description("Specifies to whom the beverage should be delivered"] [Example("Donny"), Example("Walter"), Example("Bunny")] public string BeverageRecipient { get; set; } |
I’m looking into implementing a command line utility. I think GoCommando looks just like the framework I need. How about doing a NuGet package?
Great idea!
I’ll look into it some time in the future when I have the time and HAHA JUST KIDDING, check this out: GoCommando in the NuGet Gallery.
Install-Package GoCommandoand you have been liberated!Great! Thank you very much, Mookid.
By the way, I solved one of the TODO’s in todo.txt. It is now possible to provide a factory methods to the Run-method, which makes it possible to provide your own instance of ICommando. There’s a pull request at GitHub waiting for you.
Pull request has been slightly simplified and merged – thanks
PS:
Update-Package GoCommandoCool dude!