2010-03-12 Jb Evain <jbevain@novell.com>
[mono.git] / mcs / tools / monop / options.cs
1 //
2 // options.cs: Processes command line args
3 //
4 // Author:
5 //      John Luke  <john.luke@gmail.com>
6 //
7 // Permission is hereby granted, free of charge, to any person obtaining
8 // a copy of this software and associated documentation files (the
9 // "Software"), to deal in the Software without restriction, including
10 // without limitation the rights to use, copy, modify, merge, publish,
11 // distribute, sublicense, and/or sell copies of the Software, and to
12 // permit persons to whom the Software is furnished to do so, subject to
13 // the following conditions:
14 // 
15 // The above copyright notice and this permission notice shall be
16 // included in all copies or substantial portions of the Software.
17 // 
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 //
26
27 using System;
28
29 public class Options
30 {
31         public bool DeclaredOnly = false;
32         public bool FilterObsolete = false;
33         public bool PrintRefs = false;
34         public bool Search = false;
35         public bool ShowPrivate = false;
36         public string AssemblyReference = null;
37         public string Type = null;
38
39         public Options ()
40         {
41         }
42
43         // returning true means processed ok
44         // and execution should continue
45         internal bool ProcessArgs (string[] args)
46         {
47                 if (args.Length < 1) {
48                         PrintHelp ();
49                         return false;
50                 }
51
52                 for (int i = 0; i < args.Length; i++) {
53                         switch (args[i]) {
54                                 case "-h":
55                                 case "--help":
56                                         PrintHelp ();
57                                         return false;
58                                 case "--runtime-version":
59                                         PrintRuntimeVersion ();
60                                         return false;
61                                 case "-d":
62                                 case "--declared-only":
63                                         DeclaredOnly = true;
64                                         break;
65                                 case "--filter-obsolete":
66                                 case "-f":
67                                         FilterObsolete = true;
68                                         break;
69                                 case "-p":
70                                 case "--private":
71                                         ShowPrivate = true;
72                                         break;
73                                 case "--refs":
74                                         PrintRefs = true;
75                                         break;
76                                 case "-s":
77                                 case "-k":
78                                 case "--search":
79                                         Search = true;
80                                         break;
81                                 case "-c":
82                                         i++;
83                                         if (i < args.Length)
84                                                 MonoP.Completion (args[i]);
85                                         return false;
86                                 case "-r":
87                                         i++;
88                                         if (i < args.Length)
89                                                 AssemblyReference = args[i];
90                                         break;
91                                 default:
92                                         if (args[i].StartsWith ("-r:") || args[i].StartsWith ("/r:")) {
93                                                 AssemblyReference = args [i].Substring (3);
94                                                 break;
95                                         }
96
97                                         // The first unrecognizable option becomes
98                                         // the type to look up
99                                         if (Type == null) {
100                                                 Type = args[i];
101                                                 break;
102                                         }
103
104                                         // others are ignored
105                                         Console.WriteLine ("ignored: {0}", args[i]);
106                                         break;
107                         }
108                 }
109
110                 // must specify at least one of these
111                 if (Type == null && AssemblyReference == null)
112                         return false;
113
114                 return true;
115         }
116
117         void PrintRuntimeVersion ()
118         {
119                 Console.WriteLine ("runtime version: {0}", Environment.Version);
120         }
121
122         void PrintHelp ()
123         {
124                 Console.WriteLine ("Usage is: monop [option] [-c] [-r:Assembly] [class-name]");
125                 Console.WriteLine ("");
126                 Console.WriteLine ("options:");
127                 Console.WriteLine ("\t--declared-only,-d\tOnly show members declared in the Type");
128                 Console.WriteLine ("\t--help,-h\t\tShow this information");
129                 Console.WriteLine ("\t--filter-obsolete,-f\tDo not show obsolete types and members");
130                 Console.WriteLine ("\t--private,-p\t\tShow private members");
131                 Console.WriteLine ("\t--refs\t\t\tPrint a list of the referenced assemblies for an assembly");
132                 Console.WriteLine ("\t--runtime-version\tPrint runtime version");
133                 Console.WriteLine ("\t--search,-s,-k\t\tSearch through all known namespaces");
134         }
135 }
136