From 08fb9274e6b378b5edd333efcc1d6dfb04f912eb Mon Sep 17 00:00:00 2001 From: Jonathan Pryor Date: Wed, 1 Dec 2010 00:06:44 -0500 Subject: [PATCH] Add response file suport to Mono.Options. Response file support is an "opt-in" feature, performed by adding a ResponseFileSource to the OptionSet initialization logic: var p = new OptionSet () { // normal options here... new ResponseFileSource (), }; Response files make use of the new "ArgumentSource" support, which acts as a low-level argument pre-processor, allowing processing of arguments _before_ Option processing is performed. --- data/mono-options.pc.in | 2 +- .../Mono.Options/Assembly/AssemblyInfo.cs | 2 +- .../en/Mono.Options/ArgumentSource.xml | 238 ++++++++++++++++++ .../Documentation/en/Mono.Options/Option.xml | 34 ++- .../en/Mono.Options/OptionAction`2.xml | 2 + .../en/Mono.Options/OptionContext.xml | 14 ++ .../en/Mono.Options/OptionException.xml | 14 ++ .../en/Mono.Options/OptionSet.xml | 194 +++++++++++--- .../en/Mono.Options/OptionValueCollection.xml | 64 ++++- .../en/Mono.Options/OptionValueType.xml | 8 + .../en/Mono.Options/ResponseFileSource.xml | 134 ++++++++++ .../Mono.Options/Documentation/en/index.xml | 15 +- .../Mono.Options/Mono.Options/Options.cs | 213 +++++++++++++--- .../Test/Mono.Options/OptionSetTest.cs | 171 +++++++++++-- 14 files changed, 1007 insertions(+), 98 deletions(-) create mode 100644 mcs/class/Mono.Options/Documentation/en/Mono.Options/ArgumentSource.xml create mode 100644 mcs/class/Mono.Options/Documentation/en/Mono.Options/ResponseFileSource.xml diff --git a/data/mono-options.pc.in b/data/mono-options.pc.in index 028ff763f33..8c569820d4e 100644 --- a/data/mono-options.pc.in +++ b/data/mono-options.pc.in @@ -4,4 +4,4 @@ Sources=${assemblies_dir}/Options.cs Name: Mono.Options Description: Command Line Parsing Library -Version: 0.2.1 +Version: 0.2.2 diff --git a/mcs/class/Mono.Options/Assembly/AssemblyInfo.cs b/mcs/class/Mono.Options/Assembly/AssemblyInfo.cs index 183af76b037..281d53b44f9 100644 --- a/mcs/class/Mono.Options/Assembly/AssemblyInfo.cs +++ b/mcs/class/Mono.Options/Assembly/AssemblyInfo.cs @@ -41,7 +41,7 @@ using System.Security.Permissions; // // DO NOT MODIFY STRINGS BELOW WITHOUT UPDATING mono/data/mono-options.pc.in // - "0.2.1.0" + "0.2.2.0" // // DO NOT MODIFY STRINGS ABOVE WITHOUT UPDATING mono/data/mono-options.pc.in // diff --git a/mcs/class/Mono.Options/Documentation/en/Mono.Options/ArgumentSource.xml b/mcs/class/Mono.Options/Documentation/en/Mono.Options/ArgumentSource.xml new file mode 100644 index 00000000000..83d92060659 --- /dev/null +++ b/mcs/class/Mono.Options/Documentation/en/Mono.Options/ArgumentSource.xml @@ -0,0 +1,238 @@ + + + + + Mono.Options + 0.2.2.0 + + + System.Object + + + + + Support for inserting additional arguments during + + processing. + + + + The type is an + abstraction to allow "insertion" of additional values for option + processing while processing arguments. + + + The principal use case is for response files, as used by + CSC.EXE, CL.EXE, and numerous other + compilers. A response file contains additional options for the tool, + and the contents of the response file should be "inserted" as if + entered on the command line. Response files are useful for bypassing + command-line length limitations, among other things. + + + Applications must opt-in to response file support by calling + + before calling + . + + + Inheriting classes must override the following abstract methods: + + + + + + + + + Constructor + + 0.2.2.0 + + + + + Construct and initialize a + instance. + + + + + + + + + Property + + 0.2.2.0 + + + System.String + + + + The description to provide for the argument source within + . + + + A containing + the description to provide for the argument source within + . + + + + + + + + + Method + + 0.2.2.0 + + + System.Collections.Generic.IEnumerable<System.String> + + + + + + + A to extract arguments from. + + + Extract arguments from a . + + + A + which will provide arguments extracted from . + + + + Arguments are extracted from by + splitting on newlines and spaces but maintaining the contents of + single-quoted and double-quoted strings. Thus, A B will be + split as the separate strings "A", "B", while + "A B" will be returned as-is. + + + is not + d. + + + + + + + + Method + + 0.2.2.0 + + + System.Boolean + + + + + + + + A containing the argument to replace + with additional arguments. + + + A + which will refer to teh replacement arguments if this method returns + ; otherwise, this value should be ignored by + callers. + + + Replace the argument with a set of + replacement arguments. + + + if this + will replace + with a set of replacement strings and + contains the replacement strings; + otherwise, . + + + + Before + + attempts to parse an argument as an option (or option value), all + registered + are consulted in registration order to see if + "supports" the + argument via + . + The first ArgumentSource to return + from GetArguments() may provide the replacement tokens, and + no later ArgumentSourcees are consulted. + + + + + + + + + Method + + 0.2.2.0 + + + System.Collections.Generic.IEnumerable<System.String> + + + + + + + A containing the file to extract + arguments from. + + + Extract arguments from the specified filename. + + + A + which will provide arguments extracted from . + + + + + could not be read. + + + + + + + + Method + + 0.2.2.0 + + + System.String[] + + + + + The names to provide for the argument source within + . + + + A array containing + the names to provide for the argument source within + . + + + + + + + diff --git a/mcs/class/Mono.Options/Documentation/en/Mono.Options/Option.xml b/mcs/class/Mono.Options/Documentation/en/Mono.Options/Option.xml index 859bb4be296..f3e7e547a97 100644 --- a/mcs/class/Mono.Options/Documentation/en/Mono.Options/Option.xml +++ b/mcs/class/Mono.Options/Documentation/en/Mono.Options/Option.xml @@ -1,9 +1,11 @@ + Mono.Options 0.2.0.0 0.2.1.0 + 0.2.2.0 All members of this type are safe for multithreaded operations. @@ -86,10 +88,12 @@ + Constructor 0.2.0.0 0.2.1.0 + 0.2.2.0 @@ -154,10 +158,12 @@ + Constructor 0.2.0.0 0.2.1.0 + 0.2.2.0 @@ -348,10 +354,12 @@ + Property 0.2.0.0 0.2.1.0 + 0.2.2.0 System.String @@ -379,10 +387,12 @@ + Method 0.2.0.0 0.2.1.0 + 0.2.2.0 System.String[] @@ -407,10 +417,12 @@ + Method 0.2.0.0 0.2.1.0 + 0.2.2.0 System.String[] @@ -456,10 +468,12 @@ + Method 0.2.0.0 0.2.1.0 + 0.2.2.0 System.Void @@ -507,10 +521,12 @@ + Property 0.2.0.0 0.2.1.0 + 0.2.2.0 System.Int32 @@ -544,10 +560,12 @@ + Method 0.2.0.0 0.2.1.0 + 0.2.2.0 System.Void @@ -587,7 +605,7 @@ // Case-Insensitive and Concatenating OptionSet using System; using System.Collections.Generic; -using Mono.Options; +using NDesk.Options; class DemoOptionSet : OptionSet { protected override void InsertItem (int index, Option item) @@ -730,10 +748,12 @@ class Demo { + Property 0.2.0.0 0.2.1.0 + 0.2.2.0 Mono.Options.OptionValueType @@ -758,14 +778,19 @@ class Demo { + Method 0.2.0.0 0.2.1.0 + 0.2.2.0 T + + + @@ -811,16 +836,15 @@ class Demo { . - - - + Property 0.2.0.0 0.2.1.0 + 0.2.2.0 System.String @@ -850,10 +874,12 @@ class Demo { + Method 0.2.0.0 0.2.1.0 + 0.2.2.0 System.String diff --git a/mcs/class/Mono.Options/Documentation/en/Mono.Options/OptionAction`2.xml b/mcs/class/Mono.Options/Documentation/en/Mono.Options/OptionAction`2.xml index ab8ffdb8f1c..0fbd6ce3d7b 100644 --- a/mcs/class/Mono.Options/Documentation/en/Mono.Options/OptionAction`2.xml +++ b/mcs/class/Mono.Options/Documentation/en/Mono.Options/OptionAction`2.xml @@ -1,9 +1,11 @@ + Mono.Options 0.2.0.0 0.2.1.0 + 0.2.2.0 diff --git a/mcs/class/Mono.Options/Documentation/en/Mono.Options/OptionContext.xml b/mcs/class/Mono.Options/Documentation/en/Mono.Options/OptionContext.xml index d75832d2fe4..87abd3c8902 100644 --- a/mcs/class/Mono.Options/Documentation/en/Mono.Options/OptionContext.xml +++ b/mcs/class/Mono.Options/Documentation/en/Mono.Options/OptionContext.xml @@ -1,9 +1,11 @@ + Mono.Options 0.2.0.0 0.2.1.0 + 0.2.2.0 System.Object @@ -22,10 +24,12 @@ + Constructor 0.2.0.0 0.2.1.0 + 0.2.2.0 @@ -46,10 +50,12 @@ + Property 0.2.0.0 0.2.1.0 + 0.2.2.0 Mono.Options.Option @@ -63,10 +69,12 @@ + Property 0.2.0.0 0.2.1.0 + 0.2.2.0 System.Int32 @@ -88,10 +96,12 @@ + Property 0.2.0.0 0.2.1.0 + 0.2.2.0 System.String @@ -109,10 +119,12 @@ + Property 0.2.0.0 0.2.1.0 + 0.2.2.0 Mono.Options.OptionSet @@ -137,10 +149,12 @@ + Property 0.2.0.0 0.2.1.0 + 0.2.2.0 Mono.Options.OptionValueCollection diff --git a/mcs/class/Mono.Options/Documentation/en/Mono.Options/OptionException.xml b/mcs/class/Mono.Options/Documentation/en/Mono.Options/OptionException.xml index 3b65e4751b1..5ebfb683fd6 100644 --- a/mcs/class/Mono.Options/Documentation/en/Mono.Options/OptionException.xml +++ b/mcs/class/Mono.Options/Documentation/en/Mono.Options/OptionException.xml @@ -1,9 +1,11 @@ + Mono.Options 0.2.0.0 0.2.1.0 + 0.2.2.0 System.Exception @@ -44,9 +46,11 @@ + Constructor 0.2.1.0 + 0.2.2.0 @@ -56,10 +60,12 @@ + Constructor 0.2.0.0 0.2.1.0 + 0.2.2.0 @@ -90,10 +96,12 @@ + Constructor 0.2.0.0 0.2.1.0 + 0.2.2.0 @@ -122,10 +130,12 @@ + Constructor 0.2.0.0 0.2.1.0 + 0.2.2.0 @@ -163,10 +173,12 @@ + Method 0.2.0.0 0.2.1.0 + 0.2.2.0 System.Void @@ -201,10 +213,12 @@ + Property 0.2.0.0 0.2.1.0 + 0.2.2.0 System.String diff --git a/mcs/class/Mono.Options/Documentation/en/Mono.Options/OptionSet.xml b/mcs/class/Mono.Options/Documentation/en/Mono.Options/OptionSet.xml index 0be30b58c7c..6f0707a55da 100644 --- a/mcs/class/Mono.Options/Documentation/en/Mono.Options/OptionSet.xml +++ b/mcs/class/Mono.Options/Documentation/en/Mono.Options/OptionSet.xml @@ -1,9 +1,11 @@ + Mono.Options 0.2.0.0 0.2.1.0 + 0.2.2.0 All public static members of this type are safe for multithreaded @@ -18,8 +20,8 @@ System.Collections.ObjectModel.KeyedCollection<System.String,Mono.Options.Option> - System.String - Mono.Options.Option + System.String + Mono.Options.Option @@ -48,6 +50,10 @@ arguments which were not matched by a registered . + + Response files, as used by mcs and other compiler tools, may be + supported by using . + Three conditions must be met for a sequence of arguments to be considered as a match for an : @@ -290,7 +296,7 @@ using System; using System.Collections.Generic; -using Mono.Options; +using NDesk.Options; class Test { static int verbosity; @@ -437,7 +443,7 @@ Try `greet --help' for more information. using System; using System.Linq; using System.Collections.Generic; -using Mono.Options; +using NDesk.Options; class Test { public static void Main (string[] args) @@ -630,7 +636,7 @@ Options: // Case-Insensitive and Concatenating OptionSet using System; using System.Collections.Generic; -using Mono.Options; +using NDesk.Options; class DemoOptionSet : OptionSet { protected override void InsertItem (int index, Option item) @@ -813,14 +819,17 @@ Key: a\b\c=d\e\f + + Constructor 0.2.0.0 0.2.1.0 + 0.2.2.0 @@ -841,10 +850,12 @@ Key: a\b\c=d\e\f + Constructor 0.2.0.0 0.2.1.0 + 0.2.2.0 @@ -890,14 +901,14 @@ Key: a\b\c=d\e\f See the following example, which demonstrates how different localizers alter the program output. - // Localization with Mono.Options.OptionSet. + // Localization with NDesk.Options.OptionSet. // // Compile as: -// gmcs -r:Mono.Posix.dll -r:Mono.Options.dll code-localization.cs +// gmcs -r:Mono.Posix.dll -r:NDesk.Options.dll code-localization.cs using System; using System.IO; using Mono.Unix; -using Mono.Options; +using NDesk.Options; class LocalizationDemo { public static void Main (string[] args) @@ -948,7 +959,7 @@ class LocalizationDemo { if (help) p.WriteOptionDescriptions (Console.Out); if (version) - Console.WriteLine ("Mono.Options Localizer Demo 1.0"); + Console.WriteLine ("NDesk.Options Localizer Demo 1.0"); if (verbose > 0) Console.WriteLine ("Message level: {0}", verbose); } @@ -961,21 +972,21 @@ class LocalizationDemo { -v, --verbose increase message verbosity. -n=VALUE must be an int -V, --version output version information and exit. -Mono.Options Localizer Demo 1.0 +NDesk.Options Localizer Demo 1.0 $ LANGUAGE=es mono localization.exe --with-gettext --help --version -h, -?, --help A mostrar este mensaje y salir. -v, --verbose Aumento mensaje verbosidad. -n=VALUE Debe ser un int -V, --version Salida de información de versión y sale. -Mono.Options Localizer Demo 1.0 +NDesk.Options Localizer Demo 1.0 $ mono localization.exe --with-hello --help --version -h, -?, --help hello:show this message and exit. -v, --verbose hello:increase message verbosity. -nhello:=VALUE hello:must be an int -V, --version hello:output version information and exit. -Mono.Options Localizer Demo 1.0 +NDesk.Options Localizer Demo 1.0 $ mono localization.exe -n not-an-int localization: Could not convert string `not-an-int' to type Int32 for option `-n'. @@ -1009,12 +1020,48 @@ localization: hello:Could not convert string `not-an-int' to type Int32 for opti + + + + Method + + 0.2.2.0 + + + Mono.Options.OptionSet + + + + + + + A to register for + argument processing. + + + Registers so that it may be consulted + during argument processing within + . + + + The current instance. + This is to permit method chaining. + + + + + is . + + + + Method 0.2.0.0 0.2.1.0 + 0.2.2.0 Mono.Options.OptionSet @@ -1054,10 +1101,12 @@ localization: hello:Could not convert string `not-an-int' to type Int32 for opti + Method 0.2.0.0 0.2.1.0 + 0.2.2.0 Mono.Options.OptionSet @@ -1113,10 +1162,12 @@ localization: hello:Could not convert string `not-an-int' to type Int32 for opti + Method 0.2.0.0 0.2.1.0 + 0.2.2.0 Mono.Options.OptionSet @@ -1172,10 +1223,12 @@ localization: hello:Could not convert string `not-an-int' to type Int32 for opti + Method 0.2.0.0 0.2.1.0 + 0.2.2.0 Mono.Options.OptionSet @@ -1241,10 +1294,12 @@ localization: hello:Could not convert string `not-an-int' to type Int32 for opti + Method 0.2.0.0 0.2.1.0 + 0.2.2.0 Mono.Options.OptionSet @@ -1300,14 +1355,19 @@ localization: hello:Could not convert string `not-an-int' to type Int32 for opti + Method 0.2.0.0 0.2.1.0 + 0.2.2.0 Mono.Options.OptionSet + + + @@ -1353,20 +1413,22 @@ localization: hello:Could not convert string `not-an-int' to type Int32 for opti a previously registered . - - - + Method 0.2.0.0 0.2.1.0 + 0.2.2.0 Mono.Options.OptionSet + + + @@ -1446,20 +1508,23 @@ localization: hello:Could not convert string `not-an-int' to type Int32 for opti is - - - + Method 0.2.0.0 0.2.1.0 + 0.2.2.0 Mono.Options.OptionSet + + + + @@ -1516,21 +1581,23 @@ localization: hello:Could not convert string `not-an-int' to type Int32 for opti is - - - - + Method 0.2.0.0 0.2.1.0 + 0.2.2.0 Mono.Options.OptionSet + + + + @@ -1600,17 +1667,42 @@ localization: hello:Could not convert string `not-an-int' to type Int32 for opti is - - - - + + + + + Property + + 0.2.2.0 + + + System.Collections.ObjectModel.ReadOnlyCollection<Mono.Options.ArgumentSource> + + + + A collection of all + s which will be consulted during + + processing. + + + A + containing all s which + have been + ed. + + + + + Method 0.2.0.0 0.2.1.0 + 0.2.2.0 Mono.Options.OptionContext @@ -1645,9 +1737,11 @@ localization: hello:Could not convert string `not-an-int' to type Int32 for opti + Method 0.2.1.0 + 0.2.2.0 System.String @@ -1694,22 +1788,24 @@ localization: hello:Could not convert string `not-an-int' to type Int32 for opti + Method 0.2.0.0 0.2.1.0 + 0.2.2.0 + + + System.Obsolete("Use KeyedCollection.this[string]") + + Mono.Options.Option - - - System.Obsolete("Use KeyedCollection.this[string]") - - A containing the option name to @@ -1740,10 +1836,12 @@ localization: hello:Could not convert string `not-an-int' to type Int32 for opti + Method 0.2.0.0 0.2.1.0 + 0.2.2.0 System.Boolean @@ -1832,10 +1930,12 @@ localization: hello:Could not convert string `not-an-int' to type Int32 for opti + Method 0.2.0.0 0.2.1.0 + 0.2.2.0 System.Void @@ -1862,10 +1962,12 @@ localization: hello:Could not convert string `not-an-int' to type Int32 for opti + Property 0.2.0.0 0.2.1.0 + 0.2.2.0 System.Converter<System.String,System.String> @@ -1891,10 +1993,12 @@ localization: hello:Could not convert string `not-an-int' to type Int32 for opti + Method 0.2.0.0 0.2.1.0 + 0.2.2.0 System.Collections.Generic.List<System.String> @@ -1917,6 +2021,16 @@ localization: hello:Could not convert string `not-an-int' to type Int32 for opti containing all unhandled arguments. + + Parse looks at each argument from in order, passing each argument to each + within + using + + until a source returns (and the + replacement sequence is used) or no ArgumentSource supports + the argument. Parse then attempts to process argument as + an option. + An argument is unhandled if: @@ -1978,7 +2092,7 @@ localization: hello:Could not convert string `not-an-int' to type Int32 for opti using System; using System.Collections.Generic; -using Mono.Options; +using NDesk.Options; class Test { static int verbosity; @@ -2059,10 +2173,12 @@ class Test { + Method 0.2.0.0 0.2.1.0 + 0.2.2.0 System.Boolean @@ -2154,10 +2270,12 @@ class Test { + Method 0.2.0.0 0.2.1.0 + 0.2.2.0 System.Void @@ -2180,10 +2298,12 @@ class Test { + Method 0.2.0.0 0.2.1.0 + 0.2.2.0 System.Void @@ -2212,10 +2332,12 @@ class Test { + Method 0.2.0.0 0.2.1.0 + 0.2.2.0 System.Void @@ -2261,6 +2383,12 @@ class Test { more than one value, the leading number is used to specify which value the string is for. + + Once all s have been written, + all s are printed out + using and + . + @@ -2271,7 +2399,7 @@ class Test { using System; using System.Collections.Generic; -using Mono.Options; +using NDesk.Options; class Test { static int verbosity; diff --git a/mcs/class/Mono.Options/Documentation/en/Mono.Options/OptionValueCollection.xml b/mcs/class/Mono.Options/Documentation/en/Mono.Options/OptionValueCollection.xml index b4dcf59408d..66caf4e4de8 100644 --- a/mcs/class/Mono.Options/Documentation/en/Mono.Options/OptionValueCollection.xml +++ b/mcs/class/Mono.Options/Documentation/en/Mono.Options/OptionValueCollection.xml @@ -1,14 +1,22 @@ - + + Mono.Options 0.2.0.0 0.2.1.0 + 0.2.2.0 System.Object + + System.Collections.Generic.ICollection<System.String> + + + System.Collections.Generic.IEnumerable<System.String> + System.Collections.Generic.IList<System.String> @@ -50,10 +58,12 @@ + Method 0.2.0.0 0.2.1.0 + 0.2.2.0 System.Void @@ -69,10 +79,12 @@ + Method 0.2.0.0 0.2.1.0 + 0.2.2.0 System.Void @@ -85,10 +97,12 @@ + Method 0.2.0.0 0.2.1.0 + 0.2.2.0 System.Boolean @@ -105,10 +119,12 @@ + Method 0.2.0.0 0.2.1.0 + 0.2.2.0 System.Void @@ -126,10 +142,12 @@ + Property 0.2.0.0 0.2.1.0 + 0.2.2.0 System.Int32 @@ -142,10 +160,12 @@ + Method 0.2.0.0 0.2.1.0 + 0.2.2.0 System.Collections.Generic.IEnumerator<System.String> @@ -159,10 +179,12 @@ + Method 0.2.0.0 0.2.1.0 + 0.2.2.0 System.Int32 @@ -179,10 +201,12 @@ + Method 0.2.0.0 0.2.1.0 + 0.2.2.0 System.Void @@ -200,10 +224,12 @@ + Property 0.2.0.0 0.2.1.0 + 0.2.2.0 System.Boolean @@ -216,10 +242,12 @@ + Property 0.2.0.0 0.2.1.0 + 0.2.2.0 System.String @@ -236,10 +264,12 @@ + Method 0.2.0.0 0.2.1.0 + 0.2.2.0 System.Boolean @@ -256,10 +286,12 @@ + Method 0.2.0.0 0.2.1.0 + 0.2.2.0 System.Void @@ -275,10 +307,12 @@ + Method 0.2.0.0 0.2.1.0 + 0.2.2.0 System.Void @@ -296,10 +330,12 @@ + Property 0.2.0.0 0.2.1.0 + 0.2.2.0 System.Boolean @@ -312,10 +348,12 @@ + Property 0.2.0.0 0.2.1.0 + 0.2.2.0 System.Object @@ -328,10 +366,12 @@ + Method 0.2.0.0 0.2.1.0 + 0.2.2.0 System.Collections.IEnumerator @@ -345,10 +385,12 @@ + Method 0.2.0.0 0.2.1.0 + 0.2.2.0 System.Int32 @@ -365,10 +407,12 @@ + Method 0.2.0.0 0.2.1.0 + 0.2.2.0 System.Boolean @@ -385,10 +429,12 @@ + Method 0.2.0.0 0.2.1.0 + 0.2.2.0 System.Int32 @@ -405,10 +451,12 @@ + Method 0.2.0.0 0.2.1.0 + 0.2.2.0 System.Void @@ -426,10 +474,12 @@ + Property 0.2.0.0 0.2.1.0 + 0.2.2.0 System.Boolean @@ -442,10 +492,12 @@ + Property 0.2.0.0 0.2.1.0 + 0.2.2.0 System.Object @@ -462,10 +514,12 @@ + Method 0.2.0.0 0.2.1.0 + 0.2.2.0 System.Void @@ -481,10 +535,12 @@ + Method 0.2.0.0 0.2.1.0 + 0.2.2.0 System.Void @@ -500,10 +556,12 @@ + Method 0.2.0.0 0.2.1.0 + 0.2.2.0 System.String[] @@ -517,10 +575,12 @@ + Method 0.2.0.0 0.2.1.0 + 0.2.2.0 System.Collections.Generic.List<System.String> @@ -534,10 +594,12 @@ + Method 0.2.0.0 0.2.1.0 + 0.2.2.0 System.String diff --git a/mcs/class/Mono.Options/Documentation/en/Mono.Options/OptionValueType.xml b/mcs/class/Mono.Options/Documentation/en/Mono.Options/OptionValueType.xml index 6f6f62c9007..aa035c500d6 100644 --- a/mcs/class/Mono.Options/Documentation/en/Mono.Options/OptionValueType.xml +++ b/mcs/class/Mono.Options/Documentation/en/Mono.Options/OptionValueType.xml @@ -1,9 +1,11 @@ + Mono.Options 0.2.0.0 0.2.1.0 + 0.2.2.0 System.Enum @@ -20,10 +22,12 @@ + Field 0.2.0.0 0.2.1.0 + 0.2.2.0 Mono.Options.OptionValueType @@ -41,10 +45,12 @@ + Field 0.2.0.0 0.2.1.0 + 0.2.2.0 Mono.Options.OptionValueType @@ -67,10 +73,12 @@ + Field 0.2.0.0 0.2.1.0 + 0.2.2.0 Mono.Options.OptionValueType diff --git a/mcs/class/Mono.Options/Documentation/en/Mono.Options/ResponseFileSource.xml b/mcs/class/Mono.Options/Documentation/en/Mono.Options/ResponseFileSource.xml new file mode 100644 index 00000000000..f97cb570494 --- /dev/null +++ b/mcs/class/Mono.Options/Documentation/en/Mono.Options/ResponseFileSource.xml @@ -0,0 +1,134 @@ + + + + + Mono.Options + 0.2.2.0 + + + Mono.Options.ArgumentSource + + + + + Inserts the contents of a file during argument processing. + + + + ResponseFileSource looks for arguments which start with + @, assumes that what follows the @ is a valid filename, + and reads the contents of the filename as the replacement text. + + + + + + + + Constructor + + 0.2.2.0 + + + + + Constructs and initializes a + instance. + + + + + + + + + Property + + 0.2.2.0 + + + System.String + + + + The description to provide for the argument source within + . + + + "Read response file for more options.". + + + + + + + + + Method + + 0.2.2.0 + + + System.Boolean + + + + + + + + A containing the argument to replace + with additional arguments. + + + A + which will refer to teh replacement arguments if this method returns + ; otherwise, this value should be ignored by + callers. + + + Replace the argument with the contents of + the specified file. + + + If starts with @, then + will contain the parsed contents of + the filename resulting from .Substring(1) + and is returned; otherwise, + is returned. + + + + + starts with @ and + .Substring(1) doees not exist. + + + + + + + + Method + + 0.2.2.0 + + + System.String[] + + + + + The names to provide for the argument source within + . + + + A array containing + an element with the value "@file". + + + + + + + diff --git a/mcs/class/Mono.Options/Documentation/en/index.xml b/mcs/class/Mono.Options/Documentation/en/index.xml index f02c2392dc7..81b20539176 100644 --- a/mcs/class/Mono.Options/Documentation/en/index.xml +++ b/mcs/class/Mono.Options/Documentation/en/index.xml @@ -3,28 +3,30 @@ Program option parser. 2008 Novell, Inc. - + + [00 24 00 00 04 80 00 00 94 00 00 00 06 02 00 00 00 24 00 00 52 53 41 31 00 04 00 00 01 00 01 00 79 15 99 77 d2 d0 3a 8e 6b ea 7a 2e 74 e8 d1 af cc 93 e8 85 19 74 95 2b b4 80 a1 2c 91 34 47 4d 04 06 24 47 c3 7e 0e 68 c0 80 53 6f cf 3c 3f be 2f f9 c9 79 ce 99 84 75 e5 06 e8 ce 82 dd 5b 0f 35 0d c1 0e 93 bf 2e ee cf 87 4b 24 77 0c 50 81 db ea 74 47 fd da fa 27 7b 22 de 47 d6 ff ea 44 96 74 a4 f9 fc cf 84 d1 50 69 08 93 80 28 4d bd d3 5f 46 cd ff 12 a1 bd 78 e4 ef 00 65 d0 16 df ] - System.Runtime.CompilerServices.RuntimeCompatibility(WrapNonExceptionThrows=true) + System.CLSCompliant(true) - System.Runtime.InteropServices.ComVisible(false) + System.Reflection.AssemblyDescription("Command Line Parsing Utilities") - System.CLSCompliant(true) + System.Reflection.AssemblyTitle("Mono.Options.dll") - System.Reflection.AssemblyDescription("Command Line Parsing Utilities") + System.Runtime.CompilerServices.RuntimeCompatibility(WrapNonExceptionThrows=true) - System.Reflection.AssemblyTitle("Mono.Options.dll") + System.Runtime.InteropServices.ComVisible(false) + @@ -32,6 +34,7 @@ + diff --git a/mcs/class/Mono.Options/Mono.Options/Options.cs b/mcs/class/Mono.Options/Mono.Options/Options.cs index 6c2df9aee9f..b9b48a96722 100644 --- a/mcs/class/Mono.Options/Mono.Options/Options.cs +++ b/mcs/class/Mono.Options/Mono.Options/Options.cs @@ -544,6 +544,92 @@ namespace Mono.Options } } + public abstract class ArgumentSource { + + protected ArgumentSource () + { + } + + public abstract string[] GetNames (); + public abstract string Description { get; } + public abstract bool GetArguments (string value, out IEnumerable replacement); + + public static IEnumerable GetArgumentsFromFile (string file) + { + return GetArguments (File.OpenText (file), true); + } + + public static IEnumerable GetArguments (TextReader reader) + { + return GetArguments (reader, false); + } + + // Cribbed from mcs/driver.cs:LoadArgs(string) + static IEnumerable GetArguments (TextReader reader, bool close) + { + try { + StringBuilder arg = new StringBuilder (); + + string line; + while ((line = reader.ReadLine ()) != null) { + int t = line.Length; + + for (int i = 0; i < t; i++) { + char c = line [i]; + + if (c == '"' || c == '\'') { + char end = c; + + for (i++; i < t; i++){ + c = line [i]; + + if (c == end) + break; + arg.Append (c); + } + } else if (c == ' ') { + if (arg.Length > 0) { + yield return arg.ToString (); + arg.Length = 0; + } + } else + arg.Append (c); + } + if (arg.Length > 0) { + yield return arg.ToString (); + arg.Length = 0; + } + } + } + finally { + if (close) + reader.Close (); + } + } + } + + public class ResponseFileSource : ArgumentSource { + + public override string[] GetNames () + { + return new string[]{"@file"}; + } + + public override string Description { + get {return "Read response file for more options.";} + } + + public override bool GetArguments (string value, out IEnumerable replacement) + { + if (string.IsNullOrEmpty (value) || !value.StartsWith ("@")) { + replacement = null; + return false; + } + replacement = ArgumentSource.GetArgumentsFromFile (value.Substring (1)); + return true; + } + } + [Serializable] public class OptionException : Exception { private string option; @@ -594,6 +680,7 @@ namespace Mono.Options public OptionSet (Converter localizer) { this.localizer = localizer; + this.roSources = new ReadOnlyCollection(sources); } Converter localizer; @@ -602,6 +689,14 @@ namespace Mono.Options get {return localizer;} } + List sources = new List (); + ReadOnlyCollection roSources; + + public ReadOnlyCollection ArgumentSources { + get {return roSources;} + } + + protected override string GetKeyForItem (Option item) { if (item == null) @@ -776,48 +871,30 @@ namespace Mono.Options return Add (new ActionOption (prototype, description, action)); } - protected virtual OptionContext CreateOptionContext () + public OptionSet Add (ArgumentSource source) { - return new OptionContext (this); + if (source == null) + throw new ArgumentNullException ("source"); + sources.Add (source); + return this; } -#if LINQ - public List Parse (IEnumerable arguments) + protected virtual OptionContext CreateOptionContext () { - bool process = true; - OptionContext c = CreateOptionContext (); - c.OptionIndex = -1; - var def = GetOptionForName ("<>"); - var unprocessed = - from argument in arguments - where ++c.OptionIndex >= 0 && (process || def != null) - ? process - ? argument == "--" - ? (process = false) - : !Parse (argument, c) - ? def != null - ? Unprocessed (null, def, c, argument) - : true - : false - : def != null - ? Unprocessed (null, def, c, argument) - : true - : true - select argument; - List r = unprocessed.ToList (); - if (c.Option != null) - c.Option.Invoke (c); - return r; + return new OptionContext (this); } -#else + public List Parse (IEnumerable arguments) { + if (arguments == null) + throw new ArgumentNullException ("arguments"); OptionContext c = CreateOptionContext (); c.OptionIndex = -1; bool process = true; List unprocessed = new List (); Option def = Contains ("<>") ? this ["<>"] : null; - foreach (string argument in arguments) { + ArgumentEnumerator ae = new ArgumentEnumerator (arguments); + foreach (string argument in ae) { ++c.OptionIndex; if (argument == "--") { process = false; @@ -827,6 +904,8 @@ namespace Mono.Options Unprocessed (unprocessed, def, c, argument); continue; } + if (AddSource (ae, argument)) + continue; if (!Parse (argument, c)) Unprocessed (unprocessed, def, c, argument); } @@ -834,7 +913,48 @@ namespace Mono.Options c.Option.Invoke (c); return unprocessed; } -#endif + + class ArgumentEnumerator : IEnumerable { + List> sources = new List> (); + + public ArgumentEnumerator (IEnumerable arguments) + { + sources.Add (arguments.GetEnumerator ()); + } + + public void Add (IEnumerable arguments) + { + sources.Add (arguments.GetEnumerator ()); + } + + public IEnumerator GetEnumerator () + { + do { + IEnumerator c = sources [sources.Count-1]; + if (c.MoveNext ()) + yield return c.Current; + else + sources.RemoveAt (sources.Count-1); + } while (sources.Count > 0); + } + + IEnumerator IEnumerable.GetEnumerator () + { + return GetEnumerator (); + } + } + + bool AddSource (ArgumentEnumerator ae, string argument) + { + foreach (ArgumentSource source in sources) { + IEnumerable replacement; + if (!source.GetArguments (argument, out replacement)) + continue; + ae.Add (replacement); + return true; + } + return false; + } private static bool Unprocessed (ICollection extra, Option def, OptionContext c, string argument) { @@ -1011,6 +1131,37 @@ namespace Mono.Options indent = true; } } + + foreach (ArgumentSource s in sources) { + string[] names = s.GetNames (); + if (names == null || names.Length == 0) + continue; + + int written = 0; + + Write (o, ref written, " "); + Write (o, ref written, names [0]); + for (int i = 1; i < names.Length; ++i) { + Write (o, ref written, ", "); + Write (o, ref written, names [i]); + } + + if (written < OptionWidth) + o.Write (new string (' ', OptionWidth - written)); + else { + o.WriteLine (); + o.Write (new string (' ', OptionWidth)); + } + + bool indent = false; + string prefix = new string (' ', OptionWidth+2); + foreach (string line in GetLines (localizer (GetDescription (s.Description)))) { + if (indent) + o.Write (prefix); + o.WriteLine (line); + indent = true; + } + } } bool WriteOptionPrototype (TextWriter o, Option p, ref int written) diff --git a/mcs/class/Mono.Options/Test/Mono.Options/OptionSetTest.cs b/mcs/class/Mono.Options/Test/Mono.Options/OptionSetTest.cs index 0d9af0be576..0d1433cdce6 100644 --- a/mcs/class/Mono.Options/Test/Mono.Options/OptionSetTest.cs +++ b/mcs/class/Mono.Options/Test/Mono.Options/OptionSetTest.cs @@ -27,6 +27,7 @@ // using System; +using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.Globalization; @@ -80,6 +81,52 @@ namespace Tests.Mono.Options public override string ToString () {return s;} } + class TestArgumentSource : ArgumentSource, IEnumerable { + string[] names; + string desc; + + public TestArgumentSource (string[] names, string desc) + { + this.names = names; + this.desc = desc; + } + + Dictionary args = new Dictionary(); + + public void Add (string key, params string[] values) + { + args.Add (key, values); + } + + public override string[] GetNames () + { + return names; + } + + public override string Description { + get {return desc;} + } + + public override bool GetArguments (string value, out IEnumerable replacement) + { + replacement = null; + + string[] values; + if (args.TryGetValue (value, out values)) { + replacement = values; + return true; + } + + return false; + } + + + IEnumerator IEnumerable.GetEnumerator () + { + return args.GetEnumerator (); + } + } + [TestFixture] public class OptionSetTest : ListContract