Module net.sourceforge.argparse4j
Class FileArgumentType
- java.lang.Object
-
- net.sourceforge.argparse4j.impl.type.FileArgumentType
-
- All Implemented Interfaces:
ArgumentType<java.io.File>
public class FileArgumentType extends java.lang.Object implements ArgumentType<java.io.File>
ArgumentType subclass for File type, using fluent style API. This object can convert path string toFileobject. 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.
-
-
Field Summary
Fields Modifier and Type Field Description private booleanacceptSystemInprivate FileVerificationcurrentFileVerificationprivate FileVerificationfirstFileVerification
-
Constructor Summary
Constructors Constructor Description FileArgumentType()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description FileArgumentTypeacceptSystemIn()If the argument is "-", accept it as standard input.java.io.Fileconvert(ArgumentParser parser, Argument arg, java.lang.String value)Convertsvalueto appropriate type.private booleanisSystemIn(java.io.File file)FileArgumentTypeor()Start a new verification group.FileArgumentTypeverifyCanCreate()Verifies that the specified path is writable.FileArgumentTypeverifyCanExecute()Verifies that the specified path is executable.FileArgumentTypeverifyCanRead()Verifies that the specified path is readable.FileArgumentTypeverifyCanWrite()Verifies that the specified path is writable.FileArgumentTypeverifyCanWriteParent()Verifies that the parent directory of the specified path is writable.FileArgumentTypeverifyExists()Verifies that the specified path exists.FileArgumentTypeverifyIsAbsolute()Verifies that the specified path is an absolute path.FileArgumentTypeverifyIsDirectory()Verifies that the specified path is a directory.FileArgumentTypeverifyIsFile()Verifies that the specified path is a regular file.FileArgumentTypeverifyNotExists()Verifies that the specified path does not exist.
-
-
-
Field Detail
-
acceptSystemIn
private boolean acceptSystemIn
-
firstFileVerification
private final FileVerification firstFileVerification
-
currentFileVerification
private FileVerification currentFileVerification
-
-
Method Detail
-
acceptSystemIn
public FileArgumentType 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 FileArgumentType verifyExists()
Verifies that the specified path exists. If the verification fails, error will be reported.- Returns:
- this
-
verifyNotExists
public FileArgumentType verifyNotExists()
Verifies that the specified path does not exist. If the verification fails, error will be reported.- Returns:
- this
-
verifyIsFile
public FileArgumentType verifyIsFile()
Verifies that the specified path is a regular file. If the verification fails, error will be reported.- Returns:
- this
-
verifyIsDirectory
public FileArgumentType verifyIsDirectory()
Verifies that the specified path is a directory. If the verification fails, error will be reported.- Returns:
- this
-
verifyCanRead
public FileArgumentType verifyCanRead()
Verifies that the specified path is readable. If the verification fails, error will be reported.- Returns:
- this
-
verifyCanWrite
public FileArgumentType verifyCanWrite()
Verifies that the specified path is writable. If the verification fails, error will be reported.- Returns:
- this
-
verifyCanWriteParent
public FileArgumentType verifyCanWriteParent()
Verifies that the parent directory of the specified path is writable. If the verification fails, error will be reported.- Returns:
- this
-
verifyCanCreate
public FileArgumentType verifyCanCreate()
Verifies that the specified path is writable. If the verification fails, error will be reported.- Returns:
- this
-
verifyCanExecute
public FileArgumentType verifyCanExecute()
Verifies that the specified path is executable. If the verification fails, error will be reported.- Returns:
- this
-
verifyIsAbsolute
public FileArgumentType verifyIsAbsolute()
Verifies that the specified path is an absolute path. If the verification fails, error will be reported.- Returns:
- this
-
or
public FileArgumentType or()
Start a new verification group. Of all verification groups at least 1 must be verified successfully for the file to be accepted.- Returns:
- this
-
convert
public java.io.File convert(ArgumentParser parser, Argument arg, java.lang.String value) throws ArgumentParserException
Description copied from interface:ArgumentTypeConverts
valueto appropriate type.If the objects derived from
RuntimeExceptionare thrown in conversion because of invalid input from command line, subclass must catch these exceptions and wrap them inArgumentParserExceptionand give simple error message to explain what happened briefly.- Specified by:
convertin interfaceArgumentType<java.io.File>- 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.io.File file)
-
-