a4bfe4016b92782a4e2f4228d344c112c1c7e110
[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 internal class Options
30 {
31         internal bool DeclaredOnly = false;
32         internal bool Search = false;
33         internal bool ShowPrivate = false;
34         internal string AssemblyReference = null;
35         internal string Type = null;
36
37         internal Options ()
38         {
39         }
40
41         // returning true means processed ok
42         // and execution should continue
43         internal bool ProcessArgs (string[] args)
44         {
45                 if (args.Length < 1) {
46                         PrintUsage ();
47                         return false;
48                 }
49
50                 for (int i = 0; i < args.Length; i++) {
51                         switch (args[i]) {
52                                 case "-h":
53                                 case "--help":
54                                         PrintHelp ();
55                                         return false;
56                                 case "--runtime-version":
57                                         PrintRuntimeVersion ();
58                                         return false;
59                                 case "-d":
60                                 case "--declared-only":
61                                         DeclaredOnly = true;
62                                         break;
63                                 case "-p":
64                                 case "--private":
65                                         ShowPrivate = true;
66                                         break;
67                                 case "-s":
68                                 case "-k":
69                                 case "--search":
70                                         Search = true;
71                                         break;
72                                 case "-c":
73                                         i++;
74                                         if (i < args.Length)
75                                                 MonoP.Completion (args[i]);
76                                         return false;
77                                 case "-r":
78                                         i++;
79                                         if (i < args.Length)
80                                                 AssemblyReference = args[i];
81                                         break;
82                                 default:
83                                         if (args[i].StartsWith ("-r:") || args[i].StartsWith ("/r:")) {
84                                                 AssemblyReference = args [i].Substring (3);
85                                                 break;
86                                         }
87
88                                         // The first unrecognizable option becomes
89                                         // the type to look up
90                                         if (Type == null) {
91                                                 Type = args[i];
92                                                 break;
93                                         }
94
95                                         // others are ignored
96                                         Console.WriteLine ("ignored: {0}", args[i]);
97                                         break;
98                         }
99                 }
100
101                 // must specify at least one of these
102                 if (Type == null && AssemblyReference == null)
103                         return false;
104
105                 return true;
106         }
107
108         void PrintRuntimeVersion ()
109         {
110                 Console.WriteLine ("runtime version: {0}", Environment.Version);
111         }
112
113         void PrintUsage ()
114         {
115                 Console.WriteLine ("Usage is: monop [option] [-c] [-r:Assembly] [class-name]");
116         }
117
118         void PrintHelp ()
119         {
120                 PrintUsage ();
121                 Console.WriteLine ("");
122                 Console.WriteLine ("options:");
123                 Console.WriteLine ("\t--declared-only,-d\tOnly show members declared in the Type");
124                 Console.WriteLine ("\t--help,-h\t\tShow this information");
125                 Console.WriteLine ("\t--private,-p\t\tShow private members");
126                 Console.WriteLine ("\t--runtime-version\tPrint runtime version");
127                 Console.WriteLine ("\t--search,-s,-k\t\tSearch through all known namespaces");
128         }
129 }
130