Class PathArgumentType
- java.lang.Object
-
- net.sourceforge.argparse4j.ext.java7.PathArgumentType
-
- All Implemented Interfaces:
ArgumentType<java.nio.file.Path>
public class PathArgumentType extends java.lang.Object implements ArgumentType<java.nio.file.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 whenacceptSystemIn()
is used. Also there are several convenient verification features such as checking readability or existence.- Since:
- 0.8.0
-
-
Field Summary
Fields Modifier and Type Field Description private boolean
acceptSystemIn
private FileVerification
currentFileVerification
private java.nio.file.FileSystem
fileSystem
private FileVerification
firstFileVerification
-
Constructor Summary
Constructors Constructor Description PathArgumentType()
Create an instance using the default file system for resolving the path.PathArgumentType(java.nio.file.FileSystem fileSystem)
Create an instance using the given file system for resolving the path.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description PathArgumentType
acceptSystemIn()
If the argument is "-", accept it as standard input.java.nio.file.Path
convert(ArgumentParser parser, Argument arg, java.lang.String value)
Convertsvalue
to appropriate type.private boolean
isSystemIn(java.lang.String path)
PathArgumentType
or()
Start a new verification group.PathArgumentType
verifyCanCreate()
Verifies that the specified path is writable.PathArgumentType
verifyCanExecute()
Verifies that the specified path is executable.PathArgumentType
verifyCanRead()
Verifies that the specified path is readable.PathArgumentType
verifyCanWrite()
Verifies that the specified path is writable.PathArgumentType
verifyCanWriteParent()
Verifies that the parent directory of the specified path is writable.PathArgumentType
verifyExists()
Verifies that the specified path exists.PathArgumentType
verifyIsAbsolute()
Verifies that the specified path is an absolute path.PathArgumentType
verifyIsDirectory()
Verifies that the specified path is a directory.PathArgumentType
verifyIsFile()
Verifies that the specified path is a regular file.PathArgumentType
verifyNotExists()
Verifies that the specified path does not exist.
-
-
-
Field Detail
-
fileSystem
private final java.nio.file.FileSystem fileSystem
-
acceptSystemIn
private boolean acceptSystemIn
-
firstFileVerification
private final FileVerification firstFileVerification
-
currentFileVerification
private FileVerification currentFileVerification
-
-
Constructor Detail
-
PathArgumentType
public PathArgumentType()
Create an instance using the default file system for resolving the path.
-
PathArgumentType
public PathArgumentType(java.nio.file.FileSystem fileSystem)
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 Detail
-
acceptSystemIn
public PathArgumentType acceptSystemIn()
If the argument is "-", accept it as standard input. If this method is used, all verification methods will be ignored.- Returns:
- this
-
verifyExists
public PathArgumentType verifyExists()
Verifies that the specified path exists. If the verification fails, error will be reported.- Returns:
- this
-
verifyNotExists
public PathArgumentType verifyNotExists()
Verifies that the specified path does not exist. If the verification fails, error will be reported.- Returns:
- this
-
verifyIsFile
public PathArgumentType verifyIsFile()
Verifies that the specified path is a regular file. If the verification fails, error will be reported.- Returns:
- this
-
verifyIsDirectory
public PathArgumentType verifyIsDirectory()
Verifies that the specified path is a directory. If the verification fails, error will be reported.- Returns:
- this
-
verifyCanRead
public PathArgumentType verifyCanRead()
Verifies that the specified path is readable. If the verification fails, error will be reported.- Returns:
- this
-
verifyCanWrite
public PathArgumentType verifyCanWrite()
Verifies that the specified path is writable. If the verification fails, error will be reported.- Returns:
- this
-
verifyCanWriteParent
public PathArgumentType verifyCanWriteParent()
Verifies that the parent directory of the specified path is writable. If the verification fails, error will be reported.- Returns:
- this
-
verifyCanCreate
public PathArgumentType verifyCanCreate()
Verifies that the specified path is writable. If the verification fails, error will be reported.- Returns:
- this
-
verifyCanExecute
public PathArgumentType verifyCanExecute()
Verifies that the specified path is executable. If the verification fails, error will be reported.- Returns:
- this
-
verifyIsAbsolute
public PathArgumentType verifyIsAbsolute()
Verifies that the specified path is an absolute path. If the verification fails, error will be reported.- Returns:
- this
-
or
public PathArgumentType 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 java.nio.file.Path convert(ArgumentParser parser, Argument arg, java.lang.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<java.nio.file.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
private boolean isSystemIn(java.lang.String path)
-
-