예제 #1
0
        /// <summary>
        /// Ensures the consistency of the SingleFileOptionsBase command line options related to
        /// the location of the output file, and adjusts the options for ease of use.
        /// </summary>
        /// <param name="options">
        /// A <see cref="SingleFileOptionsBase"/> object containing the relevant options.
        /// </param>
        /// <returns>
        /// true if the options are internally consistent; otherwise false.
        /// </returns>
        public static bool ValidateOutputOptions(this SingleFileOptionsBase options)
        {
            bool valid = true;

            if (options.Inline)
            {
                if (options.OutputFilePath == null)
                {
                    options.Force          = true;
                    options.OutputFilePath = options.InputFilePath;
                }
                else
                {
                    ReportInvalidOutputOptions(options);
                    valid = false;
                }
            }
            else
            {
                if (options.OutputFilePath == null)
                {
                    ReportInvalidOutputOptions(options);
                    valid = false;
                }
            }

            return(valid);
        }
예제 #2
0
        /// <summary>
        /// Ensures the consistency of the command line options related to the location and format
        /// of the output file, and adjusts the options for ease of use.
        /// </summary>
        /// <param name="options">
        /// A <see cref="SingleFileOptionsBase"/> object containing the command line options.
        /// </param>
        /// <returns>
        /// true if the options are internally consistent; otherwise false.
        /// </returns>
        public static bool Validate(this SingleFileOptionsBase options)
        {
            bool valid = true;

            valid &= options.ValidateOutputLocationOptions();
            valid &= options.ValidateOutputFormatOptions();

            return(valid);
        }
예제 #3
0
        private static void ReportInvalidOutputOptions(SingleFileOptionsBase options)
        {
            string inlineOptionsDescription        = DriverUtilities.GetOptionDescription <SingleFileOptionsBase>(nameof(options.Inline));
            string outputFilePathOptionDescription = DriverUtilities.GetOptionDescription <SingleFileOptionsBase>(nameof(options.OutputFilePath));

            Console.Error.WriteLine(
                string.Format(
                    CultureInfo.CurrentCulture,
                    DriverResources.ExactlyOneOfTwoOptionsIsRequired,
                    inlineOptionsDescription,
                    outputFilePathOptionDescription));
        }
        private static bool ValidateOutputFormatOptions(this SingleFileOptionsBase options)
        {
            bool valid = true;

            if (options.PrettyPrint && options.Minify)
            {
                ReportInvalidOutputFormatOptions();
                valid = false;
            }
            else if (!options.PrettyPrint && !options.Minify)
            {
                options.PrettyPrint = true;
            }

            return(valid);
        }
        /// <summary>
        /// Ensures the consistency of the command line options related to the location and format
        /// of the output file, and adjusts the options for ease of use.
        /// </summary>
        /// <param name="options">
        /// A <see cref="SingleFileOptionsBase"/> object containing the command line options.
        /// </param>
        /// <returns>
        /// true if the options are internally consistent; otherwise false.
        /// </returns>
        public static bool Validate(this SingleFileOptionsBase options)
        {
            if (options.SarifOutputVersion == SarifVersion.Unknown)
            {
                //  Parsing the output version failed and the the enum evaluated to 0.
                Console.WriteLine(DriverResources.ErrorInvalidTransformTargetVersion);
                return(false);
            }

            if (!options.ValidateOutputLocationOptions())
            {
                return(false);
            }

            if (!options.ValidateOutputFormatOptions())
            {
                return(false);
            }

            return(true);
        }