Package software.amazon.smithy.cli
Class Parser
- java.lang.Object
-
- software.amazon.smithy.cli.Parser
-
public final class Parser extends java.lang.Object
Defines the CLI argument parser of aCommand
.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Parser.Argument
A command line argument.static class
Parser.Arity
Defines the arity of an argument.static class
Parser.Builder
Builds anParser
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static Parser.Builder
builder()
java.util.List<Parser.Argument>
getArgs()
java.util.Optional<java.lang.String>
getPositionalHelp()
java.util.Optional<java.lang.String>
getPositionalName()
Arguments
parse(java.lang.String[] args)
Parses command line arguments in anArguments
object.Arguments
parse(java.lang.String[] args, int offset)
Parses command line arguments in anArguments
object.
-
-
-
Method Detail
-
builder
public static Parser.Builder builder()
-
getPositionalName
public java.util.Optional<java.lang.String> getPositionalName()
-
getPositionalHelp
public java.util.Optional<java.lang.String> getPositionalHelp()
-
getArgs
public java.util.List<Parser.Argument> getArgs()
-
parse
public Arguments parse(java.lang.String[] args)
Parses command line arguments in anArguments
object.All arguments after the first argument that does not start with "-" or after "--" are treated as positional options. Arguments that come before this must be present in the argument spec returned by the command. Any encountered unknown argument will throw an exception. Arguments that expect a value and do not find one will throw an exception.
- Parameters:
args
- Arguments to parse.- Returns:
- Returns the parsed arguments.
- Throws:
CliError
- if the arguments are invalid.
-
parse
public Arguments parse(java.lang.String[] args, int offset)
Parses command line arguments in anArguments
object.- Parameters:
args
- Arguments to parse.offset
- Number of arguments to skip before parsing.- Returns:
- Returns the parsed arguments.
- Throws:
CliError
- if the arguments are invalid.- See Also:
parse(String[])
-
-