コード例 #1
0
        private static string[] getSuggestedOptions(Iterator <string> iter, CCommand cmd, string optNameToken, string prefix)
        {
            List <Option> optionsList = new List <Option>(); // TODO: reuse list

            // list options
            bool useShort = prefix.Equals("-");

            if (useShort)
            {
                cmd.ListShortOptions(optionsList, optNameToken);
                optionsList.Sort(delegate(Option op1, Option op2) {
                    return(op1.ShortName.CompareTo(op2.ShortName));
                });
            }
            else
            {
                cmd.ListOptions(optionsList, optNameToken);
                optionsList.Sort(delegate(Option op1, Option op2) {
                    return(op1.Name.CompareTo(op2.Name));
                });
            }

            if (optionsList.Count > 1) // multiple options available
            {
                return(getSuggestedOptions(optionsList, useShort));
            }

            if (optionsList.Count == 1) // single option available
            {
                Option opt = optionsList[0];

                if (isOptionNameMatch(opt, optNameToken, useShort)) // option name already matched - try values
                {
                    if (opt.HasValues())                            // option has predefined values?
                    {
                        if (iter.HasNext())                         // has value token?
                        {
                            return(opt.ListValues(iter.Next()));
                        }

                        return(opt.Values);
                    }

                    if (iter.HasNext())
                    {
                        return(EMPTY_SUGGESTIONS); // don't suggest option value
                    }
                }

                return(singleSuggestion(getSuggestedOption(opt, useShort))); // suggest option`s name
            }

            return(EMPTY_SUGGESTIONS);
        }
コード例 #2
0
        private string[] ListOptions(CCommand cmd, string token = null)
        {
            IList <Option> options = cmd.ListOptions(token);

            string[] names = new string[options.Count];
            for (int i = 0; i < options.Count; ++i)
            {
                names[i] = options[i].Name;
            }

            return(names);
        }
コード例 #3
0
        private string[] ListOptions(CCommand cmd, string token = null)
        {
            IList<Option> options = cmd.ListOptions(token);
            string[] names = new string[options.Count];
            for (int i = 0; i < options.Count; ++i)
            {
                names[i] = options[i].Name;
            }

            return names;
        }
コード例 #4
0
        private static string[] getSuggestedOptions(Iterator<string> iter, CCommand cmd, string optNameToken, string prefix)
        {
            List<Option> optionsList = new List<Option>(); // TODO: reuse list

            // list options
            bool useShort = prefix.Equals("-");
            if (useShort)
            {
                cmd.ListShortOptions(optionsList, optNameToken);
                optionsList.Sort(delegate(Option op1, Option op2) {
                    return op1.ShortName.CompareTo(op2.ShortName);
                });
            }
            else
            {
                cmd.ListOptions(optionsList, optNameToken);
                optionsList.Sort(delegate(Option op1, Option op2) {
                    return op1.Name.CompareTo(op2.Name);
                });
            }

            if (optionsList.Count > 1) // multiple options available
            {
                return getSuggestedOptions(optionsList, useShort);
            }

            if (optionsList.Count == 1) // single option available
            {
                Option opt = optionsList[0];

                if (isOptionNameMatch(opt, optNameToken, useShort)) // option name already matched - try values
                {
                    if (opt.HasValues()) // option has predefined values?
                    {
                        if (iter.HasNext()) // has value token?
                        {
                            return opt.ListValues(iter.Next());
                        }

                        return opt.Values;
                    }

                    if (iter.HasNext())
                    {
                        return EMPTY_SUGGESTIONS; // don't suggest option value
                    }
                }

                return singleSuggestion(getSuggestedOption(opt, useShort)); // suggest option`s name
            }

            return EMPTY_SUGGESTIONS;
        }