Class PathArgumentType
- All Implemented Interfaces:
ArgumentType<Path>
ArgumentType subclass for Path type, using fluent style API.
This object can convert path string to Path
object. The
command-line programs traditionally accept the file path "-" as standard
input. This object supports this when
acceptSystemIn()
is used. Also there are several
convenient verification features such as checking readability or existence.
- Since:
- 0.8.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate boolean
private FileVerification
private final FileSystem
private final FileVerification
-
Constructor Summary
ConstructorsConstructorDescriptionCreate an instance using the default file system for resolving the path.PathArgumentType
(FileSystem fileSystem) Create an instance using the given file system for resolving the path. -
Method Summary
Modifier and TypeMethodDescriptionIf the argument is "-", accept it as standard input.convert
(ArgumentParser parser, Argument arg, String value) Convertsvalue
to appropriate type.private boolean
isSystemIn
(String path) or()
Start a new verification group.Verifies that the specified path is writable.Verifies that the specified path is executable.Verifies that the specified path is readable.Verifies that the specified path is writable.Verifies that the parent directory of the specified path is writable.Verifies that the specified path exists.Verifies that the specified path is an absolute path.Verifies that the specified path is a directory.Verifies that the specified path is a regular file.Verifies that the specified path does not exist.
-
Field Details
-
fileSystem
-
acceptSystemIn
private boolean acceptSystemIn -
firstFileVerification
-
currentFileVerification
-
-
Constructor Details
-
PathArgumentType
public PathArgumentType()Create an instance using the default file system for resolving the path. -
PathArgumentType
Create an instance using the given file system for resolving the path.
Warning: Using the non-default file system disables all file verifications.
- Parameters:
fileSystem
- The file system to use for resolving paths
-
-
Method Details
-
acceptSystemIn
If the argument is "-", accept it as standard input. If this method is used, all verification methods will be ignored.- Returns:
- this
-
verifyExists
Verifies that the specified path exists. If the verification fails, error will be reported.- Returns:
- this
-
verifyNotExists
Verifies that the specified path does not exist. If the verification fails, error will be reported.- Returns:
- this
-
verifyIsFile
Verifies that the specified path is a regular file. If the verification fails, error will be reported.- Returns:
- this
-
verifyIsDirectory
Verifies that the specified path is a directory. If the verification fails, error will be reported.- Returns:
- this
-
verifyCanRead
Verifies that the specified path is readable. If the verification fails, error will be reported.- Returns:
- this
-
verifyCanWrite
Verifies that the specified path is writable. If the verification fails, error will be reported.- Returns:
- this
-
verifyCanWriteParent
Verifies that the parent directory of the specified path is writable. If the verification fails, error will be reported.- Returns:
- this
-
verifyCanCreate
Verifies that the specified path is writable. If the verification fails, error will be reported.- Returns:
- this
-
verifyCanExecute
Verifies that the specified path is executable. If the verification fails, error will be reported.- Returns:
- this
-
verifyIsAbsolute
Verifies that the specified path is an absolute path. If the verification fails, error will be reported.- Returns:
- this
-
or
Start a new verification group. Of all verification groups at least 1 must be verified successfully for the path to be accepted.- Returns:
- this
-
convert
public Path convert(ArgumentParser parser, Argument arg, String value) throws ArgumentParserException Description copied from interface:ArgumentType
Converts
value
to appropriate type.If the objects derived from
RuntimeException
are thrown in conversion because of invalid input from command line, subclass must catch these exceptions and wrap them inArgumentParserException
and give simple error message to explain what happened briefly.- Specified by:
convert
in interfaceArgumentType<Path>
- Parameters:
parser
- The parser.arg
- The argument this type attached to.value
- The attribute value.- Returns:
- Converted object.
- Throws:
ArgumentParserException
- If conversion fails.
-
isSystemIn
-