Beispiel #1
0
 /// <summary>
 /// Parses the args for the given definition and then calls the Main() method defined by the type.
 /// </summary>
 /// <param name="definition"></param>
 /// <param name="args"></param>
 /// <returns></returns>
 public static ArgAction InvokeMain(CommandLineArgumentsDefinition definition, params string[] args)
 {
     return(REPL.DriveREPL <ArgAction>(definition.Metadata.Meta <TabCompletion>(), (a) =>
     {
         return Execute <ArgAction>(() =>
         {
             Args instance = new Args();
             var result = instance.ParseInternal(definition, a);
             if (result.HandledException == null)
             {
                 result.Context.RunBeforeInvoke();
                 result.Value.InvokeMainMethod();
                 result.Context.RunAfterInvoke();
             }
             return result;
         });
     }, args));
 }
Beispiel #2
0
 /// <summary>
 /// Parses the given arguments using a command line arguments definition.  Then, invokes the action
 /// that was specified.
 /// </summary>
 /// <param name="definition">The definition that defines a set of command line arguments and actions.</param>
 /// <param name="args"></param>
 /// <returns>The raw result of the parse with metadata about the specified action.  The action is executed before returning.</returns>
 public static ArgAction InvokeAction(CommandLineArgumentsDefinition definition, params string[] args)
 {
     return(REPL.DriveREPL <ArgAction>(definition.Hooks.Where(h => h is TabCompletion).Select(h => h as TabCompletion).SingleOrDefault(), (a) =>
     {
         return Execute <ArgAction>(() =>
         {
             Args instance = new Args();
             var result = instance.ParseInternal(definition, a);
             if (result.HandledException == null)
             {
                 result.Context.RunBeforeInvoke();
                 result.Invoke();
                 result.Context.RunAfterInvoke();
             }
             return result;
         });
     }, args));
 }
Beispiel #3
0
 /// <summary>
 /// Creates a new instance of T and populates it's properties based on the given arguments. T must correctly
 /// implement the heuristics for Actions (or sub commands) because this method will not only detect the action
 /// specified on the command line, but will also find and execute the method that implements the action.
 /// </summary>
 /// <typeparam name="T">The argument scaffold type that must properly implement at least one action.</typeparam>
 /// <param name="args">The command line arguments to parse</param>
 /// <returns>The raw result of the parse with metadata about the specified action.  The action is executed before returning.</returns>
 public static ArgAction <T> InvokeAction <T>(params string[] args)
 {
     return(REPL.DriveREPL <ArgAction <T> >(typeof(T).Attr <TabCompletion>(), (a) =>
     {
         return Execute <ArgAction <T> >(() =>
         {
             Args instance = new Args();
             var result = instance.ParseInternal <T>(a);
             if (result.HandledException == null)
             {
                 result.Context.RunBeforeInvoke();
                 result.Invoke();
                 result.Context.RunAfterInvoke();
             }
             return result;
         });
     }, args));
 }
Beispiel #4
0
 /// <summary>
 /// Creates a new instance of T and populates it's properties based on the given arguments. T must correctly
 /// implement the heuristics for Actions (or sub commands) because this method will not only detect the action
 /// specified on the command line, but will also find and execute the method that implements the action.
 /// </summary>
 /// <typeparam name="T">The argument scaffold type that must properly implement at least one action.</typeparam>
 /// <param name="args">The command line arguments to parse</param>
 /// <returns>The raw result of the parse with metadata about the specified action.  The action is executed before returning.</returns>
 public static ArgAction<T> InvokeAction<T>(params string[] args)
 {
     ArgAction<T> ret = Execute<ArgAction<T>>(() =>
     {
         return REPL.DriveREPL<ArgAction<T>>(typeof(T).Attr<TabCompletion>(), (a) =>
         {
         var result = ParseAction<T>(a);
             if (result.HandledException == null)
             {
                 result.Context.RunBeforeInvoke();
                 result.Invoke();
                 result.Context.RunAfterInvoke();
             }
         return result;
     }
     , args);
     });
     return ret;
 }
Beispiel #5
0
        /// <summary>
        /// Parses the args for the given scaffold type and then calls the Main() method defined by the type.
        /// </summary>
        /// <param name="t">The argument scaffold type.</param>
        /// <param name="args">The command line arguments to parse</param>
        /// <returns>The raw result of the parse with metadata about the specified action.</returns>
        public static ArgAction InvokeMain(Type t, params string[] args)
        {
            ArgAction ret = Execute(() =>
            {
                return REPL.DriveREPL<ArgAction>(t.Attr<TabCompletion>(), (a) =>
                {
                var result = ParseAction(t, a);
                    if (result.HandledException == null)
                    {
                        result.Context.RunBeforeInvoke();
                        result.Value.InvokeMainMethod();
                        result.Context.RunAfterInvoke();
                    }
                return result;
            }
            , args);
            });

            return ret;
        }