Exemple #1
0
        public static IDictionary <string, object> ArgumentsToDictionary(string[] arguments)
        {
            if (arguments == null)
            {
                throw new ArgumentNullException(nameof(arguments));
            }

            var properties = new Dictionary <string, object>(arguments.Length);

            foreach (var item in arguments)
            {
                var text = IsWrappedOfQuote(item) ? TrimQuot(item) : item;
                text = Regex.Unescape(text);

                if (CommandStringUtility.TryGetKeyValue(text, out var key, out var value) == true)
                {
                    if (CommandStringUtility.IsWrappedOfQuote(value))
                    {
                        properties.Add(key, CommandStringUtility.TrimQuot(value));
                    }
                    else if (decimal.TryParse(value, out decimal l) == true)
                    {
                        properties.Add(key, l);
                    }
                    else if (bool.TryParse(value, out bool b) == true)
                    {
                        properties.Add(key, b);
                    }
                    else
                    {
                        properties.Add(key, value);
                    }
                }
Exemple #2
0
        private void CompletionImpl(Func <string[], string, string> func)
        {
            var matches  = new List <Match>(CommandStringUtility.MatchCompletion(this.inputText));
            var find     = string.Empty;
            var prefix   = false;
            var postfix  = false;
            var leftText = this.inputText;

            if (matches.Count > 0)
            {
                var match     = matches.Last();
                var matchText = match.Value;
                if (matchText.Length > 0 && matchText.First() == '\"')
                {
                    prefix    = true;
                    matchText = matchText.Substring(1);
                }
                if (matchText.Length > 1 && matchText.Last() == '\"')
                {
                    postfix   = true;
                    matchText = matchText.Remove(matchText.Length - 1);
                }
                if (matchText == string.Empty || matchText.Trim() != string.Empty)
                {
                    find = matchText;
                    matches.RemoveAt(matches.Count - 1);
                    leftText = this.inputText.Remove(match.Index);
                }
            }

            var argList = new List <string>();

            for (var i = 0; i < matches.Count; i++)
            {
                var matchText = CommandStringUtility.TrimQuot(matches[i].Value).Trim();
                if (matchText != string.Empty)
                {
                    argList.Add(matchText);
                }
            }

            var completions = this.GetCompletion(argList.ToArray(), find);

            if (completions != null && completions.Any())
            {
                this.completion = func(completions, this.completion);
                var inputText = this.inputText;

                if (prefix == true || postfix == true)
                {
                    this.promptBlock.Inlines.Clear();
                    this.promptBlock.Inlines.Add(new Run()
                    {
                        Text = this.Prompt + leftText + "\"" + this.completion + "\"",
                    });
                }
                else
                {
                    this.promptBlock.Inlines.Clear();
                    this.promptBlock.Inlines.Add(new Run()
                    {
                        Text = this.Prompt + leftText + this.completion,
                    });
                }
                this.inputText = inputText;
            }
        }