Command Line Helper

Description

CommandLineHelper is a utility class in WinForms Controls created to parse command line arguments for Windows Forms application easily. The purpose of command line for WinForms application is used to launch application with user selected configuration.

To make it more user friendly, a built in Command Line Builder Dialog is available to help user to create command line using the available options, create batch file as well as create window's shortcut.


Arguments and Switches

Command line parameters are categorized as arguments and switches where argument are mandatory parameter while switches on the other hand are optional parameter. Arguments and switches are registered to application by developer using AddArgument and AddSwitch functions.

Switches normally use as an true or false logic. An optional variable can be added to define quantitative value, for example: /T:time

Usage

Initialization

  1. Create a new instance
    CommandLineHelper cmdLine = new CommandLineHelper("Description");
  2.  Register command line argument and switches
    cmdLine.AddArgument("Source Path", "Source Folder Path");
    cmdLine.AddSwitch("/MIN", "Minimize Window");
    cmdLine.AddSwitch("/T", "Delay(ms)", "t");

Parse Command Line

Call cmdLine.ParseCommandLine() to parse command line arguments in constructor of main form or Shown event. The function will return TRUE if the command line is valid.

With valid command line input, value for each argument can be retrieve by the following functions:
  string sourcePath = cmdLine.GetArgumentValue("Source Path");
  bool minWindow = cmdLine.IsSwitchSet("/MIN");
  int delay = Convert.ToInt32(cmdLine.GetSwitchValue("/T", "100"));

Build Command Line - Programmatically

To create or update command line programmatically using the current application settings, set value for each argument and switches with following functions:
  • cmdLine.SetArgument("Source Path", "C:\\Target\\");
  • cmdLine.ClearSwitch("/MIN");
  • cmdLine.SetSwitch("/T", "20");
Then, generate the complete command line as follow:
  string output = cmdLine.BuildCommandLine(); 

 Command Line Builder - Interactive

Command line can also be created by user using the interactive Command Line Builder Dialog. The dialog is created to assist user to fill in the value for each arguments and select option for each switches when building command line. The generated command line can be copy to clipboard, output a batch file or even create as Window's shortcut.

  cmdLine.ShowDialog();

Download CommandLineHelper from WinForms Controls.

Popular posts from this blog

C# DSP Simulation - DSP Lab

C# DSP Toolbox: Digital Filters (Updated)