示例#1
0
            internal static bool IsValidValue(Type type, string value)
            {
                if (type == typeof(string))
                {
                    if (value.StartsWith("--")) // can't be long option
                    {
                        return(false);
                    }
                    if (value.StartsWith("-"))                 // can't be short option
                    {
                        return(CStringUtils.IsNumeric(value)); // but can be a negative number
                    }
                    if (value.Equals("&&") || value.Equals("||"))
                    {
                        return(false);
                    }

                    return(value.Length > 0); // can't be empty
                }

                if (type == typeof(int))
                {
                    return(CStringUtils.IsInteger(value));
                }

                if (type == typeof(float))
                {
                    return(CStringUtils.IsNumeric(value));
                }

                return(false);
            }
示例#2
0
        private static string[] getSuggestions(string commandLine, IList <string> tokens)
        {
            CIterator <string> iter = new CIterator <string>(tokens);

            CCommand cmd = CRegistery.FindCommand(iter.Next());

            if (cmd == null)
            {
                return(EMPTY_SUGGESTIONS); // no command found
            }

            while (iter.HasNext())
            {
                string token   = iter.Next();
                int    iterPos = iter.Position; // store position to revert for the case if option skip fails

                // first try to parse options
                if (token.StartsWith("--")) // long option
                {
                    string optionName = token.Substring(2);
                    if (SkipOption(iter, cmd, optionName))
                    {
                        continue;
                    }

                    iter.Position = iterPos;
                    return(getSuggestedOptions(iter, cmd, optionName, "--"));
                }
                else if (token.StartsWith("-") && !CStringUtils.IsNumeric(token)) // short option
                {
                    string optionName = token.Substring(1);
                    if (SkipOption(iter, cmd, optionName))
                    {
                        continue;
                    }

                    iter.Position = iterPos;
                    return(getSuggestedOptions(iter, cmd, optionName, "-"));
                }

                if (iter.HasNext())
                {
                    return(EMPTY_SUGGESTIONS); // TODO: add multiple args suggestion support
                }

                return(getSuggestedArgs(commandLine, cmd, token));
            }

            return(getSuggestedArgs(commandLine, cmd, ""));
        }
示例#3
0
        private bool TryParseOption(CIterator <string> iter, string token)
        {
            if (this.IsIgnoreOptions)
            {
                return(false);
            }

            // first, try to parse options
            if (token.StartsWith("--"))
            {
                string optionName = token.Substring(2);
                ParseOption(iter, optionName);
                return(true);
            }

            if (token.StartsWith("-") && !CStringUtils.IsNumeric(token))
            {
                string optionName = token.Substring(1);
                ParseOption(iter, optionName);
                return(true);
            }

            return(false);
        }