2010-06-03 Jb Evain <jbevain@novell.com>
[mcs.git] / tools / monop / options.cs
blobfa1a10dda3460f0322c9ec13357830d3071f2076
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.
27 using System;
29 public class Options
31 public bool DeclaredOnly = false;
32 public bool FilterObsolete = false;
33 public bool PrintRefs = false;
34 public bool Search = false;
35 public bool ShowAll = false;
36 public bool ShowPrivate = false;
37 public string AssemblyReference = null;
38 public string Type = null;
40 public Options ()
44 // returning true means processed ok
45 // and execution should continue
46 internal bool ProcessArgs (string[] args)
48 if (args.Length < 1) {
49 PrintHelp ();
50 return false;
53 for (int i = 0; i < args.Length; i++) {
54 switch (args[i]) {
55 case "-h":
56 case "--help":
57 PrintHelp ();
58 return false;
59 case "--runtime-version":
60 PrintRuntimeVersion ();
61 return false;
62 case "-d":
63 case "--declared-only":
64 DeclaredOnly = true;
65 break;
66 case "--filter-obsolete":
67 case "-f":
68 FilterObsolete = true;
69 break;
70 case "-p":
71 case "--private":
72 ShowPrivate = true;
73 break;
74 case "--refs":
75 PrintRefs = true;
76 break;
77 case "-s":
78 case "-k":
79 case "--search":
80 Search = true;
81 break;
82 case "-c":
83 i++;
84 if (i < args.Length)
85 MonoP.Completion (args[i]);
86 return false;
87 case "-r":
88 i++;
89 if (i < args.Length)
90 AssemblyReference = args[i];
91 break;
92 case "-a":
93 ShowAll = true;
94 break;
95 default:
96 if (args[i].StartsWith ("-r:") || args[i].StartsWith ("/r:")) {
97 AssemblyReference = args [i].Substring (3);
98 break;
101 // The first unrecognizable option becomes
102 // the type to look up
103 if (Type == null) {
104 Type = args[i];
105 break;
108 // others are ignored
109 Console.WriteLine ("ignored: {0}", args[i]);
110 break;
114 // must specify at least one of these
115 if (Type == null && AssemblyReference == null)
116 return false;
118 return true;
121 void PrintRuntimeVersion ()
123 Console.WriteLine ("runtime version: {0}", Environment.Version);
126 void PrintHelp ()
128 Console.WriteLine ("Usage is: monop [option] [-c] [-r:Assembly] [class-name]");
129 Console.WriteLine ("");
130 Console.WriteLine ("options:");
131 Console.WriteLine ("\t--declared-only,-d\tOnly show members declared in the Type");
132 Console.WriteLine ("\t--help,-h\t\tShow this information");
133 Console.WriteLine ("\t--filter-obsolete,-f\tDo not show obsolete types and members");
134 Console.WriteLine ("\t--private,-p\t\tShow private members");
135 Console.WriteLine ("\t--refs\t\t\tPrint a list of the referenced assemblies for an assembly");
136 Console.WriteLine ("\t--runtime-version\tPrint runtime version");
137 Console.WriteLine ("\t--search,-s,-k\t\tSearch through all known namespaces");
138 Console.WriteLine ("\t--a\t\tShows all the types declare in the specified assembly");