Cinchoo – Command Line Argument Parser, Part 9

Inside Command Line Argument Parser – Events

In this section, I’ll brief you about list of callback event mechanism available during Command-Line argument parsing, where you can carry out custom actions to meet your needs.

1. Add a reference to Cinchoo.Core.dll

2. Namespace: Cinchoo.Core.Shell

Below are the events fired by Cinchoo framework while loading the command line arguments

Object level events
  • BeforeCommandLineArgObjectLoaded – Event fired before command line arguments are parsed and loaded.
[ChoBeforeCommandLineArgObjectLoadedHandler]
public void OnBeforeCommandLineArgObjectLoadedHandler(object sender, ChoPreviewCommandLineArgObjectEventArgs args)
{
    args.Cancel = false;
}
  • AfterCommandLineArgObjectLoaded – Event fired after command line arguments are parsed and loaded successfully.
[ChoAfterCommandLineArgObjectLoadedHandler]
public void OnAfterCommandLineArgObjectLoadedHandler(object sender, ChoCommandLineArgObjectEventArgs args)
{
}
  • CommandLineArgObjectLoadError – Event fired when there was exception found while parsing the command line arguments.
[ChoCommandLineArgObjectLoadErrorHandler]
public void OnCommandLineArgObjectLoadError(object sender, ChoCommandLineArgObjectErrorEventArgs args)
{
    Exception ex = args.Exception;
    args.Handled = true;
}
Member level events
  • BeforeCommandLineArgLoaded – Event fired before each command-line argument member loaded.
[ChoBeforeCommandLineArgLoadedHandler]
public void OnBeforeCommandLineArgLoadedHandler(object sender, ChoPreviewCommandLineArgEventArgs args)
{
    if (args.MemberName == "Folders")
    {
        if (args.Value is string)
        {
            string folders = args.Value as string;

            if (!folders.IsNullOrWhiteSpace())
            {
                Folders = folders.SplitNTrim(";");
                args.Cancel = true;
            }
        }
    }
}
  • AfterCommandLineArgLoaded – Event fired after each command-line argument member loaded successfully.
[ChoAfterCommandLineArgLoadedHandler]
public void OnAfterCommandLineArgLoadedHandler(object sender, ChoCommandLineArgEventArgs args)
{
    if (args.MemberName == "Folders")
    {
    }
}
  • CommandLineArgLoadError – Event fired when there was error while loading command-line argument member.
[ChoCommandLineArgObjectLoadErrorHandler]
public void OnCommandLineArgObjectLoadError(object sender, ChoCommandLineArgObjectErrorEventArgs args)
{
    Exception ex = args.Exception;
    args.Handled = true;
}
  • CommandLineArgMemberNotFound – Event fired when there is no command-line member defined for a command-line switch.
[ChoCommandLineArgMemberNotFoundHandler]
public void OnCommandLineArgMemberNotFoundHandler(object sender, ChoCommandLineArgNotFoundEventArgs args)
{
    string cmdLineArgSwitch = args.CmdLineArgSwitch;
    string cmdLineArgValue = args.CmdLineArgValue;
}
  • UnrecognizedCommandLineArgFound – Event fired when there is an unrecognized command line switch found.
[ChoUnrecognizedCommandLineArgFoundHandler]
public void OnUnrecognizedCommandLineArgFoundHandler(object sender, ChoUnrecognizedCommandLineArgEventArg args)
{
    string cmdLineArgValue = args.CmdLineArgValue;
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s