Channel 9 Forums - The Sandbox - MSH-Style Command Line Parser for Console apps. V1.5http://mschnlnine.vo.llnwd.net/d1/Dev/App_Themes/C9/images/feedimage.pngChannel 9 Forums - The Sandbox - MSH-Style Command Line Parser for Console apps. V1.5http://channel9.msdn.com/Forums
Channel 9 keeps you up to date with the latest news and behind the scenes info from Microsoft that developers love to keep up with. From LINQ to SilverLight – Watch videos and hear about all the cool technologies coming and the people behind them.http://channel9.msdn.com/Forums
enTue, 03 Mar 2015 19:04:38 GMTTue, 03 Mar 2015 19:04:38 GMTRev97-7-1The Sandbox - MSH-Style Command Line Parser for Console apps. V1.5Quick and easy "MSH style" console input parameter parser with many features. Super simple to use. A single line of code will parse any amount of complicated parameters into the types you defined in the Data class. Also supports multiple Command "Sets".
Will convert and verify the strings into the types defined in the public fields and/or properties of the attributed Data class.

Summary of features:
--------------------------
- Supports named parameters and position parameters.
- Parcial names. "-Name" is same as "-n" or "-na".
- Automaticly builds "Usage" and Detailed Help.
- Supports all primitive types *and Arrays of those types. Will also support any type that has a type converter to convert from a string.
- Standardizes on "-" (not "/") for parm names.
- Parameter/values can be delimited by colon or space. Example: "-name xxx" or "-name:xxx"
- Reserved parameters --, -?, -??, -h, -help, -ver, -version.
- Mandatory parameters.
- Prompt user with your prompt string if Mandatory parameter not given.

A simple app with two optional parameters my look like:
// InputArgsSimple.cs - Defines the expected parms, validations and help
using System;
using CmdParser;

namespace MyConsoleApp
{
/// <summary>
/// InputArgsSimple.cs
/// Defines the parameters we expect at the command line.
/// Here is a simple class that define two optional parameters.
/// First is a bool named Flag and second is a string named Name.
/// The command line to set these fields could be:
/// MyCmd -Flag -Name John
/// MyCmd -Fl:true -Nam:John
/// MyCmd -n John -f:F
///
/// Note: When using Named parameters, the order is not important.
/// We can also seperate the parm name from the value using a space or ":".
/// If a parameter is not given, the default value after construction is the
/// value (i.e. not changed.) Only need to supply enouph chars in parm names
/// to disambiguate from other parms.
/// </summary>
[CmdHelp("Simple console app.", "This is a simple console app to demo CmdParser.", "www.mysite.com", "Copyright (c) 2005 MyOrg", null)]
public class InputArgsSimple
{
[ParameterHelp("Starts app in windows mode.", "Start the program in windows mode.")]
public bool W;

[ParameterHelp("Name of user to find.", "The name of the user to find.")]
public string Name;

public InputArgsSimple()
{
}
}
}

// Main console class.
using System;
using CmdParser;
using System.Reflection;
using System.Collections;

I'm sure this is a lot of fun to build and a great learing exercise but codeproject.com has a few dozen more if that didn't do the job.

Good luck with yours.

]]>http://channel9.msdn.com/Forums/Sandbox/MSH-Style-Command-Line-Parser-for-Console-apps-V15/769c03f9466d4c96ac299dea01031e4d#769c03f9466d4c96ac299dea01031e4d
Mon, 04 Apr 2005 17:50:08 GMThttp://channel9.msdn.com/Forums/Sandbox/MSH-Style-Command-Line-Parser-for-Console-apps-V15/769c03f9466d4c96ac299dea01031e4d#769c03f9466d4c96ac299dea01031e4ddatabyte7http://channel9.msdn.com/Niners/databyte/Discussions/RSSThe Sandbox - MSH-Style Command Line Parser for Console apps. V1.5Thanks databyte. But you will need to look closer. This is nothing like those other parsers. This is modeled after the MSH (i.e. Monad) parser. Can handle all primitive types, arrays of those types, any other type you can define a converter for. It
also has integrated Detailed help and Usage help and a ton of validation such as:
CmdHelp (Defines help for the whole command.)
DefaultSet (Defines the default set when more sets match.)
Parameter (base attribute)
ParameterHelp (Defines help for the parm.)
ParsingMandatoryParameter (Parm is required)
ParsingParameterDeclaration
ParsingParameterMapping (Maps parm to set name and position)
ParsingPromptString (Prompt for input)
ParsingVariableLengthParameterList (var list)
SwitchParameter (a bool)
ValidationCount (Array min/max count)
ValidationLength (string min/max len)
ValidationPattern (Regex pattern)
ValidationRange (Object min/max range)
ValidationSet (Set of strings that are valid.)

You also get Parameter Sets, variable length parameter lists, Input Prompt, mandatory checks, various validations, etc. In effect, allows you to Overload your command line parms into "Sets" and the engine figures out which set to use or throws proper error.
It also works with any combination of Named or Position parameters and figures out which set to use if possible. You also get "Parcial" name support. So "-n:hello" is the same as "-Name hello" or even "-na xyz" if we can disabiguate the name from other parms.
Other helpful things I need to write about. Thanks.]]>http://channel9.msdn.com/Forums/Sandbox/MSH-Style-Command-Line-Parser-for-Console-apps-V15/6ff1c9be5d5b4bad92949dea01031e7a#6ff1c9be5d5b4bad92949dea01031e7a
Mon, 04 Apr 2005 19:07:09 GMThttp://channel9.msdn.com/Forums/Sandbox/MSH-Style-Command-Line-Parser-for-Console-apps-V15/6ff1c9be5d5b4bad92949dea01031e7a#6ff1c9be5d5b4bad92949dea01031e7aWilliam Stacey7http://channel9.msdn.com/Niners/staceyw/Discussions/RSSThe Sandbox - MSH-Style Command Line Parser for Console apps. V1.5Excellent !