Fixing an issue with output parameters that are of type IntPtr
[castle.git] / MonoRail / NewGenerator / Castle.NewGenerator.Core / GetOptions / Options.cs
blob73a1f9221510fdfa5df5b78ad34974651c37e127
1 //
2 // Options.cs
3 //
4 // Author: Rafael Teixeira (rafaelteixeirabr@hotmail.com)
5 //
6 // (C) 2002 Rafael Teixeira
7 //
8 //
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
16 //
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
19 //
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 namespace Mono.GetOptions
30 using System;
31 using System.Collections;
33 public delegate void ErrorReporter(int num, string msg);
35 public class Options
37 public OptionsParsingMode ParsingMode;
38 public bool BreakSingleDashManyLettersIntoManyOptions;
39 public bool EndOptionProcessingWithDoubleDash;
40 public bool DontSplitOnCommas;
41 public ErrorReporter ReportError;
43 private OptionList optionParser;
45 public Options() : this(null)
49 public Options(string[] args) : this(args, OptionsParsingMode.Both, false, true, false, null)
53 public Options(string[] args,
54 OptionsParsingMode parsingMode,
55 bool breakSingleDashManyLettersIntoManyOptions,
56 bool endOptionProcessingWithDoubleDash,
57 bool dontSplitOnCommas) :
58 this(args, OptionsParsingMode.Both, false, true, false, null)
62 public Options(string[] args,
63 OptionsParsingMode parsingMode,
64 bool breakSingleDashManyLettersIntoManyOptions,
65 bool endOptionProcessingWithDoubleDash,
66 bool dontSplitOnCommas,
67 ErrorReporter reportError)
69 ParsingMode = parsingMode;
70 BreakSingleDashManyLettersIntoManyOptions = breakSingleDashManyLettersIntoManyOptions;
71 EndOptionProcessingWithDoubleDash = endOptionProcessingWithDoubleDash;
72 DontSplitOnCommas = dontSplitOnCommas;
73 if (reportError == null)
74 ReportError = new ErrorReporter(DefaultErrorReporter);
75 else
76 ReportError = reportError;
77 InitializeOtherDefaults();
78 if (args != null)
79 ProcessArgs(args);
82 protected virtual void InitializeOtherDefaults()
84 } // Only subclasses may need to implement something here
86 public bool RunningOnWindows
88 get
90 // check for non-Unix platforms - see FAQ for more details
91 // http://www.mono-project.com/FAQ:_Technical#How_to_detect_the_execution_platform_.3F
92 int platform = (int) Environment.OSVersion.Platform;
93 return ((platform != 4) && (platform != 128));
97 #region non-option arguments
99 private ArrayList arguments = new ArrayList();
100 public string[] RemainingArguments;
102 [ArgumentProcessor]
103 public virtual void DefaultArgumentProcessor(string argument)
105 arguments.Add(argument);
108 public string FirstArgument
110 get { return (arguments.Count > 0) ? (string) arguments[0] : null; }
113 public string SecondArgument
115 get { return (arguments.Count > 1) ? (string) arguments[1] : null; }
118 public string ThirdArgument
120 get { return (arguments.Count > 2) ? (string) arguments[2] : null; }
123 public string FourthArgument
125 get { return (arguments.Count > 3) ? (string) arguments[3] : null; }
128 public string FifthArgument
130 get { return (arguments.Count > 4) ? (string) arguments[4] : null; }
133 public bool GotNoArguments
135 get { return arguments.Count == 0; }
138 #endregion
140 public void ProcessArgs(string[] args)
142 optionParser = new OptionList(this);
143 optionParser.AdditionalBannerInfo = AdditionalBannerInfo;
144 optionParser.ProcessArgs(args);
145 RemainingArguments = (string[]) arguments.ToArray(typeof(string));
148 private static void DefaultErrorReporter(int number, string message)
150 if (number > 0)
151 Console.WriteLine("Error {0}: {1}", number, message);
152 else
153 Console.WriteLine("Error: {0}", message);
156 public virtual string AdditionalBannerInfo
158 get { return null; }
161 public void ShowBanner()
163 optionParser.ShowBanner();
166 [Option("Show this help list", '?', "help")]
167 public virtual WhatToDoNext DoHelp()
169 return optionParser.DoHelp();
172 [Option("Show an additional help list", "help2")]
173 public virtual WhatToDoNext DoHelp2()
175 return optionParser.DoHelp2();
178 [Option("Display version and licensing information", 'V', "version")]
179 public virtual WhatToDoNext DoAbout()
181 return optionParser.DoAbout();
184 [Option("Show usage syntax and exit", "usage")]
185 public virtual WhatToDoNext DoUsage()
187 return optionParser.DoUsage();
190 private bool verboseParsingOfOptions = false;
192 [Option("Show verbose parsing of options", '.', "verbosegetoptions", SecondLevelHelp = true)]
193 public bool VerboseParsingOfOptions
195 set { verboseParsingOfOptions = value; }
196 get { return verboseParsingOfOptions; }
199 private bool debuggingOfOptions = false;
201 [Option("Show debugging info while processing options", '~', "debugoptions", SecondLevelHelp = true)]
202 public bool DebuggingOfOptions
206 debuggingOfOptions = value;
207 if (value)
209 Console.WriteLine("ParsingMode = {0}", ParsingMode);
210 Console.WriteLine("BreakSingleDashManyLettersIntoManyOptions = {0}", BreakSingleDashManyLettersIntoManyOptions);
211 Console.WriteLine("EndOptionProcessingWithDoubleDash = {0}", EndOptionProcessingWithDoubleDash);
212 Console.WriteLine("DontSplitOnCommas = {0}", DontSplitOnCommas);
215 get { return debuggingOfOptions; }