Skip to content

How to define custom commands

Matthias GROSPERRIN edited this page Oct 10, 2015 · 2 revisions

#How to define custom commands ?

By default, MGR.CommandLineParser will look in every assembly in its own folder for every type that inherits ICommand.

The name of your command is the name of the command's type. MGR.CommandLineParser will automatically remove "Command" if the type of your command ends with it.

ICommand is defined as follow :

public interface ICommand
{
    void Execute();
    IList<string> Arguments { get; }
}

MGR.CommandLineParser offers you a base implementation with the abstract class CommandBase. This class implements the Arguments property, add an Help option (to show the help for the requested command), and the core logic to display this help. By extending CommandBase, you simply have to define your options (as property), and override the abstract ExecuteCommand method.