Parsing command line

XSharper scripts accept command line parameters. These parameters are declaratively defined, automatically parsed and values assigned to XSharper variables. The same declaration is also used to display script usage information.

At the beginning three parameters are defined. First two arguments will be assigned to from and to variables, correspondingly. The third parameter, which is optional, is a switch /overwrite which does not have any values following it (count="none"), and sets variable overwrite to true if specified (default is false).

If executed without parameters, because usage options are set to ifNoArguments the script outputs


and exits with exit code "1". Long text lines are automatically wrapped depending on console window width.

Add GUI to the mix

Command line parameters a great for something that is used often. For less frequently used tools it's too hard to read the documentation first, figure out the right combination of switches through trial and error, deal with escaping and so on.

Fortunately, with XSharper scripts GUI is just one click away (the look is completely customizeable, #/gui-param is just another XSharper script in Library ):



Custom usage

While automatic usage generation is useful, it is also possible to replace it with completely custom text instead. For example, the script below displays custom usage text (by adding a
w/o name or switch attributes), and parameter parsing is handled separately (parameters have empty text, and thus not displayed in usage):


Note that using description attribute it's possible to define a user friendly name of a parameter that does not match the variable being set.