[Mono.Options] Add option header support.
authorJonathan Pryor <jonpryor@vt.edu>
Mon, 7 Mar 2011 00:30:48 +0000 (19:30 -0500)
committerJonathan Pryor <jonpryor@vt.edu>
Mon, 7 Mar 2011 06:59:44 +0000 (01:59 -0500)
commit419ce873554e652485b4f7a3c82ed7ac5430c609
tree486eb4dc3b90db3100cb433fc5d9858ec1a18049
parent816fb2e0ff24770267de0b6eaaac5eb57b0203ff
[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",
};
17 files changed:
data/mono-options.pc.in
mcs/class/Mono.Options/Assembly/AssemblyInfo.cs
mcs/class/Mono.Options/Documentation/en/Mono.Options/ArgumentSource.xml
mcs/class/Mono.Options/Documentation/en/Mono.Options/Option.xml
mcs/class/Mono.Options/Documentation/en/Mono.Options/OptionAction`2.xml
mcs/class/Mono.Options/Documentation/en/Mono.Options/OptionContext.xml
mcs/class/Mono.Options/Documentation/en/Mono.Options/OptionException.xml
mcs/class/Mono.Options/Documentation/en/Mono.Options/OptionSet.xml
mcs/class/Mono.Options/Documentation/en/Mono.Options/OptionValueCollection.xml
mcs/class/Mono.Options/Documentation/en/Mono.Options/OptionValueType.xml
mcs/class/Mono.Options/Documentation/en/Mono.Options/ResponseFileSource.xml
mcs/class/Mono.Options/Documentation/en/examples/bundling.cs
mcs/class/Mono.Options/Documentation/en/examples/bundling.txt
mcs/class/Mono.Options/Documentation/en/examples/greet.cs
mcs/class/Mono.Options/Documentation/en/index.xml
mcs/class/Mono.Options/Mono.Options/Options.cs
mcs/class/Mono.Options/Test/Mono.Options/OptionSetTest.cs