예제 #1
0
        public static ParseResult <bool> ToBool(string rawValue, IBoolOption option)
        {
            var value = rawValue.ToLowerInvariant();

            if (option.MatchesTrue(value) && !option.MatchesFalse(value))
            {
                return(ParseResult.AsSuccess(true));
            }
            if (!option.MatchesTrue(value) && option.MatchesFalse(value))
            {
                return(ParseResult.AsSuccess(false));
            }

            return(ParseResult.AsError <bool>($"Please enter a {option}."));
        }
예제 #2
0
 public bool ReadBool(string prompt, IBoolOption option = null, bool required = false, bool defaultValue = default, Func <bool, string> validator = null)
 {
     option = option ?? BoolOptions.All;
     return(Read(prompt, required, defaultValue, (v) => Parsers.ToBool(v, option), validator));
 }