Files
linux-packaging-mono/external/api-doc-tools/tools/DocStat/DocStat/apistat.cs
Xamarin Public Jenkins (auto-signing) 95fdb59ea6 Imported Upstream version 6.6.0.89
Former-commit-id: b39a328747c2f3414dc52e009fb6f0aa80ca2492
2019-09-24 08:53:40 +00:00

83 lines
2.1 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using Mono.Options;
namespace DocStat
{
public class apistat
{
private static void Main(string[] args)
{
apistat a = new apistat();
try
{
a.Run(args);
}
catch (Exception e)
{
Console.Error.WriteLine("apistat: {0}", e.Message);
Environment.ExitCode = 1;
}
}
internal Dictionary<string, ApiCommand> subcommands;
private void Run (string[] args) {
subcommands = new Dictionary<string, ApiCommand>() {
{"internalize", new InternalizeCommand() },
{"remaining", new RemainingCommand() },
{"obsolete", new ObsoleteCommand() },
{"comparefix", new CompareFixCommand()},
{"reportnew", new CompareReportCommand()},
{"fixsummaries", new FixSummariesCommand()}
};
GetCommand(args.First()).Run(args);
}
internal ApiCommand GetCommand(string command)
{
ApiCommand a;
if (!subcommands.TryGetValue(command, out a))
{
throw new Exception(String.Format("Unknown command: {0}.", command));
}
return a;
}
}
public abstract class ApiCommand {
public abstract void Run(IEnumerable<string> args);
protected List<string> Parse(OptionSet p, IEnumerable<string> args,
string command, string prototype, string description)
{
bool showHelp = false;
p.Add("h|?|help",
"Show this message and exit.",
v => showHelp = v != null);
List<string> extra = null;
if (args != null)
{
extra = p.Parse(args.Skip(1));
}
if (args == null || showHelp)
{
Console.WriteLine("usage: mdoc {0} {1}",
args == null ? command : args.First(), prototype);
Console.WriteLine();
Console.WriteLine(description);
Console.WriteLine();
Console.WriteLine("Available Options:");
p.WriteOptionDescriptions(Console.Out);
return null;
}
return extra;
}
}
}