예제 #1
0
        private CommandResult Parse(CommandParsingContext context, string argument)
        {
            if (IsCommand(context, argument))
            {
                string commandKey   = ExtractCommandKey(context, argument);
                object commandValue = ExtractCommandValue(context, argument);

                return(new CommandResult(commandKey, commandValue));
            }

            return(null);
        }
예제 #2
0
        /// <summary>
        /// Parses the given collection of arguments based on the current parser rule set.
        /// </summary>
        /// <param name="arguments">A collection of all arguments passed through to the application
        /// from the command line.</param>
        /// <returns>A collection of commands resulting from the parse operation.</returns>
        /// <exception cref="ArgumentNullException">Thrown when the given collection of arguments is null.</exception>
        public IEnumerable<CommandResult> Parse(string[] arguments)
        {
            VerificationProvider.VerifyNotNull(arguments, "arguments");

            var context = new CommandParsingContext(RuleSet);
            foreach (string argument in arguments)
            {
                var command = Parse(context, argument);
                if (command != null)
                {
                    yield return command;
                }
            }
        }
예제 #3
0
        /// <summary>
        /// Parses the given collection of arguments based on the current parser rule set.
        /// </summary>
        /// <param name="arguments">A collection of all arguments passed through to the application
        /// from the command line.</param>
        /// <returns>A collection of commands resulting from the parse operation.</returns>
        /// <exception cref="ArgumentNullException">Thrown when the given collection of arguments is null.</exception>
        public IEnumerable <CommandResult> Parse(string[] arguments)
        {
            VerificationProvider.VerifyNotNull(arguments, "arguments");

            var context = new CommandParsingContext(RuleSet);

            foreach (string argument in arguments)
            {
                var command = Parse(context, argument);
                if (command != null)
                {
                    yield return(command);
                }
            }
        }
예제 #4
0
        private string ExtractCommandKey(CommandParsingContext context, string command)
        {
            var prefixes   = context.GetPrefixes();
            var separators = context.GetSeparators();

            // Trim off any prefix characters from the start of the command and split on the first occurrence of any separator characters
            string commandKey = command.TrimStart(prefixes);
            int    splitIndex = commandKey.IndexOfAny(separators);

            if (splitIndex > -1 && splitIndex < commandKey.Length)
            {
                commandKey = commandKey.Substring(0, splitIndex);
            }

            return(commandKey);
        }
예제 #5
0
        private string ExtractCommandKey(CommandParsingContext context, string command)
        {
            var prefixes = context.GetPrefixes();
            var separators = context.GetSeparators();

            // Trim off any prefix characters from the start of the command and split on the first occurrence of any separator characters
            string commandKey = command.TrimStart(prefixes);
            int splitIndex = commandKey.IndexOfAny(separators);

            if (splitIndex > -1 && splitIndex < commandKey.Length)
            {
                commandKey = commandKey.Substring(0, splitIndex);
            }

            return commandKey;
        }
예제 #6
0
        private object ExtractCommandValue(CommandParsingContext context, string command)
        {
            var separators = context.GetSeparators();

            // Split the command from the first occurrence of any separator characters
            int splitIndex = command.IndexOfAny(separators);

            if (splitIndex < 0 || splitIndex >= command.Length)
            {
                return(null);
            }

            string commandValue = command.Substring(splitIndex + 1);

            // Check to see if we have multiple values
            if (commandValue.Contains(MultipleValuesSeparators[0]))
            {
                return(commandValue.Split(MultipleValuesSeparators, StringSplitOptions.RemoveEmptyEntries));
            }

            // We have only a single value
            return(commandValue);
        }
예제 #7
0
        private object ExtractCommandValue(CommandParsingContext context, string command)
        {
            var separators = context.GetSeparators();

            // Split the command from the first occurrence of any separator characters
            int splitIndex = command.IndexOfAny(separators);

            if (splitIndex < 0 || splitIndex >= command.Length)
            {
                return null;
            }

            string commandValue = command.Substring(splitIndex + 1);

            // Check to see if we have multiple values
            if (commandValue.Contains(MultipleValuesSeparators[0]))
            {
                return commandValue.Split(MultipleValuesSeparators, StringSplitOptions.RemoveEmptyEntries);
            }

            // We have only a single value
            return commandValue;
        }
예제 #8
0
        private bool IsCommand(CommandParsingContext context, string argument)
        {
            var prefixes = context.GetPrefixes();

            return(argument.StartsWithAny(prefixes));
        }
예제 #9
0
 private bool IsCommand(CommandParsingContext context, string argument)
 {
     var prefixes = context.GetPrefixes();
     return argument.StartsWithAny(prefixes);
 }
예제 #10
0
        private CommandResult Parse(CommandParsingContext context, string argument)
        {
            if (IsCommand(context, argument))
            {
                string commandKey = ExtractCommandKey(context, argument);
                object commandValue = ExtractCommandValue(context, argument);

                return new CommandResult(commandKey, commandValue);
            }

            return null;
        }