Command-Line Parsing API from TestAPI library - Type-Safe Commands how to

Posted by MicMit on Stack Overflow See other posts from Stack Overflow or by MicMit
Published on 2010-03-31T02:12:38Z Indexed on 2010/03/31 2:23 UTC
Read the original article Hit count: 560

Library at

http://testapi.codeplex.com/

Excerpt of usage from

http://blogs.msdn.com/ivo_manolov/archive/2008/12/17/9230331.aspx

A third common approach is forming strongly-typed commands from the command-line parameters. This is common for cases when the command-line looks as follows:

some-exe  COMMAND  parameters-to-the-command

The parsing in this case is a little bit more involved:

  1. Create one class for every supported command, which derives from the Command abstract base class and implements an expected Execute method.
  2. Pass an expected command along with the command-line arguments to CommandLineParser.ParseCommand – the method will return a strongly-typed Command instance that can be Execute()-d.

    // EXAMPLE #3: // Sample for parsing the following command-line: // Test.exe run /runId=10 /verbose // In this particular case we have an actual command on the command-line (“run”), which we want to effectively de-serialize and execute.

     public class   RunCommand : Command
     { 
     bool?  Verbose { get; set; } 
     int? RunId { get; set; }
     public override void Execute()
        {
       // Implement your "run" execution logic here.
        }
     }
      Command c = new RunCommand();
      CommandLineParser.ParseArguments(c, args);
      c.Execute();
    

============================

I don't get if we instantiate specific class before parsing arguments , what's the point of command line argument "run" which is very first one. I thought the idea was to instantiate and execute command/class based on a command line parameter ( "run" parameter becomes instance RunCommand class, "walk" becomes WalkCommand class and so on ). Can it be done with the latest version ?

© Stack Overflow or respective owner

Related posts about .NET

Related posts about command-line-arguments