Esempio n. 1
0
        /// <summary>
        /// Builds a string that contains a parsing error message.
        /// </summary>
        /// <param name="options">The typed instance that collected command line arguments parsed with the <see cref="CommandLine.CommandLineParser"/> class.</param>
        /// <returns>The <see cref="System.String"/> that contains the parsing error message.</returns>
        public string RenderParsingErrorsText(CommandLineOptionsBase options)
        {
            Assumes.NotNull(options, "options");

            PostParsingState state = options.LastPostParsingState;
            var badOption          = state.BadOptionInfo;

            // other violations requires BadOptionInfo to be initialized
            if (badOption == null && !state.ViolatesMutualExclusiveness)
            {
                return(string.Empty);
            }

            var errorsText = new StringBuilder(_builderCapacity);

            if (state.ViolatesRequired)
            {
                errorsText.AppendFormat(GetMessageText(MessageEnum.ParsingErrorViolatesRequired), badOption.NameWithSwitch);
            }
            else if (state.ViolatesFormat)
            {
                errorsText.AppendFormat(GetMessageText(MessageEnum.ParsingErrorViolatesFormat), badOption.NameWithSwitch);
            }
            else
            {
                errorsText.Append(GetMessageText(MessageEnum.ParsingErrorViolatesExclusiveness));
            }

            return(errorsText.ToString());
        }
 public CommandLineOptionsBase()
 {
     LastPostParsingState = new PostParsingState();
 }