public static ProcessCommandLineArguments ( IList |
||
args | IList |
The original arguments to process. |
options | string>.ICollection | Any long options (arguments that start with "--")
/// will be added to this dictionary, and removed from |
atFolder | string | If a parameter has the form @filename, the folder
/// specified by atFolder will be searched for an options text file with the
/// user-specified filename, and the contents of the file will be expanded
/// into the list of arguments (split using SplitCommandLineArguments). The
/// expanded list can contain new @filenames, which are also processed. To
/// search in the current directory, use "". The @filename may use an absolute
/// path, which overrides this folder. To disable @filename expansion, set
/// this parameter to null. Whether the feature is enabled or disabled,
/// @filenames are not removed from |
shortOptions | string>.IDictionary | A map from one-letter options that start with
/// "-" rather than "--", to the name of the corresponding long option (this
/// option can be null to ignore all short options.) For example, if this
/// contains ( |
twoArgOptions | InvertibleSet |
A set of options in which the argument can
/// be separated by a space from the option. For example, if the input is
/// "--out foo.txt" and you want to recognize "foo.txt" as the argument to
/// "--out", add the string "out" to this set. If you want to treat all
/// options this way, use |
argLimit | int | A limit placed on the number of arguments when /// expanding @files. Such a file may refer to itself, and this is the only /// protection provided against infinite recursive expansion. |
expandEnvVars | bool | If true, environment variable references
/// such as |
caseSensitiveLongOpts | bool | If true, long options are case- /// sensitive. By default, long options are not case sensitive. |
Résultat | void |
public void TestProcessCommandLineArguments2() { // Generate two options files, where the first refers to the second string atFolder = Environment.ExpandEnvironmentVariables("%TEMP%"); string file1 = "test ProcessCmdLine 1.txt"; string file2 = "test ProcessCmdLine 2.txt"; StreamWriter w = new StreamWriter(Path.Combine(atFolder, file1)); w.WriteLine("\"@" + file2 + "\" fox--jumps\n--over"); w.Close(); w = new StreamWriter(Path.Combine(atFolder, file2)); w.WriteLine("these arguments are ignored (arg limit exceeded)"); w.Close(); // Expand command line and ensure that the arg limit is enforced List <string> args = G.SplitCommandLineArguments("\"@" + file1 + "\" \"lazy dog\""); var options = new DList <KeyValuePair <string, string> >(); var msgs = new MessageHolder(); using (MessageSink.SetDefault(msgs)) UG.ProcessCommandLineArguments(args, options, atFolder, null, null, 5); ExpectList(args.AsListSource(), "@" + file1, "@" + file2, "fox--jumps", "lazy dog"); ExpectList(options, P("over", null)); ExpectList(msgs.List.Select(msg => msg.ToString()).AsListSource(), "@test ProcessCmdLine 2.txt: Warning: Limit of 5 commands exceeded"); }
public void TestProcessCommandLineArguments1() { string commandLine = "-abZ -ab123 and -a=Foo --Apple:No -b plantain --a %TEMP% @notExpanded --banana -Z --empty="; var args = G.SplitCommandLineArguments(commandLine); var shortOpts = new Dictionary <char, string> { { 'a', null }, { 'b', "banana" } }; var twoArgOptions = new InvertibleSet <string>(new[] { "banana" }); var options = new DList <KeyValuePair <string, string> >(); UG.ProcessCommandLineArguments(args, options, null, shortOpts, twoArgOptions, expandEnvVars: false); ExpectList(args.AsListSource(), "-abZ", "and", "%TEMP%", "@notExpanded", "-Z"); ExpectList(options, P("a", null), P("banana", "123"), P("a", "Foo"), P("apple", "No"), P("banana", "plantain"), P("a", null), P("banana", null), P("empty", "")); }