From: Jonathan Pryor Date: Mon, 7 Mar 2011 00:30:48 +0000 (-0500) Subject: [Mono.Options] Add option header support. X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=commitdiff_plain;h=419ce873554e652485b4f7a3c82ed7ac5430c609;p=mono.git [Mono.Options] Add option header support. Option headers can be provided via OptionSet.Add(string), and allows forgoing the use of a separate mechanism to provide contextual output. For example, one used to do this: bool show_help = false; new OptionSet { // ... { "help|h|?", v => show_help = v != null }, }.Parse (args); if (show_help) { Console.WriteLine ("usage: sample-app ARGS"); p.WriteOptionDescriptions (Console.Out); // ... } Using the new header support, the "contextual" output can be merged with the option specification: bool show_help = false; new OptionSet { "usage: sample-app ARGS", { "help|h|?", v => show_help = v != null }, }.Parse (args); if (show_help) p.WriteOptionDescriptions (Console.Out); Furthermore, headers can be provided "inline", thus serving as a mechanism to categorize options: // mcs options var p = new OptionSet { "Mono C# compiler, Copyright 2001 - 2011 Novell, Inc.", "mcs [options] source-files", // ... "Resources:", { "linkresource|linkres:", v => /* ... */ }, // ... "", "Options can be of the form -option or /option", }; --- diff --git a/data/mono-options.pc.in b/data/mono-options.pc.in index 8c569820d4e..8569ffc2efb 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.2 +Version: 0.2.3 diff --git a/mcs/class/Mono.Options/Assembly/AssemblyInfo.cs b/mcs/class/Mono.Options/Assembly/AssemblyInfo.cs index 281d53b44f9..fa9c43f3772 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.2.0" + "0.2.3.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 index 83d92060659..0e7d0c54462 100644 --- a/mcs/class/Mono.Options/Documentation/en/Mono.Options/ArgumentSource.xml +++ b/mcs/class/Mono.Options/Documentation/en/Mono.Options/ArgumentSource.xml @@ -4,6 +4,7 @@ Mono.Options 0.2.2.0 + 0.2.3.0 System.Object @@ -48,6 +49,7 @@ Constructor 0.2.2.0 + 0.2.3.0 @@ -65,6 +67,7 @@ Property 0.2.2.0 + 0.2.3.0 System.String @@ -89,6 +92,7 @@ Method 0.2.2.0 + 0.2.3.0 System.Collections.Generic.IEnumerable<System.String> @@ -128,6 +132,7 @@ Method 0.2.2.0 + 0.2.3.0 System.Boolean @@ -182,6 +187,7 @@ Method 0.2.2.0 + 0.2.3.0 System.Collections.Generic.IEnumerable<System.String> @@ -215,6 +221,7 @@ Method 0.2.2.0 + 0.2.3.0 System.String[] 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 46f5e241e9e..661c9a51b79 100644 --- a/mcs/class/Mono.Options/Documentation/en/Mono.Options/Option.xml +++ b/mcs/class/Mono.Options/Documentation/en/Mono.Options/Option.xml @@ -6,6 +6,7 @@ 0.2.0.0 0.2.1.0 0.2.2.0 + 0.2.3.0 All members of this type are safe for multithreaded operations. @@ -94,6 +95,7 @@ 0.2.0.0 0.2.1.0 0.2.2.0 + 0.2.3.0 @@ -164,6 +166,7 @@ 0.2.0.0 0.2.1.0 0.2.2.0 + 0.2.3.0 @@ -360,6 +363,7 @@ 0.2.0.0 0.2.1.0 0.2.2.0 + 0.2.3.0 System.String @@ -393,6 +397,7 @@ 0.2.0.0 0.2.1.0 0.2.2.0 + 0.2.3.0 System.String[] @@ -423,6 +428,7 @@ 0.2.0.0 0.2.1.0 0.2.2.0 + 0.2.3.0 System.String[] @@ -474,6 +480,7 @@ 0.2.0.0 0.2.1.0 0.2.2.0 + 0.2.3.0 System.Void @@ -527,6 +534,7 @@ 0.2.0.0 0.2.1.0 0.2.2.0 + 0.2.3.0 System.Int32 @@ -566,6 +574,7 @@ 0.2.0.0 0.2.1.0 0.2.2.0 + 0.2.3.0 System.Void @@ -754,6 +763,7 @@ class Demo { 0.2.0.0 0.2.1.0 0.2.2.0 + 0.2.3.0 Mono.Options.OptionValueType @@ -784,6 +794,7 @@ class Demo { 0.2.0.0 0.2.1.0 0.2.2.0 + 0.2.3.0 T @@ -845,6 +856,7 @@ class Demo { 0.2.0.0 0.2.1.0 0.2.2.0 + 0.2.3.0 System.String @@ -880,6 +892,7 @@ class Demo { 0.2.0.0 0.2.1.0 0.2.2.0 + 0.2.3.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 0fbd6ce3d7b..e5b4b073e16 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 @@ -6,6 +6,7 @@ 0.2.0.0 0.2.1.0 0.2.2.0 + 0.2.3.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 96262f7702d..bac394cc090 100644 --- a/mcs/class/Mono.Options/Documentation/en/Mono.Options/OptionContext.xml +++ b/mcs/class/Mono.Options/Documentation/en/Mono.Options/OptionContext.xml @@ -6,6 +6,7 @@ 0.2.0.0 0.2.1.0 0.2.2.0 + 0.2.3.0 System.Object @@ -30,6 +31,7 @@ 0.2.0.0 0.2.1.0 0.2.2.0 + 0.2.3.0 @@ -56,6 +58,7 @@ 0.2.0.0 0.2.1.0 0.2.2.0 + 0.2.3.0 Mono.Options.Option @@ -75,6 +78,7 @@ 0.2.0.0 0.2.1.0 0.2.2.0 + 0.2.3.0 System.Int32 @@ -102,6 +106,7 @@ 0.2.0.0 0.2.1.0 0.2.2.0 + 0.2.3.0 System.String @@ -125,6 +130,7 @@ 0.2.0.0 0.2.1.0 0.2.2.0 + 0.2.3.0 Mono.Options.OptionSet @@ -155,6 +161,7 @@ 0.2.0.0 0.2.1.0 0.2.2.0 + 0.2.3.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 5ebfb683fd6..f47db8ba357 100644 --- a/mcs/class/Mono.Options/Documentation/en/Mono.Options/OptionException.xml +++ b/mcs/class/Mono.Options/Documentation/en/Mono.Options/OptionException.xml @@ -6,6 +6,7 @@ 0.2.0.0 0.2.1.0 0.2.2.0 + 0.2.3.0 System.Exception @@ -51,6 +52,7 @@ 0.2.1.0 0.2.2.0 + 0.2.3.0 @@ -66,6 +68,7 @@ 0.2.0.0 0.2.1.0 0.2.2.0 + 0.2.3.0 @@ -102,6 +105,7 @@ 0.2.0.0 0.2.1.0 0.2.2.0 + 0.2.3.0 @@ -136,6 +140,7 @@ 0.2.0.0 0.2.1.0 0.2.2.0 + 0.2.3.0 @@ -179,6 +184,7 @@ 0.2.0.0 0.2.1.0 0.2.2.0 + 0.2.3.0 System.Void @@ -219,6 +225,7 @@ 0.2.0.0 0.2.1.0 0.2.2.0 + 0.2.3.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 90fc5ee9d2a..bddc27c5b67 100644 --- a/mcs/class/Mono.Options/Documentation/en/Mono.Options/OptionSet.xml +++ b/mcs/class/Mono.Options/Documentation/en/Mono.Options/OptionSet.xml @@ -6,6 +6,7 @@ 0.2.0.0 0.2.1.0 0.2.2.0 + 0.2.3.0 All public static members of this type are safe for multithreaded @@ -54,6 +55,13 @@ Response files, as used by mcs and other compiler tools, may be supported by using . + + "Headers" -- string constants which allow grouping of options in the + output of + + -- may be provided "inline" with the actual options. The greet + example below shows such usage. + Three conditions must be met for a sequence of arguments to be considered as a match for an : @@ -291,7 +299,7 @@ - The following example demonstrates some simple usage of + The following greet example demonstrates some simple usage of . using System; @@ -308,6 +316,11 @@ class Test { int repeat = 1; var p = new OptionSet () { + "Usage: greet [OPTIONS]+ message", + "Greet a list of individuals with an optional message.", + "If no message is specified, a generic greeting is used.", + "", + "Options:", { "n|name=", "the {NAME} of someone to greet.", v => names.Add (v) }, { "r|repeat=", @@ -332,7 +345,7 @@ class Test { } if (show_help) { - ShowHelp (p); + p.WriteOptionDescriptions (Console.Out); return; } @@ -352,16 +365,6 @@ class Test { } } - static void ShowHelp (OptionSet p) - { - Console.WriteLine ("Usage: greet [OPTIONS]+ message"); - Console.WriteLine ("Greet a list of individuals with an optional message."); - Console.WriteLine ("If no message is specified, a generic greeting is used."); - Console.WriteLine (); - Console.WriteLine ("Options:"); - p.WriteOptionDescriptions (Console.Out); - } - static void Debug (string format, params object[] args) { if (verbosity > 0) { @@ -455,7 +458,10 @@ class Test { string color = null; var p = new OptionSet () { - // gcc-like options + "Usage: bundling [OPTIONS]+", + "Demo program to show the effects of bundling options and their values", + "", + "gcc-like options:", { "D:", "Predefine a macro with an (optional) value.", (m, v) => { if (m == null) @@ -467,17 +473,20 @@ class Test { (m, v) => macros.Add (m, v) }, { "o=", "Specify the output file", v => output = v }, - // tar-like options + "", + "tar-like options:", { "f=", "The input file", v => input = v }, { "x", "Extract the file", v => extract = v != null }, { "c", "Create the file", v => create = v != null }, { "t", "List the file", v => list = v != null }, - // ls-like optional values + "", + "ls-like optional values:", { "color:", "control whether and when color is used", v => color = v }, - // other... + "", + "other:", { "h|help", "show this message and exit", v => show_help = v != null }, // default @@ -496,7 +505,7 @@ class Test { } if (show_help) { - ShowHelp (p); + p.WriteOptionDescriptions (Console.Out); return; } @@ -512,15 +521,6 @@ class Test { Console.WriteLine ("\t List: {0}", list); Console.WriteLine ("\t Color: {0}", color ?? "<null>"); } - - static void ShowHelp (OptionSet p) - { - Console.WriteLine ("Usage: bundling [OPTIONS]+"); - Console.WriteLine ("Demo program to show the effects of bundling options and their values"); - Console.WriteLine (); - Console.WriteLine ("Options:"); - p.WriteOptionDescriptions (Console.Out); - } } @@ -531,15 +531,21 @@ class Test { Usage: bundling [OPTIONS]+ Demo program to show the effects of bundling options and their values -Options: +gcc-like options: -D[=VALUE1:VALUE2] Predefine a macro with an (optional) value. -d=VALUE1-->VALUE2 Alternate macro syntax. -o=VALUE Specify the output file + +tar-like options: -f=VALUE The input file -x Extract the file -c Create the file -t List the file + +ls-like optional values: --color[=VALUE] control whether and when color is used + +other: -h, --help show this message and exit $ mono bundling.exe -D @@ -830,6 +836,7 @@ Key: a\b\c=d\e\f 0.2.0.0 0.2.1.0 0.2.2.0 + 0.2.3.0 @@ -856,6 +863,7 @@ Key: a\b\c=d\e\f 0.2.0.0 0.2.1.0 0.2.2.0 + 0.2.3.0 @@ -1026,6 +1034,7 @@ localization: hello:Could not convert string `not-an-int' to type Int32 for opti Method 0.2.2.0 + 0.2.3.0 Mono.Options.OptionSet @@ -1062,6 +1071,7 @@ localization: hello:Could not convert string `not-an-int' to type Int32 for opti 0.2.0.0 0.2.1.0 0.2.2.0 + 0.2.3.0 Mono.Options.OptionSet @@ -1099,6 +1109,41 @@ localization: hello:Could not convert string `not-an-int' to type Int32 for opti + + + + Method + + 0.2.3.0 + + + Mono.Options.OptionSet + + + + + + + A containing the header to display + during . + + + Declare a header to be printed during + . + + + The current instance. + This is to permit method chaining. + + + + The Add(string) method can be used to provide option groupin + in the output generatedy by + . + + + + @@ -1107,6 +1152,7 @@ localization: hello:Could not convert string `not-an-int' to type Int32 for opti 0.2.0.0 0.2.1.0 0.2.2.0 + 0.2.3.0 Mono.Options.OptionSet @@ -1168,6 +1214,7 @@ localization: hello:Could not convert string `not-an-int' to type Int32 for opti 0.2.0.0 0.2.1.0 0.2.2.0 + 0.2.3.0 Mono.Options.OptionSet @@ -1229,6 +1276,7 @@ localization: hello:Could not convert string `not-an-int' to type Int32 for opti 0.2.0.0 0.2.1.0 0.2.2.0 + 0.2.3.0 Mono.Options.OptionSet @@ -1300,6 +1348,7 @@ localization: hello:Could not convert string `not-an-int' to type Int32 for opti 0.2.0.0 0.2.1.0 0.2.2.0 + 0.2.3.0 Mono.Options.OptionSet @@ -1361,6 +1410,7 @@ localization: hello:Could not convert string `not-an-int' to type Int32 for opti 0.2.0.0 0.2.1.0 0.2.2.0 + 0.2.3.0 Mono.Options.OptionSet @@ -1422,6 +1472,7 @@ localization: hello:Could not convert string `not-an-int' to type Int32 for opti 0.2.0.0 0.2.1.0 0.2.2.0 + 0.2.3.0 Mono.Options.OptionSet @@ -1517,6 +1568,7 @@ localization: hello:Could not convert string `not-an-int' to type Int32 for opti 0.2.0.0 0.2.1.0 0.2.2.0 + 0.2.3.0 Mono.Options.OptionSet @@ -1590,6 +1642,7 @@ localization: hello:Could not convert string `not-an-int' to type Int32 for opti 0.2.0.0 0.2.1.0 0.2.2.0 + 0.2.3.0 Mono.Options.OptionSet @@ -1674,6 +1727,7 @@ localization: hello:Could not convert string `not-an-int' to type Int32 for opti Property 0.2.2.0 + 0.2.3.0 System.Collections.ObjectModel.ReadOnlyCollection<Mono.Options.ArgumentSource> @@ -1703,6 +1757,7 @@ localization: hello:Could not convert string `not-an-int' to type Int32 for opti 0.2.0.0 0.2.1.0 0.2.2.0 + 0.2.3.0 Mono.Options.OptionContext @@ -1742,6 +1797,7 @@ localization: hello:Could not convert string `not-an-int' to type Int32 for opti 0.2.1.0 0.2.2.0 + 0.2.3.0 System.String @@ -1794,6 +1850,7 @@ localization: hello:Could not convert string `not-an-int' to type Int32 for opti 0.2.0.0 0.2.1.0 0.2.2.0 + 0.2.3.0 @@ -1842,6 +1899,7 @@ localization: hello:Could not convert string `not-an-int' to type Int32 for opti 0.2.0.0 0.2.1.0 0.2.2.0 + 0.2.3.0 System.Boolean @@ -1936,6 +1994,7 @@ localization: hello:Could not convert string `not-an-int' to type Int32 for opti 0.2.0.0 0.2.1.0 0.2.2.0 + 0.2.3.0 System.Void @@ -1968,6 +2027,7 @@ localization: hello:Could not convert string `not-an-int' to type Int32 for opti 0.2.0.0 0.2.1.0 0.2.2.0 + 0.2.3.0 System.Converter<System.String,System.String> @@ -1999,6 +2059,7 @@ localization: hello:Could not convert string `not-an-int' to type Int32 for opti 0.2.0.0 0.2.1.0 0.2.2.0 + 0.2.3.0 System.Collections.Generic.List<System.String> @@ -2104,6 +2165,11 @@ class Test { int repeat = 1; var p = new OptionSet () { + "Usage: greet [OPTIONS]+ message", + "Greet a list of individuals with an optional message.", + "If no message is specified, a generic greeting is used.", + "", + "Options:", { "n|name=", "the {NAME} of someone to greet.", v => names.Add (v) }, { "r|repeat=", @@ -2128,7 +2194,7 @@ class Test { } if (show_help) { - ShowHelp (p); + p.WriteOptionDescriptions (Console.Out); return; } @@ -2148,16 +2214,6 @@ class Test { } } - static void ShowHelp (OptionSet p) - { - Console.WriteLine ("Usage: greet [OPTIONS]+ message"); - Console.WriteLine ("Greet a list of individuals with an optional message."); - Console.WriteLine ("If no message is specified, a generic greeting is used."); - Console.WriteLine (); - Console.WriteLine ("Options:"); - p.WriteOptionDescriptions (Console.Out); - } - static void Debug (string format, params object[] args) { if (verbosity > 0) { @@ -2179,6 +2235,7 @@ class Test { 0.2.0.0 0.2.1.0 0.2.2.0 + 0.2.3.0 System.Boolean @@ -2276,6 +2333,7 @@ class Test { 0.2.0.0 0.2.1.0 0.2.2.0 + 0.2.3.0 System.Void @@ -2304,6 +2362,7 @@ class Test { 0.2.0.0 0.2.1.0 0.2.2.0 + 0.2.3.0 System.Void @@ -2338,6 +2397,7 @@ class Test { 0.2.0.0 0.2.1.0 0.2.2.0 + 0.2.3.0 System.Void @@ -2411,6 +2471,11 @@ class Test { int repeat = 1; var p = new OptionSet () { + "Usage: greet [OPTIONS]+ message", + "Greet a list of individuals with an optional message.", + "If no message is specified, a generic greeting is used.", + "", + "Options:", { "n|name=", "the {NAME} of someone to greet.", v => names.Add (v) }, { "r|repeat=", @@ -2435,7 +2500,7 @@ class Test { } if (show_help) { - ShowHelp (p); + p.WriteOptionDescriptions (Console.Out); return; } @@ -2455,16 +2520,6 @@ class Test { } } - static void ShowHelp (OptionSet p) - { - Console.WriteLine ("Usage: greet [OPTIONS]+ message"); - Console.WriteLine ("Greet a list of individuals with an optional message."); - Console.WriteLine ("If no message is specified, a generic greeting is used."); - Console.WriteLine (); - Console.WriteLine ("Options:"); - p.WriteOptionDescriptions (Console.Out); - } - static void Debug (string format, params object[] args) { if (verbosity > 0) { 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 eb98dc99a67..070daace68c 100644 --- a/mcs/class/Mono.Options/Documentation/en/Mono.Options/OptionValueCollection.xml +++ b/mcs/class/Mono.Options/Documentation/en/Mono.Options/OptionValueCollection.xml @@ -6,6 +6,7 @@ 0.2.0.0 0.2.1.0 0.2.2.0 + 0.2.3.0 System.Object @@ -64,6 +65,7 @@ 0.2.0.0 0.2.1.0 0.2.2.0 + 0.2.3.0 System.Void @@ -85,6 +87,7 @@ 0.2.0.0 0.2.1.0 0.2.2.0 + 0.2.3.0 System.Void @@ -103,6 +106,7 @@ 0.2.0.0 0.2.1.0 0.2.2.0 + 0.2.3.0 System.Boolean @@ -125,6 +129,7 @@ 0.2.0.0 0.2.1.0 0.2.2.0 + 0.2.3.0 System.Void @@ -148,6 +153,7 @@ 0.2.0.0 0.2.1.0 0.2.2.0 + 0.2.3.0 System.Int32 @@ -166,6 +172,7 @@ 0.2.0.0 0.2.1.0 0.2.2.0 + 0.2.3.0 System.Collections.Generic.IEnumerator<System.String> @@ -185,6 +192,7 @@ 0.2.0.0 0.2.1.0 0.2.2.0 + 0.2.3.0 System.Int32 @@ -207,6 +215,7 @@ 0.2.0.0 0.2.1.0 0.2.2.0 + 0.2.3.0 System.Void @@ -230,6 +239,7 @@ 0.2.0.0 0.2.1.0 0.2.2.0 + 0.2.3.0 System.Boolean @@ -248,6 +258,7 @@ 0.2.0.0 0.2.1.0 0.2.2.0 + 0.2.3.0 System.String @@ -270,6 +281,7 @@ 0.2.0.0 0.2.1.0 0.2.2.0 + 0.2.3.0 System.Boolean @@ -292,6 +304,7 @@ 0.2.0.0 0.2.1.0 0.2.2.0 + 0.2.3.0 System.Void @@ -313,6 +326,7 @@ 0.2.0.0 0.2.1.0 0.2.2.0 + 0.2.3.0 System.Void @@ -336,6 +350,7 @@ 0.2.0.0 0.2.1.0 0.2.2.0 + 0.2.3.0 System.Boolean @@ -354,6 +369,7 @@ 0.2.0.0 0.2.1.0 0.2.2.0 + 0.2.3.0 System.Object @@ -372,6 +388,7 @@ 0.2.0.0 0.2.1.0 0.2.2.0 + 0.2.3.0 System.Collections.IEnumerator @@ -391,6 +408,7 @@ 0.2.0.0 0.2.1.0 0.2.2.0 + 0.2.3.0 System.Int32 @@ -413,6 +431,7 @@ 0.2.0.0 0.2.1.0 0.2.2.0 + 0.2.3.0 System.Boolean @@ -435,6 +454,7 @@ 0.2.0.0 0.2.1.0 0.2.2.0 + 0.2.3.0 System.Int32 @@ -457,6 +477,7 @@ 0.2.0.0 0.2.1.0 0.2.2.0 + 0.2.3.0 System.Void @@ -480,6 +501,7 @@ 0.2.0.0 0.2.1.0 0.2.2.0 + 0.2.3.0 System.Boolean @@ -498,6 +520,7 @@ 0.2.0.0 0.2.1.0 0.2.2.0 + 0.2.3.0 System.Object @@ -520,6 +543,7 @@ 0.2.0.0 0.2.1.0 0.2.2.0 + 0.2.3.0 System.Void @@ -541,6 +565,7 @@ 0.2.0.0 0.2.1.0 0.2.2.0 + 0.2.3.0 System.Void @@ -562,6 +587,7 @@ 0.2.0.0 0.2.1.0 0.2.2.0 + 0.2.3.0 System.String[] @@ -581,6 +607,7 @@ 0.2.0.0 0.2.1.0 0.2.2.0 + 0.2.3.0 System.Collections.Generic.List<System.String> @@ -600,6 +627,7 @@ 0.2.0.0 0.2.1.0 0.2.2.0 + 0.2.3.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 aa035c500d6..c16f5608f27 100644 --- a/mcs/class/Mono.Options/Documentation/en/Mono.Options/OptionValueType.xml +++ b/mcs/class/Mono.Options/Documentation/en/Mono.Options/OptionValueType.xml @@ -6,6 +6,7 @@ 0.2.0.0 0.2.1.0 0.2.2.0 + 0.2.3.0 System.Enum @@ -28,6 +29,7 @@ 0.2.0.0 0.2.1.0 0.2.2.0 + 0.2.3.0 Mono.Options.OptionValueType @@ -51,6 +53,7 @@ 0.2.0.0 0.2.1.0 0.2.2.0 + 0.2.3.0 Mono.Options.OptionValueType @@ -79,6 +82,7 @@ 0.2.0.0 0.2.1.0 0.2.2.0 + 0.2.3.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 index f97cb570494..566f4a3fcda 100644 --- a/mcs/class/Mono.Options/Documentation/en/Mono.Options/ResponseFileSource.xml +++ b/mcs/class/Mono.Options/Documentation/en/Mono.Options/ResponseFileSource.xml @@ -4,6 +4,7 @@ Mono.Options 0.2.2.0 + 0.2.3.0 Mono.Options.ArgumentSource @@ -28,6 +29,7 @@ Constructor 0.2.2.0 + 0.2.3.0 @@ -45,6 +47,7 @@ Property 0.2.2.0 + 0.2.3.0 System.String @@ -67,6 +70,7 @@ Method 0.2.2.0 + 0.2.3.0 System.Boolean @@ -112,6 +116,7 @@ Method 0.2.2.0 + 0.2.3.0 System.String[] diff --git a/mcs/class/Mono.Options/Documentation/en/examples/bundling.cs b/mcs/class/Mono.Options/Documentation/en/examples/bundling.cs index b13ebbc5574..4694128671b 100644 --- a/mcs/class/Mono.Options/Documentation/en/examples/bundling.cs +++ b/mcs/class/Mono.Options/Documentation/en/examples/bundling.cs @@ -13,7 +13,10 @@ class Test { string color = null; var p = new OptionSet () { - // gcc-like options + "Usage: bundling [OPTIONS]+", + "Demo program to show the effects of bundling options and their values", + "", + "gcc-like options:", { "D:", "Predefine a macro with an (optional) value.", (m, v) => { if (m == null) @@ -25,17 +28,20 @@ class Test { (m, v) => macros.Add (m, v) }, { "o=", "Specify the output file", v => output = v }, - // tar-like options + "", + "tar-like options:", { "f=", "The input file", v => input = v }, { "x", "Extract the file", v => extract = v != null }, { "c", "Create the file", v => create = v != null }, { "t", "List the file", v => list = v != null }, - // ls-like optional values + "", + "ls-like optional values:", { "color:", "control whether and when color is used", v => color = v }, - // other... + "", + "other:", { "h|help", "show this message and exit", v => show_help = v != null }, // default @@ -54,7 +60,7 @@ class Test { } if (show_help) { - ShowHelp (p); + p.WriteOptionDescriptions (Console.Out); return; } @@ -70,14 +76,5 @@ class Test { Console.WriteLine ("\t List: {0}", list); Console.WriteLine ("\t Color: {0}", color ?? ""); } - - static void ShowHelp (OptionSet p) - { - Console.WriteLine ("Usage: bundling [OPTIONS]+"); - Console.WriteLine ("Demo program to show the effects of bundling options and their values"); - Console.WriteLine (); - Console.WriteLine ("Options:"); - p.WriteOptionDescriptions (Console.Out); - } } diff --git a/mcs/class/Mono.Options/Documentation/en/examples/bundling.txt b/mcs/class/Mono.Options/Documentation/en/examples/bundling.txt index 034a6bea146..0ef6432f6d1 100644 --- a/mcs/class/Mono.Options/Documentation/en/examples/bundling.txt +++ b/mcs/class/Mono.Options/Documentation/en/examples/bundling.txt @@ -2,15 +2,21 @@ $ mono bundling.exe --help Usage: bundling [OPTIONS]+ Demo program to show the effects of bundling options and their values -Options: +gcc-like options: -D[=VALUE1:VALUE2] Predefine a macro with an (optional) value. -d=VALUE1-->VALUE2 Alternate macro syntax. -o=VALUE Specify the output file + +tar-like options: -f=VALUE The input file -x Extract the file -c Create the file -t List the file + +ls-like optional values: --color[=VALUE] control whether and when color is used + +other: -h, --help show this message and exit $ mono bundling.exe -D diff --git a/mcs/class/Mono.Options/Documentation/en/examples/greet.cs b/mcs/class/Mono.Options/Documentation/en/examples/greet.cs index 6327862fa4e..129228bbea0 100644 --- a/mcs/class/Mono.Options/Documentation/en/examples/greet.cs +++ b/mcs/class/Mono.Options/Documentation/en/examples/greet.cs @@ -12,6 +12,11 @@ class Test { int repeat = 1; var p = new OptionSet () { + "Usage: greet [OPTIONS]+ message", + "Greet a list of individuals with an optional message.", + "If no message is specified, a generic greeting is used.", + "", + "Options:", { "n|name=", "the {NAME} of someone to greet.", v => names.Add (v) }, { "r|repeat=", @@ -36,7 +41,7 @@ class Test { } if (show_help) { - ShowHelp (p); + p.WriteOptionDescriptions (Console.Out); return; } @@ -56,16 +61,6 @@ class Test { } } - static void ShowHelp (OptionSet p) - { - Console.WriteLine ("Usage: greet [OPTIONS]+ message"); - Console.WriteLine ("Greet a list of individuals with an optional message."); - Console.WriteLine ("If no message is specified, a generic greeting is used."); - Console.WriteLine (); - Console.WriteLine ("Options:"); - p.WriteOptionDescriptions (Console.Out); - } - static void Debug (string format, params object[] args) { if (verbosity > 0) { diff --git a/mcs/class/Mono.Options/Documentation/en/index.xml b/mcs/class/Mono.Options/Documentation/en/index.xml index 81b20539176..00061a953b0 100644 --- a/mcs/class/Mono.Options/Documentation/en/index.xml +++ b/mcs/class/Mono.Options/Documentation/en/index.xml @@ -3,7 +3,7 @@ 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 ] diff --git a/mcs/class/Mono.Options/Mono.Options/Options.cs b/mcs/class/Mono.Options/Mono.Options/Options.cs index ecba10ba176..c8385271f9d 100644 --- a/mcs/class/Mono.Options/Mono.Options/Options.cs +++ b/mcs/class/Mono.Options/Mono.Options/Options.cs @@ -388,9 +388,17 @@ namespace Mono.Options throw new ArgumentOutOfRangeException ("maxValueCount"); this.prototype = prototype; - this.names = prototype.Split ('|'); this.description = description; this.count = maxValueCount; + this.names = (this is OptionSet.Category) + // append GetHashCode() so that "duplicate" categories have distinct + // names, e.g. adding multiple "" categories should be valid. + ? new[]{prototype + this.GetHashCode ()} + : prototype.Split ('|'); + + if (this is OptionSet.Category) + return; + this.type = ParsePrototype (); if (this.count == 0 && type != OptionValueType.None) @@ -762,6 +770,31 @@ namespace Mono.Options } } + public OptionSet Add (string header) + { + if (header == null) + throw new ArgumentNullException ("header"); + Add (new Category (header)); + return this; + } + + internal sealed class Category : Option { + + // Prototype starts with '=' because this is an invalid prototype + // (see Option.ParsePrototype(), and thus it'll prevent Category + // instances from being accidentally used as normal options. + public Category (string description) + : base ("=:Category:= " + description, description) + { + } + + protected override void OnParseComplete (OptionContext c) + { + throw new NotSupportedException ("Category.OnParseComplete should not be invoked."); + } + } + + public new OptionSet Add (Option option) { base.Add (option); @@ -1109,11 +1142,20 @@ namespace Mono.Options } private const int OptionWidth = 29; + private const int Description_FirstWidth = 80 - OptionWidth; + private const int Description_RemWidth = 80 - OptionWidth - 2; public void WriteOptionDescriptions (TextWriter o) { foreach (Option p in this) { int written = 0; + + Category c = p as Category; + if (c != null) { + WriteDescription (o, p.Description, "", 80, 80); + continue; + } + if (!WriteOptionPrototype (o, p, ref written)) continue; @@ -1124,14 +1166,8 @@ namespace Mono.Options o.Write (new string (' ', OptionWidth)); } - bool indent = false; - string prefix = new string (' ', OptionWidth+2); - foreach (string line in GetLines (localizer (GetDescription (p.Description)))) { - if (indent) - o.Write (prefix); - o.WriteLine (line); - indent = true; - } + WriteDescription (o, p.Description, new string (' ', OptionWidth+2), + Description_FirstWidth, Description_RemWidth); } foreach (ArgumentSource s in sources) { @@ -1155,14 +1191,19 @@ namespace Mono.Options 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; - } + WriteDescription (o, s.Description, new string (' ', OptionWidth+2), + Description_FirstWidth, Description_RemWidth); + } + } + + void WriteDescription (TextWriter o, string value, string prefix, int firstWidth, int remWidth) + { + bool indent = false; + foreach (string line in GetLines (localizer (GetDescription (value)), firstWidth, remWidth)) { + if (indent) + o.Write (prefix); + o.WriteLine (line); + indent = true; } } @@ -1289,11 +1330,9 @@ namespace Mono.Options return sb.ToString (); } - private static IEnumerable GetLines (string description) + private static IEnumerable GetLines (string description, int firstWidth, int remWidth) { - return StringCoda.WrappedLines (description, - 80 - OptionWidth, - 80 - OptionWidth - 2); + return StringCoda.WrappedLines (description, firstWidth, remWidth); } } } diff --git a/mcs/class/Mono.Options/Test/Mono.Options/OptionSetTest.cs b/mcs/class/Mono.Options/Test/Mono.Options/OptionSetTest.cs index 0d1433cdce6..b012fed03f5 100644 --- a/mcs/class/Mono.Options/Test/Mono.Options/OptionSetTest.cs +++ b/mcs/class/Mono.Options/Test/Mono.Options/OptionSetTest.cs @@ -356,6 +356,9 @@ namespace Tests.Mono.Options Utils.AssertException (typeof(ArgumentNullException), "Argument cannot be null.\nParameter name: option", p, v => { v.Add ((Option) null); }); + Utils.AssertException (typeof(ArgumentNullException), + "Argument cannot be null.\nParameter name: header", + p, v => { v.Add ((string) null); }); // bad type Utils.AssertException (typeof(OptionException), @@ -382,6 +385,7 @@ namespace Tests.Mono.Options public void WriteOptionDescriptions () { var p = new OptionSet () { + "\n:Category 1:", { "p|indicator-style=", "append / indicator to directories", v => {} }, { "color:", "controls color info", v => {} }, { "color2:", "set {color}", v => {} }, @@ -407,10 +411,14 @@ namespace Tests.Mono.Options { "long-desc5", "Lots of spaces in the middle - . - . - . - . - . - . - . - and more until the end.", v => {} }, + "", + "==This is a really long category name which will involve line wrapping, just because...==", { "o|out=", "The {DIRECTORY} to place the generated files and directories.\n\n" + "If not specified, defaults to\n`dirname FILE`/cache/`basename FILE .tree`.", v => {} }, + "", + "Category 3:", { "h|?|help", "show help text", v => {} }, { "version", "output version information and exit", v => {} }, { "<>", v => {} }, @@ -418,6 +426,8 @@ namespace Tests.Mono.Options }; StringWriter expected = new StringWriter (); + expected.WriteLine (""); + expected.WriteLine (":Category 1:"); expected.WriteLine (" -p, --indicator-style=VALUE"); expected.WriteLine (" append / indicator to directories"); expected.WriteLine (" --color[=VALUE] controls color info"); @@ -441,11 +451,16 @@ namespace Tests.Mono.Options expected.WriteLine (" 2 3 4 5 and more until the end."); expected.WriteLine (" --long-desc5 Lots of spaces in the middle - . - . - . - . - . -"); expected.WriteLine (" . - . - and more until the end."); + expected.WriteLine (""); + expected.WriteLine ("==This is a really long category name which will involve line wrapping, just"); + expected.WriteLine ("because...=="); expected.WriteLine (" -o, --out=DIRECTORY The DIRECTORY to place the generated files and"); expected.WriteLine (" directories."); expected.WriteLine (" "); expected.WriteLine (" If not specified, defaults to"); expected.WriteLine (" `dirname FILE`/cache/`basename FILE .tree`."); + expected.WriteLine (""); + expected.WriteLine ("Category 3:"); expected.WriteLine (" -h, -?, --help show help text"); expected.WriteLine (" --version output version information and exit"); expected.WriteLine (" @s1, @s2 Read Response File for More Options");