示例#1
0
 public Option(string shortKey, string longKey, string description, params IArgument[] arguments)
     : this()
 {
     Key = new OptionKeys
     {
         Long = longKey,
         Short = shortKey
     };
     Description = description;
     Arguments = arguments.ToList();
 }
示例#2
0
 public void ChooseAccount()
 {
     var optionKeys = new OptionKeys(() => {
         WriteAccountList();
         "Insert the number of the account to display:".WriteLine();
     });
     optionKeys.Options(_accounts.Count(),
         accountIndex => {
             var account = _accounts.Skip(accountIndex).First();
             DisplayAccount(account);
         })
         .ChooseAndLoopOptions();
 }
        private void DoParse(string configuration, bool ignoreUnknown)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            if (string.IsNullOrWhiteSpace(configuration))
            {
                throw new ArgumentException("is empty", configuration);
            }

            Clear();

            // break it down by commas
            var arr = configuration.Split(StringSplits.Comma);
            Dictionary <string, string> map = null;

            foreach (var paddedOption in arr)
            {
                var option = paddedOption.Trim();

                if (string.IsNullOrWhiteSpace(option))
                {
                    continue;
                }

                // check for special tokens
                int idx = option.IndexOf('=');
                if (idx > 0)
                {
                    var key   = option.Substring(0, idx).Trim();
                    var value = option.Substring(idx + 1).Trim();

                    switch (OptionKeys.TryNormalize(key))
                    {
                    case OptionKeys.SyncTimeout:
                        SyncTimeout = OptionKeys.ParseInt32(key, value, minValue: 1);
                        break;

                    case OptionKeys.AllowAdmin:
                        AllowAdmin = OptionKeys.ParseBoolean(key, value);
                        break;

                    case OptionKeys.AbortOnConnectFail:
                        AbortOnConnectFail = OptionKeys.ParseBoolean(key, value);
                        break;

                    case OptionKeys.ResolveDns:
                        ResolveDns = OptionKeys.ParseBoolean(key, value);
                        break;

                    case OptionKeys.ServiceName:
                        ServiceName = value;
                        break;

                    case OptionKeys.ClientName:
                        ClientName = value;
                        break;

                    case OptionKeys.ChannelPrefix:
                        ChannelPrefix = value;
                        break;

                    case OptionKeys.ConfigChannel:
                        ConfigurationChannel = value;
                        break;

                    case OptionKeys.KeepAlive:
                        KeepAlive = OptionKeys.ParseInt32(key, value);
                        break;

                    case OptionKeys.ConnectTimeout:
                        ConnectTimeout = OptionKeys.ParseInt32(key, value);
                        break;

                    case OptionKeys.ConnectRetry:
                        ConnectRetry = OptionKeys.ParseInt32(key, value);
                        break;

                    case OptionKeys.ConfigCheckSeconds:
                        ConfigCheckSeconds = OptionKeys.ParseInt32(key, value);
                        break;

                    case OptionKeys.Version:
                        DefaultVersion = OptionKeys.ParseVersion(key, value);
                        break;

                    case OptionKeys.Password:
                        Password = value;
                        break;

                    case OptionKeys.TieBreaker:
                        TieBreaker = value;
                        break;

                    case OptionKeys.Ssl:
                        Ssl = OptionKeys.ParseBoolean(key, value);
                        break;

                    case OptionKeys.SslHost:
                        SslHost = value;
                        break;

                    case OptionKeys.HighPrioritySocketThreads:
                        HighPrioritySocketThreads = OptionKeys.ParseBoolean(key, value);
                        break;

                    case OptionKeys.WriteBuffer:
                        WriteBuffer = OptionKeys.ParseInt32(key, value);
                        break;

                    case OptionKeys.Proxy:
                        Proxy = OptionKeys.ParseProxy(key, value);
                        break;

                    case OptionKeys.ResponseTimeout:
                        ResponseTimeout = OptionKeys.ParseInt32(key, value, minValue: 1);
                        break;

                    case OptionKeys.DefaultDatabase:
                        defaultDatabase = OptionKeys.ParseInt32(key, value);
                        break;

                    case OptionKeys.PreserveAsyncOrder:
                        PreserveAsyncOrder = OptionKeys.ParseBoolean(key, value);
                        break;

#if !CORE_CLR
                    case OptionKeys.SslProtocols:
                        SslProtocols = OptionKeys.ParseSslProtocols(key, value);
                        break;
#endif
                    default:
                        if (!string.IsNullOrEmpty(key) && key[0] == '$')
                        {
                            RedisCommand cmd;
                            var          cmdName = option.Substring(1, idx - 1);
                            if (Enum.TryParse(cmdName, true, out cmd))
                            {
                                if (map == null)
                                {
                                    map = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);
                                }
                                map[cmdName] = value;
                            }
                        }
                        else
                        {
                            if (!ignoreUnknown)
                            {
                                OptionKeys.Unknown(key);
                            }
                        }
                        break;
                    }
                }
                else
                {
                    var ep = Format.TryParseEndPoint(option);
                    if (ep != null && !endpoints.Contains(ep))
                    {
                        endpoints.Add(ep);
                    }
                }
            }
            if (map != null && map.Count != 0)
            {
                CommandMap = CommandMap.Create(map);
            }
        }
示例#4
0
 //getter for possible keys
 public string[] GetOptionKeys()
 {
     return(OptionKeys.Split(","));
 }
示例#5
0
        public static OptionKeys Options <T>(this string message, T[] items, Action <int, T> displayItem, Action <T> itemSelectedAction)
        {
            var optionKeys = new OptionKeys(message);

            return(optionKeys.Options(items, displayItem, itemSelectedAction));
        }
示例#6
0
 internal Software(CodecApiElement parent, string propertyName)
     : base(parent, propertyName)
 {
     _optionKeys = new OptionKeys(this, "OptionKeys");
 }