5bc91bc0500c584c2ce3796fcad5ace3da63b79c
[yangtools.git] / yang-validation-tool / src / main / java / org / opendaylight / yangtools / yang / validation / tool / Params.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.yangtools.yang.validation.tool;
9
10 import java.io.File;
11 import java.net.URISyntaxException;
12
13 import net.sourceforge.argparse4j.ArgumentParsers;
14 import net.sourceforge.argparse4j.annotation.Arg;
15 import net.sourceforge.argparse4j.inf.ArgumentParser;
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
18
19 final class Params {
20
21     private static final Logger LOG = LoggerFactory.getLogger(Params.class);
22     @Arg(dest = "yang-source-dir")
23     private File yangSourceDir;
24
25     static ArgumentParser getParser() throws URISyntaxException {
26         final ArgumentParser parser = ArgumentParsers.newArgumentParser("jar_file_name");
27         parser.description("Validation Tool for Yang Models")
28             .formatUsage();
29
30         parser.addArgumentGroup("Required arguments")
31             .addArgument("--yang-source-dir")
32             .type(File.class)
33             .required(true)
34             .help("directory containing yang models which will be parsed")
35             .dest("yang-source-dir")
36             .metavar("");
37
38         return parser;
39     }
40
41     public boolean isValid() {
42         if (yangSourceDir == null) {
43             return false;
44         }
45         if (!yangSourceDir.exists()) {
46             LOG.error("Yang source directory has to exist");
47             return false;
48         }
49         if (!yangSourceDir.canRead()) {
50             LOG.error("Yang source directory has to be readable");
51             return false;
52         }
53         if (yangSourceDir.list().length == 0) {
54             LOG.error("Yang source directory {} doesn't contain any model", yangSourceDir.getPath());
55             return false;
56         }
57
58         return true;
59     }
60
61     public File getYangSourceDir() {
62         return yangSourceDir;
63     }
64 }