update MEF to preview 9
[mcs.git] / tools / mdoc / Mono.Documentation / dump.cs
blob49033d4a832911ce9ecf59a3618c51ce5ec9c010
1 using System;
2 using System.Collections.Generic;
4 using Monodoc;
5 using Mono.Options;
7 namespace Mono.Documentation {
9 class MDocTreeDumper : MDocCommand {
11 public override void Run (IEnumerable<string> args)
13 var validFormats = RootTree.GetSupportedFormats ();
14 string cur_format = "";
15 var formats = new Dictionary<string, List<string>> ();
16 var options = new OptionSet () {
17 { "f|format=",
18 "The documentation {FORMAT} used in FILES. " +
19 "Valid formats include:\n " +
20 string.Join ("\n ", validFormats) + "\n" +
21 "If not specified, no HelpSource is used. This may " +
22 "impact the PublicUrls displayed for nodes.",
23 v => {
24 if (Array.IndexOf (validFormats, v) < 0)
25 Error ("Invalid documentation format: {0}.", v);
26 cur_format = v;
27 } },
28 { "<>", v => AddFormat (formats, cur_format, v) },
30 List<string> files = Parse (options, args, "dump-tree",
31 "[OPTIONS]+ FILES",
32 "Print out the nodes within the assembled .tree FILES,\n" +
33 "as produced by 'mdoc assemble'.");
34 if (files == null)
35 return;
37 foreach (string format in formats.Keys) {
38 foreach (string file in formats [format]) {
39 HelpSource hs = format == ""
40 ? null
41 : RootTree.GetHelpSource (format, file.Replace (".tree", ""));
42 Tree t = new Tree (hs, file);
43 Node.PrintTree (t);
48 private void AddFormat (Dictionary<string, List<string>> d, string format, string file)
50 if (format == null)
51 format = "";
52 List<string> l;
53 if (!d.TryGetValue (format, out l)) {
54 l = new List<string> ();
55 d.Add (format, l);
57 l.Add (file);