Example usage for org.apache.commons.cli2.validation FileValidator setExisting

List of usage examples for org.apache.commons.cli2.validation FileValidator setExisting

Introduction

In this page you can find the example usage for org.apache.commons.cli2.validation FileValidator setExisting.

Prototype

public void setExisting(boolean existing) 

Source Link

Document

Specifies whether the argument values must represent existing files/directories.

Usage

From source file:de.tu_chemnitz.mi.barcd.app.CommandLineArgumentsParser.java

private DefaultOption createJobFileOption() {
    ArgumentBuilder ab = new ArgumentBuilder();
    DefaultOptionBuilder ob = new DefaultOptionBuilder();

    FileValidator fileValidator = new FileValidator();
    fileValidator.setReadable(true);//from w w  w  .  jav  a 2 s. c  o  m
    fileValidator.setWritable(true);
    fileValidator.setExisting(true);
    fileValidator.setFile(true);

    Argument jobArgument = ab.withName("PATH").withMinimum(1).withMaximum(1).withValidator(fileValidator)
            .create();

    DefaultOption jobFileOption = ob.withLongName("job").withDescription("The path to the job file.")
            .withArgument(jobArgument).withRequired(true).create();

    return jobFileOption;
}

From source file:org.mzd.shap.spring.cli.CommandLineApplication.java

public static FileValidator getFileValidator(boolean isDirectory, boolean isFile, boolean isExisting,
        boolean isHidden, boolean isReadable, boolean isWritable) {
    if (isDirectory && isFile) {
        throw new RuntimeException("Objects cannot simultaneously be a directory and a file");
    }//  w w w .j  ava 2  s  . c o  m
    FileValidator fv = new FileValidator();
    fv.setDirectory(isDirectory);
    fv.setExisting(isExisting);
    fv.setFile(isFile);
    fv.setHidden(isHidden);
    fv.setReadable(isReadable);
    fv.setWritable(isWritable);
    return fv;
}