Ejemplo n.º 1
0
        /// <summary>
        /// Extract the target to be called and its arguments from command line arguments
        /// </summary>
        /// <param name="arguments">all command line arguments (required for error display)</param>
        /// <param name="options">parsed options</param>
        /// <returns></returns>
        static (MethodInfo target, string[] arguments) ParseCommandLineTarget(string[] arguments, Options options)
        {
            var targetAndArguments = options.TargetAndArguments;
            var targets            = options.Targets;

            if (targetAndArguments.Length == 0)
            {
                try
                {
                    return(GetDefaultTarget(targets), new string[] { });
                }
                catch (Exception e)
                {
                    throw new ParseException(arguments, -1, e);
                }
            }

            var candidates = HelpText.PublicTargets(targets.GetType());

            var targetName      = targetAndArguments[0];
            var targetArguments = targetAndArguments.Skip(1).ToArray();

            try
            {
                var target = candidates.FindByName(
                    _ => GetOptParser.GetLongOptionNameForMember(_.Name),
                    targetName,
                    "targets"
                    );
                return(target, targetArguments);
            }
            catch (ArgumentOutOfRangeException e)
            {
                throw new ParseException(arguments, Array.IndexOf(arguments, targetName), e);
            }
        }
Ejemplo n.º 2
0
 private static string Syntax(MethodInfo method)
 {
     return(new[] { GetOptParser.GetLongOptionNameForMember(method.Name), }
            .Concat(method.GetParameters().Select(_ => $"<{_.Name}>"))
            .Join(" "));
 }