Skip to content
Browse files

bug fix: rethrow premature errors when intercepted

  • Loading branch information...
1 parent 8f6201c commit 5d4a8d639286b372cfa89ff81a38480627a6908e @adrianaisemberg committed May 7, 2012
Showing with 26 additions and 18 deletions.
  1. +13 −9 CLAP/HelpGenerator.cs
  2. +11 −7 CLAP/MultiParser.cs
  3. +2 −2 CLAP/Properties/AssemblyInfo.cs
View
22 CLAP/HelpGenerator.cs
@@ -203,7 +203,7 @@ private static string GetTypeName(Type type)
private static ParserHelpInfo GetParserHelp(ParserRunner parser)
{
- return new ParserHelpInfo
+ var h = new ParserHelpInfo
{
Type = parser.Type,
Verbs = parser.GetVerbs().Select(verb => new VerbHelpInfo
@@ -247,16 +247,20 @@ private static ParserHelpInfo GetParserHelp(ParserRunner parser)
Type = handler.Type,
Description = handler.Description,
Validations = new List<string>(),
- })).Union(new GlobalParameterHelpInfo[]
+ })).ToList(),
+ };
+
+ if (parser.Register.RegisteredHelpHandlers.Any())
+ {
+ h.Globals.Add(new GlobalParameterHelpInfo
{
- new GlobalParameterHelpInfo
- {
- Names=parser.Register.RegisteredHelpHandlers.Keys.ToList(),
- Type = typeof(bool),
- Description = "Help",
- }
- }).ToList(),
+ Names = parser.Register.RegisteredHelpHandlers.Keys.ToList(),
+ Type = typeof(bool),
+ Description = "Help",
+ });
};
+
+ return h;
}
}
}
View
18 CLAP/MultiParser.cs
@@ -214,13 +214,15 @@ public int RunTargets(string[] args, params object[] targets)
{
// handle error using the first available error handler
//
+ // (if returns true - should rethrow)
+ //
if (TryHandlePrematureError(ex, targets))
{
- return ErrorCode;
+ throw;
}
else
{
- throw;
+ return ErrorCode;
}
}
@@ -237,11 +239,13 @@ public int RunTargets(string[] args, params object[] targets)
private bool TryHandlePrematureError(Exception ex, object[] targets)
{
+ var context = new ExceptionContext(ex);
+
if (Register.RegisteredErrorHandler != null)
{
- Register.RegisteredErrorHandler(new ExceptionContext(ex));
+ Register.RegisteredErrorHandler(context);
- return true;
+ return context.ReThrow;
}
else
{
@@ -255,14 +259,14 @@ private bool TryHandlePrematureError(Exception ex, object[] targets)
{
var target = targets == null ? null : targets[i];
- errorHandler.Invoke(target, new[] { new ExceptionContext(ex) });
+ errorHandler.Invoke(target, new[] { context });
- return true;
+ return context.ReThrow;
}
}
}
- return false;
+ return true;
}
/// <summary>
View
4 CLAP/Properties/AssemblyInfo.cs
@@ -29,5 +29,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("4.1")]
-[assembly: AssemblyFileVersion("4.1")]
+[assembly: AssemblyVersion("4.2")]
+[assembly: AssemblyFileVersion("4.2")]

0 comments on commit 5d4a8d6

Please sign in to comment.
Something went wrong with that request. Please try again.