Esempio n. 1
0
        public DotNetCommandLineOptions Parse(IEnumerable <string> args)
        {
            IEnumerable <string> dotNetTestArgs = args.TakeWhile(arg => arg != nspecArgDivider);
            IEnumerable <string> nspecArgs      = args.Skip(dotNetTestArgs.Count() + 1);

            var options = new DotNetCommandLineOptions();

            // look for first argument (the project), before remaining dotnet-test options

            string firstArg = dotNetTestArgs.FirstOrDefault();

            if (IsUnknownArgument(firstArg))
            {
                options.Project = firstArg;

                dotNetTestArgs = dotNetTestArgs.Skip(1);
            }

            // look for remaining dotnet-test options

            IEnumerable <string> remainingArgs;

            remainingArgs = ParsingUtils.SetIntForOptionalArg(dotNetTestArgs,
                                                              parentProcessArgKey, value => options.ParentProcessId = value);

            remainingArgs = ParsingUtils.SetIntForOptionalArg(remainingArgs,
                                                              portArgKey, value => options.Port = value);

            remainingArgs = ParsingUtils.SetBoolForSwitchArg(remainingArgs,
                                                             designTimeArgKey, value => options.DesignTime = value);

            remainingArgs = ParsingUtils.SetBoolForSwitchArg(remainingArgs,
                                                             listArgKey, value => options.List = value);

            remainingArgs = ParsingUtils.SetBoolForSwitchArg(remainingArgs,
                                                             waitCommandArgKey, value => options.WaitCommand = value);

            options.NSpecArgs = nspecArgs.ToArray();

            options.UnknownArgs = remainingArgs.ToArray();

            return(options);
        }
Esempio n. 2
0
        public NSpecCommandLineOptions Parse(IEnumerable <string> args)
        {
            IEnumerable <string> remainingArgs;

            // set default option values

            var options = new NSpecCommandLineOptions()
            {
                FormatterOptions = new Dictionary <string, string>(),
                DebugTests       = new string[0],
            };

            // check for first argument (the class name), before remaining named options

            string firstArg = args.FirstOrDefault();

            if (IsUnknownArgument(firstArg))
            {
                options.ClassName = firstArg;

                remainingArgs = args.Skip(1);
            }
            else
            {
                remainingArgs = args;
            }

            // check for remaining named options

            remainingArgs = ParsingUtils.SetTextForOptionalArg(remainingArgs,
                                                               tagsKey, allKnownTokens, value => options.Tags = value);

            remainingArgs = ParsingUtils.SetBoolForSwitchArg(remainingArgs,
                                                             failFastKey, value => options.FailFast = value);

            remainingArgs = ParsingUtils.SetTextForOptionalArgPrefix(remainingArgs,
                                                                     formatterPrefix, value => options.FormatterName = value);

            remainingArgs = ParsingUtils.SetBoolForSwitchArg(remainingArgs,
                                                             debugChannelKey, value => options.DebugChannel = value);

            remainingArgs = ParsingUtils.SetTextForOptionalArg(remainingArgs,
                                                               debugTestsKey, allKnownTokens, value =>
            {
                options.DebugTests = value.Split(',')
                                     .Select(token => token.Trim())
                                     .ToArray();
            });

            int lastCount;

            do
            {
                lastCount = remainingArgs.Count();

                remainingArgs = ParsingUtils.SetTextForOptionalArgPrefix(remainingArgs,
                                                                         formatterOptionsPrefix, text =>
                {
                    string[] tokens = text.Split('=');

                    if (tokens.Length > 2)
                    {
                        throw new ArgumentException(
                            $"Formatter option '{text}' must be either a single 'flag' or a 'name=value' pair");
                    }

                    string name  = tokens.First();
                    string value = tokens.Last();

                    options.FormatterOptions[name] = value;
                });
            } while (lastCount != remainingArgs.Count());

            options.UnknownArgs = remainingArgs.ToArray();

            return(options);
        }