Skip to content
Browse files

added exit codes (1 or 0)

  • Loading branch information...
1 parent af1029e commit cab1ff6d08afadc0377f5378c8d6b1f3e1b60340 @adrianaisemberg committed Mar 22, 2012
Showing with 99 additions and 92 deletions.
  1. +9 −6 CLAP/MultiParser.cs
  2. +38 −38 CLAP/Parser.Console.cs
  3. +38 −38 CLAP/Parser.WinForms.cs
  4. +12 −8 CLAP/ParserRunner.cs
  5. +2 −2 ConsoleTest/Program.cs
View
15 CLAP/MultiParser.cs
@@ -17,6 +17,9 @@ public abstract class MultiParser
private static readonly string[] s_delimiters = new[] { ".", "/" };
private readonly Type[] m_types;
+ internal const int ErrorCode = 1;
+ internal const int SuccessCode = 0;
+
#endregion Fields
#region Properties
@@ -171,17 +174,17 @@ private ParserRunner GetSingleTypeParser(string[] args, object obj, ParserRegist
/// Run a parser of static verbs
/// </summary>
/// <param name="args">The user arguments</param>
- public void RunStatic(string[] args)
+ public int RunStatic(string[] args)
{
- RunTargets(args, null);
+ return RunTargets(args, null);
}
/// <summary>
/// Run a parser of instance verbs against instances of the verb classes
/// </summary>
/// <param name="args">The user arguments</param>
/// <param name="targets">The instances of the verb classes</param>
- public void RunTargets(string[] args, params object[] targets)
+ public int RunTargets(string[] args, params object[] targets)
{
ParserRunner parser = null;
@@ -191,7 +194,7 @@ public void RunTargets(string[] args, params object[] targets)
{
HandleEmptyArguments(targets);
- return;
+ return SuccessCode;
}
try
@@ -213,7 +216,7 @@ public void RunTargets(string[] args, params object[] targets)
//
if (TryHandlePrematureError(ex, targets))
{
- return;
+ return ErrorCode;
}
else
{
@@ -229,7 +232,7 @@ public void RunTargets(string[] args, params object[] targets)
var target = targets.None() ? null : targets[index];
- parser.Run(args, target);
+ return parser.Run(args, target);
}
private bool TryHandlePrematureError(Exception ex, object[] targets)
View
76 CLAP/Parser.Console.cs
@@ -10,39 +10,39 @@ public partial class Parser
/// </summary>
/// <param name="args">The user arguments</param>
/// <param name="targets">The instances of the verb classes</param>
- public static void RunConsole(string[] args, params object[] targets)
+ public static int RunConsole(string[] args, params object[] targets)
{
Debug.Assert(targets.Any());
Debug.Assert(targets.All(t => t != null));
var p = new Parser(targets.Select(t => t.GetType()).ToArray()).Console();
- ((MultiParser)p).RunTargets(args, targets);
+ return ((MultiParser)p).RunTargets(args, targets);
}
/// <summary>
/// Executes a generic console static parser of a specified type
/// </summary>
/// <typeparam name="T">The type of the parser</typeparam>
/// <param name="args">The user arguments</param>
- public static void RunConsole<T>(string[] args)
- { new Parser<T>().Console().RunStatic(args); }
+ public static int RunConsole<T>(string[] args)
+ { return new Parser<T>().Console().RunStatic(args); }
/// <summary>
/// Executes a generic console parser of a specified type
/// </summary>
/// <typeparam name="T">The type of the parser</typeparam>
/// <param name="args">The user arguments</param>
/// <param name="t">An instance of the verb class</param>
- public static void RunConsole<T>(string[] args, T t)
- { new Parser<T>().Console().RunTargets(args, t); }
+ public static int RunConsole<T>(string[] args, T t)
+ { return new Parser<T>().Console().RunTargets(args, t); }
/// <summary>
/// Executes a generic console static parser of some specified types
/// </summary>
/// <param name="args">The user arguments</param>
- public static void RunConsole<T1, T2>(string[] args)
- { new Parser<T1, T2>().Console().RunStatic(args); }
+ public static int RunConsole<T1, T2>(string[] args)
+ { return new Parser<T1, T2>().Console().RunStatic(args); }
/// <summary>
/// Executes a generic console parser of some specified types
@@ -52,15 +52,15 @@ public static void RunConsole<T>(string[] args, T t)
/// <param name="args">The user arguments</param>
/// <param name="t1">An instance of the verb class</param>
/// <param name="t2">An instance of the verb class</param>
- public static void RunConsole<T1, T2>(string[] args, T1 t1, T2 t2)
- { new Parser<T1, T2>().Console().RunTargets(args, t1, t2); }
+ public static int RunConsole<T1, T2>(string[] args, T1 t1, T2 t2)
+ { return new Parser<T1, T2>().Console().RunTargets(args, t1, t2); }
/// <summary>
/// Executes a generic console static parser of some specified types
/// </summary>
/// <param name="args">The user arguments</param>
- public static void RunConsole<T1, T2, T3>(string[] args)
- { new Parser<T1, T2, T3>().Console().RunStatic(args); }
+ public static int RunConsole<T1, T2, T3>(string[] args)
+ { return new Parser<T1, T2, T3>().Console().RunStatic(args); }
/// <summary>
/// Executes a generic console parser of some specified types
@@ -72,15 +72,15 @@ public static void RunConsole<T>(string[] args, T t)
/// <param name="t1">An instance of the verb class</param>
/// <param name="t2">An instance of the verb class</param>
/// <param name="t3">An instance of the verb class</param>
- public static void RunConsole<T1, T2, T3>(string[] args, T1 t1, T2 t2, T3 t3)
- { new Parser<T1, T2, T3>().Console().RunTargets(args, t1, t2, t3); }
+ public static int RunConsole<T1, T2, T3>(string[] args, T1 t1, T2 t2, T3 t3)
+ { return new Parser<T1, T2, T3>().Console().RunTargets(args, t1, t2, t3); }
/// <summary>
/// Executes a generic console static parser of some specified types
/// </summary>
/// <param name="args">The user arguments</param>
- public static void RunConsole<T1, T2, T3, T4>(string[] args)
- { new Parser<T1, T2, T3, T4>().Console().RunStatic(args); }
+ public static int RunConsole<T1, T2, T3, T4>(string[] args)
+ { return new Parser<T1, T2, T3, T4>().Console().RunStatic(args); }
/// <summary>
/// Executes a generic console parser of some specified types
@@ -94,15 +94,15 @@ public static void RunConsole<T>(string[] args, T t)
/// <param name="t2">An instance of the verb class</param>
/// <param name="t3">An instance of the verb class</param>
/// <param name="t4">An instance of the verb class</param>
- public static void RunConsole<T1, T2, T3, T4>(string[] args, T1 t1, T2 t2, T3 t3, T4 t4)
- { new Parser<T1, T2, T3, T4>().Console().RunTargets(args, t1, t2, t3, t4); }
+ public static int RunConsole<T1, T2, T3, T4>(string[] args, T1 t1, T2 t2, T3 t3, T4 t4)
+ { return new Parser<T1, T2, T3, T4>().Console().RunTargets(args, t1, t2, t3, t4); }
/// <summary>
/// Executes a generic console static parser of some specified types
/// </summary>
/// <param name="args">The user arguments</param>
- public static void RunConsole<T1, T2, T3, T4, T5>(string[] args)
- { new Parser<T1, T2, T3, T4, T5>().Console().RunStatic(args); }
+ public static int RunConsole<T1, T2, T3, T4, T5>(string[] args)
+ { return new Parser<T1, T2, T3, T4, T5>().Console().RunStatic(args); }
/// <summary>
/// Executes a generic console parser of some specified types
@@ -118,15 +118,15 @@ public static void RunConsole<T>(string[] args, T t)
/// <param name="t3">An instance of the verb class</param>
/// <param name="t4">An instance of the verb class</param>
/// <param name="t5">An instance of the verb class</param>
- public static void RunConsole<T1, T2, T3, T4, T5>(string[] args, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5)
- { new Parser<T1, T2, T3, T4, T5>().Console().RunTargets(args, t1, t2, t3, t4, t5); }
+ public static int RunConsole<T1, T2, T3, T4, T5>(string[] args, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5)
+ { return new Parser<T1, T2, T3, T4, T5>().Console().RunTargets(args, t1, t2, t3, t4, t5); }
/// <summary>
/// Executes a generic console static parser of some specified types
/// </summary>
/// <param name="args">The user arguments</param>
- public static void RunConsole<T1, T2, T3, T4, T5, T6>(string[] args)
- { new Parser<T1, T2, T3, T4, T5, T6>().Console().RunStatic(args); }
+ public static int RunConsole<T1, T2, T3, T4, T5, T6>(string[] args)
+ { return new Parser<T1, T2, T3, T4, T5, T6>().Console().RunStatic(args); }
/// <summary>
/// Executes a generic console parser of some specified types
@@ -144,15 +144,15 @@ public static void RunConsole<T>(string[] args, T t)
/// <param name="t4">An instance of the verb class</param>
/// <param name="t5">An instance of the verb class</param>
/// <param name="t6">An instance of the verb class</param>
- public static void RunConsole<T1, T2, T3, T4, T5, T6>(string[] args, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6)
- { new Parser<T1, T2, T3, T4, T5, T6>().Console().RunTargets(args, t1, t2, t3, t4, t5, t6); }
+ public static int RunConsole<T1, T2, T3, T4, T5, T6>(string[] args, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6)
+ { return new Parser<T1, T2, T3, T4, T5, T6>().Console().RunTargets(args, t1, t2, t3, t4, t5, t6); }
/// <summary>
/// Executes a generic console static parser of some specified types
/// </summary>
/// <param name="args">The user arguments</param>
- public static void RunConsole<T1, T2, T3, T4, T5, T6, T7>(string[] args)
- { new Parser<T1, T2, T3, T4, T5, T6, T7>().Console().RunStatic(args); }
+ public static int RunConsole<T1, T2, T3, T4, T5, T6, T7>(string[] args)
+ { return new Parser<T1, T2, T3, T4, T5, T6, T7>().Console().RunStatic(args); }
/// <summary>
/// Executes a generic console parser of some specified types
@@ -172,15 +172,15 @@ public static void RunConsole<T>(string[] args, T t)
/// <param name="t5">An instance of the verb class</param>
/// <param name="t6">An instance of the verb class</param>
/// <param name="t7">An instance of the verb class</param>
- public static void RunConsole<T1, T2, T3, T4, T5, T6, T7>(string[] args, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7)
- { new Parser<T1, T2, T3, T4, T5, T6, T7>().Console().RunTargets(args, t1, t2, t3, t4, t5, t6, t7); }
+ public static int RunConsole<T1, T2, T3, T4, T5, T6, T7>(string[] args, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7)
+ { return new Parser<T1, T2, T3, T4, T5, T6, T7>().Console().RunTargets(args, t1, t2, t3, t4, t5, t6, t7); }
/// <summary>
/// Executes a generic console static parser of some specified types
/// </summary>
/// <param name="args">The user arguments</param>
- public static void RunConsole<T1, T2, T3, T4, T5, T6, T7, T8>(string[] args)
- { new Parser<T1, T2, T3, T4, T5, T6, T7, T8>().Console().RunStatic(args); }
+ public static int RunConsole<T1, T2, T3, T4, T5, T6, T7, T8>(string[] args)
+ { return new Parser<T1, T2, T3, T4, T5, T6, T7, T8>().Console().RunStatic(args); }
/// <summary>
/// Executes a generic console parser of some specified types
@@ -202,15 +202,15 @@ public static void RunConsole<T>(string[] args, T t)
/// <param name="t6">An instance of the verb class</param>
/// <param name="t7">An instance of the verb class</param>
/// <param name="t8">An instance of the verb class</param>
- public static void RunConsole<T1, T2, T3, T4, T5, T6, T7, T8>(string[] args, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8)
- { new Parser<T1, T2, T3, T4, T5, T6, T7, T8>().Console().RunTargets(args, t1, t2, t3, t4, t5, t6, t7, t8); }
+ public static int RunConsole<T1, T2, T3, T4, T5, T6, T7, T8>(string[] args, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8)
+ { return new Parser<T1, T2, T3, T4, T5, T6, T7, T8>().Console().RunTargets(args, t1, t2, t3, t4, t5, t6, t7, t8); }
/// <summary>
/// Executes a generic console static parser of some specified types
/// </summary>
/// <param name="args">The user arguments</param>
- public static void RunConsole<T1, T2, T3, T4, T5, T6, T7, T8, T9>(string[] args)
- { new Parser<T1, T2, T3, T4, T5, T6, T7, T8, T9>().Console().RunStatic(args); }
+ public static int RunConsole<T1, T2, T3, T4, T5, T6, T7, T8, T9>(string[] args)
+ { return new Parser<T1, T2, T3, T4, T5, T6, T7, T8, T9>().Console().RunStatic(args); }
/// <summary>
/// Executes a generic console parser of some specified types
@@ -234,7 +234,7 @@ public static void RunConsole<T>(string[] args, T t)
/// <param name="t7">An instance of the verb class</param>
/// <param name="t8">An instance of the verb class</param>
/// <param name="t9">An instance of the verb class</param>
- public static void RunConsole<T1, T2, T3, T4, T5, T6, T7, T8, T9>(string[] args, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9)
- { new Parser<T1, T2, T3, T4, T5, T6, T7, T8, T9>().Console().RunTargets(args, t1, t2, t3, t4, t5, t6, t7, t8, t9); }
+ public static int RunConsole<T1, T2, T3, T4, T5, T6, T7, T8, T9>(string[] args, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9)
+ { return new Parser<T1, T2, T3, T4, T5, T6, T7, T8, T9>().Console().RunTargets(args, t1, t2, t3, t4, t5, t6, t7, t8, t9); }
}
}
View
76 CLAP/Parser.WinForms.cs
@@ -10,39 +10,39 @@ public partial class Parser
/// </summary>
/// <param name="args">The user arguments</param>
/// <param name="targets">The instances of the verb classes</param>
- public static void RunWinForms(string[] args, params object[] targets)
+ public static int RunWinForms(string[] args, params object[] targets)
{
Debug.Assert(targets.Any());
Debug.Assert(targets.All(t => t != null));
var p = new Parser(targets.Select(t => t.GetType()).ToArray()).WinForms();
- ((MultiParser)p).RunTargets(args, targets);
+ return ((MultiParser)p).RunTargets(args, targets);
}
/// <summary>
/// Executes a generic winforms static parser of a specified type
/// </summary>
/// <typeparam name="T">The type of the parser</typeparam>
/// <param name="args">The user arguments</param>
- public static void RunWinForms<T>(string[] args)
- { new Parser<T>().WinForms().RunStatic(args); }
+ public static int RunWinForms<T>(string[] args)
+ { return new Parser<T>().WinForms().RunStatic(args); }
/// <summary>
/// Executes a generic winforms parser of a specified type
/// </summary>
/// <typeparam name="T">The type of the parser</typeparam>
/// <param name="args">The user arguments</param>
/// <param name="t">An instance of the verb class</param>
- public static void RunWinForms<T>(string[] args, T t)
- { new Parser<T>().WinForms().RunTargets(args, t); }
+ public static int RunWinForms<T>(string[] args, T t)
+ { return new Parser<T>().WinForms().RunTargets(args, t); }
/// <summary>
/// Executes a generic winforms static parser of some specified types
/// </summary>
/// <param name="args">The user arguments</param>
- public static void RunWinForms<T1, T2>(string[] args)
- { new Parser<T1, T2>().WinForms().RunStatic(args); }
+ public static int RunWinForms<T1, T2>(string[] args)
+ { return new Parser<T1, T2>().WinForms().RunStatic(args); }
/// <summary>
/// Executes a generic winforms parser of some specified types
@@ -52,15 +52,15 @@ public static void RunWinForms<T>(string[] args, T t)
/// <param name="args">The user arguments</param>
/// <param name="t1">An instance of the verb class</param>
/// <param name="t2">An instance of the verb class</param>
- public static void RunWinForms<T1, T2>(string[] args, T1 t1, T2 t2)
- { new Parser<T1, T2>().WinForms().RunTargets(args, t1, t2); }
+ public static int RunWinForms<T1, T2>(string[] args, T1 t1, T2 t2)
+ { return new Parser<T1, T2>().WinForms().RunTargets(args, t1, t2); }
/// <summary>
/// Executes a generic winforms static parser of some specified types
/// </summary>
/// <param name="args">The user arguments</param>
- public static void RunWinForms<T1, T2, T3>(string[] args)
- { new Parser<T1, T2, T3>().WinForms().RunStatic(args); }
+ public static int RunWinForms<T1, T2, T3>(string[] args)
+ { return new Parser<T1, T2, T3>().WinForms().RunStatic(args); }
/// <summary>
/// Executes a generic winforms parser of some specified types
@@ -72,15 +72,15 @@ public static void RunWinForms<T>(string[] args, T t)
/// <param name="t1">An instance of the verb class</param>
/// <param name="t2">An instance of the verb class</param>
/// <param name="t3">An instance of the verb class</param>
- public static void RunWinForms<T1, T2, T3>(string[] args, T1 t1, T2 t2, T3 t3)
- { new Parser<T1, T2, T3>().WinForms().RunTargets(args, t1, t2, t3); }
+ public static int RunWinForms<T1, T2, T3>(string[] args, T1 t1, T2 t2, T3 t3)
+ { return new Parser<T1, T2, T3>().WinForms().RunTargets(args, t1, t2, t3); }
/// <summary>
/// Executes a generic winforms static parser of some specified types
/// </summary>
/// <param name="args">The user arguments</param>
- public static void RunWinForms<T1, T2, T3, T4>(string[] args)
- { new Parser<T1, T2, T3, T4>().WinForms().RunStatic(args); }
+ public static int RunWinForms<T1, T2, T3, T4>(string[] args)
+ { return new Parser<T1, T2, T3, T4>().WinForms().RunStatic(args); }
/// <summary>
/// Executes a generic winforms parser of some specified types
@@ -94,15 +94,15 @@ public static void RunWinForms<T>(string[] args, T t)
/// <param name="t2">An instance of the verb class</param>
/// <param name="t3">An instance of the verb class</param>
/// <param name="t4">An instance of the verb class</param>
- public static void RunWinForms<T1, T2, T3, T4>(string[] args, T1 t1, T2 t2, T3 t3, T4 t4)
- { new Parser<T1, T2, T3, T4>().WinForms().RunTargets(args, t1, t2, t3, t4); }
+ public static int RunWinForms<T1, T2, T3, T4>(string[] args, T1 t1, T2 t2, T3 t3, T4 t4)
+ { return new Parser<T1, T2, T3, T4>().WinForms().RunTargets(args, t1, t2, t3, t4); }
/// <summary>
/// Executes a generic winforms static parser of some specified types
/// </summary>
/// <param name="args">The user arguments</param>
- public static void RunWinForms<T1, T2, T3, T4, T5>(string[] args)
- { new Parser<T1, T2, T3, T4, T5>().WinForms().RunStatic(args); }
+ public static int RunWinForms<T1, T2, T3, T4, T5>(string[] args)
+ { return new Parser<T1, T2, T3, T4, T5>().WinForms().RunStatic(args); }
/// <summary>
/// Executes a generic winforms parser of some specified types
@@ -118,15 +118,15 @@ public static void RunWinForms<T>(string[] args, T t)
/// <param name="t3">An instance of the verb class</param>
/// <param name="t4">An instance of the verb class</param>
/// <param name="t5">An instance of the verb class</param>
- public static void RunWinForms<T1, T2, T3, T4, T5>(string[] args, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5)
- { new Parser<T1, T2, T3, T4, T5>().WinForms().RunTargets(args, t1, t2, t3, t4, t5); }
+ public static int RunWinForms<T1, T2, T3, T4, T5>(string[] args, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5)
+ { return new Parser<T1, T2, T3, T4, T5>().WinForms().RunTargets(args, t1, t2, t3, t4, t5); }
/// <summary>
/// Executes a generic winforms static parser of some specified types
/// </summary>
/// <param name="args">The user arguments</param>
- public static void RunWinForms<T1, T2, T3, T4, T5, T6>(string[] args)
- { new Parser<T1, T2, T3, T4, T5, T6>().WinForms().RunStatic(args); }
+ public static int RunWinForms<T1, T2, T3, T4, T5, T6>(string[] args)
+ { return new Parser<T1, T2, T3, T4, T5, T6>().WinForms().RunStatic(args); }
/// <summary>
/// Executes a generic winforms parser of some specified types
@@ -144,15 +144,15 @@ public static void RunWinForms<T>(string[] args, T t)
/// <param name="t4">An instance of the verb class</param>
/// <param name="t5">An instance of the verb class</param>
/// <param name="t6">An instance of the verb class</param>
- public static void RunWinForms<T1, T2, T3, T4, T5, T6>(string[] args, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6)
- { new Parser<T1, T2, T3, T4, T5, T6>().WinForms().RunTargets(args, t1, t2, t3, t4, t5, t6); }
+ public static int RunWinForms<T1, T2, T3, T4, T5, T6>(string[] args, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6)
+ { return new Parser<T1, T2, T3, T4, T5, T6>().WinForms().RunTargets(args, t1, t2, t3, t4, t5, t6); }
/// <summary>
/// Executes a generic winforms static parser of some specified types
/// </summary>
/// <param name="args">The user arguments</param>
- public static void RunWinForms<T1, T2, T3, T4, T5, T6, T7>(string[] args)
- { new Parser<T1, T2, T3, T4, T5, T6, T7>().WinForms().RunStatic(args); }
+ public static int RunWinForms<T1, T2, T3, T4, T5, T6, T7>(string[] args)
+ { return new Parser<T1, T2, T3, T4, T5, T6, T7>().WinForms().RunStatic(args); }
/// <summary>
/// Executes a generic winforms parser of some specified types
@@ -172,15 +172,15 @@ public static void RunWinForms<T>(string[] args, T t)
/// <param name="t5">An instance of the verb class</param>
/// <param name="t6">An instance of the verb class</param>
/// <param name="t7">An instance of the verb class</param>
- public static void RunWinForms<T1, T2, T3, T4, T5, T6, T7>(string[] args, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7)
- { new Parser<T1, T2, T3, T4, T5, T6, T7>().WinForms().RunTargets(args, t1, t2, t3, t4, t5, t6, t7); }
+ public static int RunWinForms<T1, T2, T3, T4, T5, T6, T7>(string[] args, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7)
+ { return new Parser<T1, T2, T3, T4, T5, T6, T7>().WinForms().RunTargets(args, t1, t2, t3, t4, t5, t6, t7); }
/// <summary>
/// Executes a generic winforms static parser of some specified types
/// </summary>
/// <param name="args">The user arguments</param>
- public static void RunWinForms<T1, T2, T3, T4, T5, T6, T7, T8>(string[] args)
- { new Parser<T1, T2, T3, T4, T5, T6, T7, T8>().WinForms().RunStatic(args); }
+ public static int RunWinForms<T1, T2, T3, T4, T5, T6, T7, T8>(string[] args)
+ { return new Parser<T1, T2, T3, T4, T5, T6, T7, T8>().WinForms().RunStatic(args); }
/// <summary>
/// Executes a generic winforms parser of some specified types
@@ -202,15 +202,15 @@ public static void RunWinForms<T>(string[] args, T t)
/// <param name="t6">An instance of the verb class</param>
/// <param name="t7">An instance of the verb class</param>
/// <param name="t8">An instance of the verb class</param>
- public static void RunWinForms<T1, T2, T3, T4, T5, T6, T7, T8>(string[] args, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8)
- { new Parser<T1, T2, T3, T4, T5, T6, T7, T8>().WinForms().RunTargets(args, t1, t2, t3, t4, t5, t6, t7, t8); }
+ public static int RunWinForms<T1, T2, T3, T4, T5, T6, T7, T8>(string[] args, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8)
+ { return new Parser<T1, T2, T3, T4, T5, T6, T7, T8>().WinForms().RunTargets(args, t1, t2, t3, t4, t5, t6, t7, t8); }
/// <summary>
/// Executes a generic winforms static parser of some specified types
/// </summary>
/// <param name="args">The user arguments</param>
- public static void RunWinForms<T1, T2, T3, T4, T5, T6, T7, T8, T9>(string[] args)
- { new Parser<T1, T2, T3, T4, T5, T6, T7, T8, T9>().WinForms().RunStatic(args); }
+ public static int RunWinForms<T1, T2, T3, T4, T5, T6, T7, T8, T9>(string[] args)
+ { return new Parser<T1, T2, T3, T4, T5, T6, T7, T8, T9>().WinForms().RunStatic(args); }
/// <summary>
/// Executes a generic winforms parser of some specified types
@@ -234,7 +234,7 @@ public static void RunWinForms<T>(string[] args, T t)
/// <param name="t7">An instance of the verb class</param>
/// <param name="t8">An instance of the verb class</param>
/// <param name="t9">An instance of the verb class</param>
- public static void RunWinForms<T1, T2, T3, T4, T5, T6, T7, T8, T9>(string[] args, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9)
- { new Parser<T1, T2, T3, T4, T5, T6, T7, T8, T9>().WinForms().RunTargets(args, t1, t2, t3, t4, t5, t6, t7, t8, t9); }
+ public static int RunWinForms<T1, T2, T3, T4, T5, T6, T7, T8, T9>(string[] args, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9)
+ { return new Parser<T1, T2, T3, T4, T5, T6, T7, T8, T9>().WinForms().RunTargets(args, t1, t2, t3, t4, t5, t6, t7, t8, t9); }
}
}
View
20 CLAP/ParserRunner.cs
@@ -51,20 +51,20 @@ internal ParserRunner(Type type, ParserRegistration parserRegistration)
#region Public Methods
- public void Run(string[] args, object obj)
+ public int Run(string[] args, object obj)
{
- TryRunInternal(args, obj);
+ return TryRunInternal(args, obj);
}
#endregion Public Methods
#region Private Methods
- private void TryRunInternal(string[] args, object obj)
+ private int TryRunInternal(string[] args, object obj)
{
try
{
- RunInternal(args, obj);
+ return RunInternal(args, obj);
}
catch (Exception ex)
{
@@ -74,10 +74,12 @@ private void TryRunInternal(string[] args, object obj)
{
throw;
}
+
+ return MultiParser.ErrorCode;
}
}
- private void RunInternal(string[] args, object obj)
+ private int RunInternal(string[] args, object obj)
{
//
// *** empty args are handled by the multi-parser
@@ -92,7 +94,7 @@ private void RunInternal(string[] args, object obj)
if (HandleHelp(firstArg, obj))
{
- return;
+ return MultiParser.ErrorCode;
}
var verb = firstArg;
@@ -155,10 +157,10 @@ private void RunInternal(string[] args, object obj)
throw new UnhandledParametersException(inputArgs);
}
- Execute(obj, method, parameterValues);
+ return Execute(obj, method, parameterValues);
}
- private void Execute(
+ private int Execute(
object target,
Method method,
ParameterAndValue[] parameters)
@@ -207,6 +209,8 @@ private void RunInternal(string[] args, object obj)
}
}
}
+
+ return verbException == null ? MultiParser.SuccessCode : MultiParser.ErrorCode;
}
private void PostInterception(
View
4 ConsoleTest/Program.cs
@@ -11,12 +11,12 @@ namespace ConsoleTest
{
class Program
{
- static void Main(string[] args)
+ static int Main(string[] args)
{
//Debugger.Launch();
//Parser.RunConsole<TheApp>(args);
- Parser.RunConsole<ClapApp, SomeApp, TheApp>(args);
+ return Parser.RunConsole<ClapApp, SomeApp, TheApp>(args);
//Parser.Run<SomeApp, ClapApp>(args);
}
}

0 comments on commit cab1ff6

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