[metadata] Lock around special static fields hash access
[mono.git] / mcs / tools / mdoc / Mono.Documentation / dump.cs
1 using System;
2 using System.Collections.Generic;
3
4 using Monodoc;
5 using Mono.Options;
6
7 namespace Mono.Documentation {
8
9         class MDocTreeDumper : MDocCommand {
10
11                 public override void Run (IEnumerable<string> args)
12                 {
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) },
29                         };
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;
36
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                                         TreeDumper.PrintTree (t.RootNode);
44                                 }
45                         }
46                 }
47
48                 private void AddFormat (Dictionary<string, List<string>> d, string format, string file)
49                 {
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);
56                         }
57                         l.Add (file);
58                 }
59         }
60 }