Class 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 when acceptSystemIn() is used. Also there are several convenient verification features such as checking readability or existence.

    Since:
    0.8.0
    • Field Detail

      • fileSystem

        private final java.nio.file.FileSystem fileSystem
      • acceptSystemIn

        private boolean acceptSystemIn
    • 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 in ArgumentParserException and give simple error message to explain what happened briefly.

        Specified by:
        convert in interface ArgumentType<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)