/// <summary>
        /// Initializes a new instance of the <see cref="CommandLineArguments"/> class.
        /// Parses and validates the known command line arguments. Any extra switches
        /// are ignored.
        /// </summary>
        /// <param name="args">The arguments.</param>
        public CommandLineArguments(string[] args)
        {
            OutputFormat = OutputFormat.Unspecified;
            YellowBand = 90;
            GreenBand = 100;
            TestFiles = new List<string>();
            RemainingArguments = new List<string>();

            if (args == null || args.Count() == 0)
            {
                ErrorMessage = "Error: No arguments specified.";
                return;
            }

            // Parse arguments.
            var fileGlobArguments = new List<string>();
            bool lookingAtFileArguments = false;
            foreach (string arg in args)
            {
                if (lookingAtFileArguments)
                {
                    fileGlobArguments.Add(arg);
                }
                else
                {
                    if (IsOptionArgument(arg))
                    {
                        ParseArgument(arg);
                    }
                    else
                    {
                        lookingAtFileArguments = true;
                        fileGlobArguments.Add(arg);
                    }
                }
            }

            // Validate them.
            if (OutputFilename != null && OutputFormat != OutputFormat.Unspecified)
            {
                ErrorMessage = "Error: If /of is specified /fmt cannot be used.";
                return;
            }

            if (OutputFilename == null && OutputFormat == OutputFormat.Unspecified)
            {
                OutputFormat = OutputFormat.CSV;
            }
            else
            {
                if (OutputFilename != null)
                {
                    string extension = Path.GetExtension(OutputFilename).Substring(1);
                    OutputFormat = GetFormat(extension);
                    if (OutputFormat == OutputFormat.Unspecified)
                        return;
                }
            }

            if (fileGlobArguments.Count == 0)
            {
                ErrorMessage = "Error: No test files specified.";
                return;
            }

            // Generate globbed list of test files to act as input.
            var finder = new FileFinder();
            TestFiles = finder.FindFiles(fileGlobArguments).ToList();

            if (TestFiles.Count == 0)
            {
                ErrorMessage = "Error: No test files found.";
                return;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CommandLineArguments"/> class.
        /// Parses and validates the known command line arguments. Any extra switches
        /// are ignored.
        /// </summary>
        /// <param name="args">The arguments.</param>
        public CommandLineArguments(string[] args)
        {
            OutputFormat       = OutputFormat.Unspecified;
            YellowBand         = 90;
            GreenBand          = 100;
            TestFiles          = new List <string>();
            RemainingArguments = new List <string>();

            if (args == null || args.Count() == 0)
            {
                ErrorMessage = "Error: No arguments specified.";
                return;
            }

            // Parse arguments.
            var  fileGlobArguments      = new List <string>();
            bool lookingAtFileArguments = false;

            foreach (string arg in args)
            {
                if (lookingAtFileArguments)
                {
                    fileGlobArguments.Add(arg);
                }
                else
                {
                    if (IsOptionArgument(arg))
                    {
                        ParseArgument(arg);
                    }
                    else
                    {
                        lookingAtFileArguments = true;
                        fileGlobArguments.Add(arg);
                    }
                }
            }

            // Validate them.
            if (OutputFilename != null && OutputFormat != OutputFormat.Unspecified)
            {
                ErrorMessage = "Error: If /of is specified /fmt cannot be used.";
                return;
            }

            if (OutputFilename == null && OutputFormat == OutputFormat.Unspecified)
            {
                OutputFormat = OutputFormat.CSV;
            }
            else
            {
                if (OutputFilename != null)
                {
                    string extension = Path.GetExtension(OutputFilename).Substring(1);
                    OutputFormat = GetFormat(extension);
                    if (OutputFormat == OutputFormat.Unspecified)
                    {
                        return;
                    }
                }
            }

            if (fileGlobArguments.Count == 0)
            {
                ErrorMessage = "Error: No test files specified.";
                return;
            }

            // Generate globbed list of test files to act as input.
            var finder = new FileFinder();

            TestFiles = finder.FindFiles(fileGlobArguments).ToList();

            if (TestFiles.Count == 0)
            {
                ErrorMessage = "Error: No test files found.";
                return;
            }
        }