コード例 #1
0
ファイル: Args.cs プロジェクト: jiaw37/PowerArgs
 /// <summary>
 /// Parses the args for the given definition and then calls the Main() method defined by the type.
 /// </summary>
 /// <param name="definition">The command line definition to parse</param>
 /// <param name="args">the command line values</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, () =>
     {
         return new ArgAction()
         {
             Cancelled = true,
             Definition = definition,
             Context = ArgHook.HookContext.Current,
         };
     }));
 }
コード例 #2
0
ファイル: Args.cs プロジェクト: zuiwanting/EventStore
 /// <summary>
 /// Creates a new instance of T and populates it's properties based on the given arguments.
 /// If T correctly implements the heuristics for Actions (or sub commands) then the complex property
 /// that represents the options of a sub command are also populated.
 /// </summary>
 /// <typeparam name="T">The argument scaffold type.</typeparam>
 /// <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<T> ParseAction<T>(params string[] args)
 {
     ArgAction<T> ret = Execute<ArgAction<T>>(() =>
     {
     Args instance = new Args();
     return instance.ParseInternal<T>(args);
     });
     return ret;
 }
コード例 #3
0
ファイル: Args.cs プロジェクト: olivierh59500/inVtero.net
        /// <summary>
        /// Parses the given arguments using a command line arguments definition.
        /// </summary>
        /// <param name="definition">The definition that defines a set of command line arguments and/or actions.</param>
        /// <param name="args">The command line arguments to parse</param>
        /// <returns></returns>
        public static ArgAction ParseAction(CommandLineArgumentsDefinition definition, params string[] args)
        {
            ArgAction ret = Execute(() =>
            {
                Args instance = new Args();
                return(instance.ParseInternal(definition, args));
            });

            return(ret);
        }
コード例 #4
0
ファイル: Args.cs プロジェクト: kfrugia-newrelic/PowerArgs
        /// <summary>
        /// Creates a new instance of the given type and populates it's properties based on the given arguments.
        /// </summary>
        /// <param name="t">The argument scaffold type</param>
        /// <param name="args">The command line arguments to parse</param>
        /// <returns>A new instance of the given type with all of the properties correctly populated</returns>
        public static object Parse(Type t, params string[] args)
        {
            object ret = Execute(() =>
            {
                Args instance = new Args();
                return(instance.ParseInternal(t, args).Value);
            });

            return(ret);
        }
コード例 #5
0
ファイル: Args.cs プロジェクト: kfrugia-newrelic/PowerArgs
        /// <summary>
        /// Creates a new instance of T and populates it's properties based on the given arguments.
        /// </summary>
        /// <typeparam name="T">The argument scaffold type.</typeparam>
        /// <param name="args">The command line arguments to parse</param>
        /// <returns>A new instance of T with all of the properties correctly populated</returns>
        public static T Parse <T>(params string[] args) where T : class
        {
            T ret = Execute(() =>
            {
                Args instance = new Args();
                return(instance.ParseInternal <T>(args).Args);
            });

            return(ret);
        }
コード例 #6
0
ファイル: Args.cs プロジェクト: kfrugia-newrelic/PowerArgs
        /// <summary>
        /// Creates a new instance of the given type and populates it's properties based on the given arguments.
        /// If the type correctly implements the heuristics for Actions (or sub commands) then the complex property
        /// that represents the options of a sub command are also populated.
        /// </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 ParseAction(Type t, params string[] args)
        {
            ArgAction ret = Execute <ArgAction>(() =>
            {
                Args instance = new Args();
                return(instance.ParseInternal(t, args));
            });

            return(ret);
        }
コード例 #7
0
ファイル: Args.cs プロジェクト: olivierh59500/inVtero.net
 /// <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.Invoke();
             }
             return result;
         });
     }, args));
 }
コード例 #8
0
ファイル: Args.cs プロジェクト: kfrugia-newrelic/PowerArgs
 /// <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));
 }
コード例 #9
0
ファイル: Args.cs プロジェクト: atruskie/PowerArgs
        /// <summary>
        /// Creates a new instance of the given type and populates it's properties based on the given arguments.
        /// If the type correctly implements the heuristics for Actions (or sub commands) then the complex property
        /// that represents the options of a sub command are also populated.
        /// </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 ParseAction(Type t, params string[] args)
        {
            Args instance = new Args();

            return(instance.ParseInternal(t, args));
        }
コード例 #10
0
ファイル: Args.cs プロジェクト: atruskie/PowerArgs
        /// <summary>
        /// Creates a new instance of T and populates it's properties based on the given arguments.
        /// If T correctly implements the heuristics for Actions (or sub commands) then the complex property
        /// that represents the options of a sub command are also populated.
        /// </summary>
        /// <typeparam name="T">The argument scaffold type.</typeparam>
        /// <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 <T> ParseAction <T>(params string[] args)
        {
            Args instance = new Args();

            return(instance.ParseInternal <T>(args));
        }