Imported Upstream version 5.2.0.175

Former-commit-id: bb0468d0f257ff100aa895eb5fe583fb5dfbf900
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2017-06-07 13:16:24 +00:00
parent 4bdbaf4a88
commit 966bba02bb
8776 changed files with 346420 additions and 149650 deletions

View File

@@ -0,0 +1,78 @@
// Sub-commands with Mono.Options.CommandSet
//
// Compile as:
// mcs -r:Mono.Options.dll commands.cs
using System;
using System.Collections.Generic;
using Mono.Options;
class CommandDemo {
public static int Main (string[] args)
{
var commands = new CommandSet ("commands") {
"usage: commands COMMAND [OPTIONS]",
"",
"Mono.Options.CommandSet sample app.",
"",
"Global options:",
{ "v:",
"Output verbosity.",
(int? n) => Verbosity = n.HasValue ? n.Value : Verbosity + 1 },
"",
"Available commands:",
new Command ("echo", "Echo arguments to the screen") {
Run = ca => Console.WriteLine ("{0}", string.Join (" ", ca)),
},
new RequiresArgs (),
};
return commands.Run (args);
}
public static int Verbosity;
}
class RequiresArgs : Command {
public RequiresArgs ()
: base ("requires-args", "Class-based Command subclass")
{
Options = new OptionSet () {
"usage: commands requires-args [OPTIONS]",
"",
"Class-based Command subclass example.",
{ "name|n=",
"{name} of person to greet.",
v => Name = v },
{ "help|h|?",
"Show this message and exit.",
v => ShowHelp = v != null },
};
}
public bool ShowHelp {get; private set;}
public new string Name {get; private set;}
public override int Invoke (IEnumerable<string> args)
{
try {
var extra = Options.Parse (args);
if (ShowHelp) {
Options.WriteOptionDescriptions (CommandSet.Out);
return 0;
}
if (string.IsNullOrEmpty (Name)) {
Console.Error.WriteLine ("commands: Missing required argument `--name=NAME`.");
Console.Error.WriteLine ("commands: Use `commands help requires-args` for details.");
return 1;
}
Console.WriteLine ($"Hello, {Name}!");
return 0;
}
catch (Exception e) {
Console.Error.WriteLine ("commands: {0}", CommandDemo.Verbosity >= 1 ? e.ToString () : e.Message);
return 1;
}
}
}

View File

@@ -0,0 +1,25 @@
mono Documentation/en/examples/commands.exe
mono Documentation/en/examples/commands.exe --help
mono Documentation/en/examples/commands.exe help
mono Documentation/en/examples/commands.exe help --help
mono Documentation/en/examples/commands.exe help echo
mono Documentation/en/examples/commands.exe echo --help
mono Documentation/en/examples/commands.exe echo hello, world
mono Documentation/en/examples/commands.exe requires-args
mono Documentation/en/examples/commands.exe help requires-args
mono Documentation/en/examples/commands.exe requires-args --help
mono Documentation/en/examples/commands.exe requires-args -n World
mono Documentation/en/examples/commands.exe invalid-command
mono Documentation/en/examples/commands.exe help invalid-command

View File

@@ -0,0 +1,74 @@
$ mono commands.exe
Use `commands help` for usage.
$ mono commands.exe --help
usage: commands COMMAND [OPTIONS]
Mono.Options.CommandSet sample app.
Global options:
-v[=VALUE] Output verbosity.
Available commands:
echo Echo arguments to the screen
requires-args Class-based Command subclass
$ mono commands.exe help
usage: commands COMMAND [OPTIONS]
Mono.Options.CommandSet sample app.
Global options:
-v[=VALUE] Output verbosity.
Available commands:
echo Echo arguments to the screen
requires-args Class-based Command subclass
$ mono commands.exe help --help
Usage: commands COMMAND [OPTIONS]
Use `commands help COMMAND` for help on a specific command.
Available commands:
echo Echo arguments to the screen
requires-args Class-based Command subclass
help Show this message and exit
$ mono commands.exe help echo
--help
$ mono commands.exe echo --help
--help
$ mono commands.exe echo hello, world
hello, world
$ mono commands.exe requires-args
commands: Missing required argument `--name=NAME`.
commands: Use `commands help requires-args` for details.
$ mono commands.exe help requires-args
usage: commands requires-args [OPTIONS]
Class-based Command subclass example.
--name, -n=name name of person to greet.
--help, -h, -? Show this message and exit.
$ mono commands.exe requires-args --help
usage: commands requires-args [OPTIONS]
Class-based Command subclass example.
--name, -n=name name of person to greet.
--help, -h, -? Show this message and exit.
$ mono commands.exe requires-args -n World
Hello, World!
$ mono commands.exe invalid-command
commands: Unknown command: invalid-command
commands: Use `commands help` for usage.
$ mono commands.exe help invalid-command
commands: Unknown command: invalid-command
commands: Use `commands help` for usage.