Bug 2297: Standalone model validation tool
[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 import net.sourceforge.argparse4j.ArgumentParsers;
13 import net.sourceforge.argparse4j.annotation.Arg;
14 import net.sourceforge.argparse4j.inf.ArgumentParser;
15
16 final class Params {
17
18     @Arg(dest = "yang-source-dir")
19     private File yangSourceDir;
20
21     static ArgumentParser getParser() throws URISyntaxException {
22         final ArgumentParser parser = ArgumentParsers.newArgumentParser("jar_file_name");
23         parser.description("Validation Tool for Yang Models")
24             .formatUsage();
25
26         parser.addArgumentGroup("Required arguments")
27             .addArgument("--yang-source-dir")
28             .type(File.class)
29             .required(true)
30             .help("directory containing yang models which will be parsed")
31             .dest("yang-source-dir")
32             .metavar("");
33
34         return parser;
35     }
36
37     public boolean isValid() {
38         if (yangSourceDir == null) {
39             return false;
40         }
41         if (!yangSourceDir.exists()) {
42             System.err.println("Yang source directory has to exist");
43             return false;
44         }
45         if (!yangSourceDir.canRead()) {
46             System.err.println("Yang source directory has to be readable");
47             return false;
48         }
49         if (yangSourceDir.list().length == 0) {
50             System.err.printf("Yang source directory '%s' does't contain any model%n", yangSourceDir.getPath());
51             return false;
52         }
53
54         return true;
55     }
56
57     public File getYangSourceDir() {
58         return yangSourceDir;
59     }
60 }