package org.saltations.c3.cli;

import com.beust.jcommander.IValueValidator;
import com.beust.jcommander.ParameterException;

import java.nio.file.Path;

import static java.lang.String.format;

/*
 * Verify that it is a folder and it exists
 */

public class InputDirPathValidation implements IValueValidator<Path>
{

    @Override
    public void validate(String name, Path value) throws ParameterException
    {
        if (!value.toFile().exists())
        {
            throw new ParameterException(format("Folder <%s> does not exist.", value.toString()));
        }

        if (!value.toFile().isDirectory())
        {
            throw new ParameterException(format("<%s> is not a folder.", value.toString()));
        }
    }

}
