Wednesday, November 5, 2008

A fast and easy console shell - Part 2

In part one I talked about how to build a fast and easy console shell. In part two, I want to talk about how to handle parameters that are passed in the command (well not passed in). Using this type of shell, I see no reason why parameters need to be passed in with the command. For example, the command “Start service ‘servername’”. The runtime needs to find where the base command ends and where the parameters start. Also, there is that problem of parameter ordering. I found, that the best way to handle this, is do just use “Console.ReadLine()”. For example,

public void Exeucte()

{

     Console.WriteLine( “Service to start:”);

     string serviceName = Console.ReadLine();

     StartService( serviceName );

}

Pretty easy! This way also allows you to enter and display defaults in case the user does not enter a value or just wants to use the default.

No comments: