Class DefaultCommandParser
java.lang.Object
org.springframework.shell.core.command.DefaultCommandParser
- All Implemented Interfaces:
CommandParser
Default implementation of
CommandParser. Supports options in the long form of
--key=value or --key value as well in the short form of -k=value or -k value. Options
and arguments can be specified in any order. Arguments are 0-based indexed among other
arguments. Option values and arguments can be quoted with double or single quotes to
include whitespace, and quote characters can be escaped with a backslash inside quoted
values (e.g. greet "she said \" and left"). Unbalanced quotes are rejected with an
IllegalArgumentException. CommandSyntax ::= CommandName [SubCommandName]* [Option | Argument]* CommandName ::= String SubCommandName ::= String Option ::= ShortOption | LongOption ShortOption ::= '-' Char ['='|' ']? String LongOption ::= '--' String ['='|' ']? String Argument ::= String Example: mycommand mysubcommand --optionA=value1 arg1 -b=value2 arg2 --optionC value3 -d value4
- Since:
- 4.0.0
- Author:
- Mahmoud Ben Hassine, David Pilar
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionParse raw input into aParsedInput.Split the input into words on whitespace, keeping quoted sections together.
-
Constructor Details
-
DefaultCommandParser
-
-
Method Details
-
parse
Description copied from interface:CommandParserParse raw input into aParsedInput.- Specified by:
parsein interfaceCommandParser- Parameters:
input- the raw input- Returns:
- the parsed input
-
tokenize
Split the input into words on whitespace, keeping quoted sections together. This is a character-by-character state machine tracking the currently open quote (none, double or single). A backslash makes the following character part of the current word without any special meaning, so an escaped quote neither opens nor closes a quoted section. Words are kept verbatim (quotes and escape sequences included), quote removal and escape resolution happen later inunquoteAndUnescapeQuoted(String).- Parameters:
input- the raw input line- Returns:
- the list of words
- Throws:
IllegalArgumentException- if the input contains an unbalanced quote- Since:
- 4.0.4
-