[runtime] Disable some tests in full-aot mode which cannot be AOTed because of type...
[mono-project.git] / mcs / tools / mdoc / Mono.Documentation / mdoc.cs
blob207d6cb40f911ba5cda004fefb7b8665b655082d
1 // Part of the mdoc(7) suite of tools.
2 using System;
3 using System.Collections.Generic;
4 using System.Diagnostics;
5 using System.IO;
6 using System.Linq;
7 using System.Text;
8 using Mono.Options;
10 namespace Mono.Documentation {
12 class MDoc {
14 private static bool debug;
16 private static void Main (string[] args)
18 MDoc d = new MDoc ();
19 try {
20 d.Run (args);
22 catch (Exception e) {
23 if (debug) {
24 Console.Error.WriteLine ("mdoc: {0}", e.ToString ());
26 else {
27 Console.Error.WriteLine ("mdoc: {0}", e.Message);
29 Console.Error.WriteLine ("See `mdoc help' for more information or use --debug to diagnose.");
30 Environment.ExitCode = 1;
34 int verbosity = 2;
36 internal Dictionary<string, MDocCommand> subcommands;
38 private void Run (string[] args)
40 subcommands = new Dictionary<string, MDocCommand> () {
41 { "assemble", new MDocAssembler () },
42 { "dump-tree", new MDocTreeDumper () },
43 { "export-html", new MDocToHtmlConverter () },
44 { "export-html-webdoc", new MDocExportWebdocHtml () },
45 { "export-msxdoc", new MDocToMSXDocConverter () },
46 { "help", new MDocHelpCommand (this) },
47 { "update", new MDocUpdater () },
48 { "update-ecma-xml", new MDocUpdateEcmaXml () },
49 { "validate", new MDocValidator () },
50 { "index", new MDocIndex () },
51 { "preserve", new MDocPreserve () }
54 bool showVersion = false;
55 bool showHelp = false;
56 var p = new OptionSet () {
57 { "version", v => showVersion = v != null },
58 { "v:", (int? v) => verbosity = v.HasValue ? v.Value : verbosity+1 },
59 { "debug", v => debug = v != null },
60 { "h|?|help", v => showHelp = v != null },
61 new ResponseFileSource (),
64 var extra = p.Parse (args);
66 if (showVersion) {
67 Console.WriteLine ("mdoc {0}", Consts.MonoVersion);
68 return;
70 if (extra.Count == 0) {
71 Console.WriteLine ("Use `mdoc help' for usage.");
72 return;
74 if (showHelp) {
75 extra.Add ("--help");
77 switch (extra [0]) {
78 case "x-msitomsx":
79 new MsidocToMsxdocConverter ().Run (extra);
80 break;
81 default:
82 GetCommand (extra [0]).Run (extra);
83 break;
87 internal MDocCommand GetCommand (string command)
89 MDocCommand h;
90 if (!subcommands.TryGetValue (command, out h)) {
91 Error ("Unknown command: {0}.", command);
93 h.TraceLevel = (TraceLevel) verbosity;
94 h.DebugOutput = debug;
95 return h;
98 private static void Error (string format, params object[] args)
100 throw new Exception (string.Format (format, args));
104 public abstract class MDocCommand {
106 public TraceLevel TraceLevel { get; set; }
107 public bool DebugOutput { get; set; }
109 public abstract void Run (IEnumerable<string> args);
111 protected List<string> Parse (OptionSet p, IEnumerable<string> args,
112 string command, string prototype, string description)
114 bool showHelp = false;
115 p.Add ("h|?|help",
116 "Show this message and exit.",
117 v => showHelp = v != null );
119 List<string> extra = null;
120 if (args != null) {
121 extra = p.Parse (args.Skip (1));
123 if (args == null || showHelp) {
124 Console.WriteLine ("usage: mdoc {0} {1}",
125 args == null ? command : args.First(), prototype);
126 Console.WriteLine ();
127 Console.WriteLine (description);
128 Console.WriteLine ();
129 Console.WriteLine ("Available Options:");
130 p.WriteOptionDescriptions (Console.Out);
131 return null;
133 return extra;
136 public void Error (string format, params object[] args)
138 throw new Exception (string.Format (format, args));
141 public void Message (TraceLevel level, string format, params object[] args)
143 if ((int) level > (int) TraceLevel)
144 return;
145 if (level == TraceLevel.Error)
146 Console.Error.WriteLine (format, args);
147 else
148 Console.WriteLine (format, args);
152 class MDocHelpCommand : MDocCommand {
154 MDoc instance;
156 public MDocHelpCommand (MDoc instance)
158 this.instance = instance;
161 public override void Run (IEnumerable<string> args)
163 if (args != null && args.Count() > 1) {
164 foreach (var arg in args.Skip (1)) {
165 instance.GetCommand (arg).Run (new string[]{arg, "--help"});
167 return;
169 Message (TraceLevel.Warning,
170 "usage: mdoc COMMAND [OPTIONS]\n" +
171 "Use `mdoc help COMMAND' for help on a specific command.\n" +
172 "\n" +
173 "Available commands:\n\n " +
174 string.Join ("\n ", instance.subcommands.Keys.OrderBy (v => v).ToArray()) +
175 "\n\n" +
176 "mdoc is a tool for documentation management.\n" +
177 "For additional information, see http://www.mono-project.com/"