updated meviz to work with new commandline parsing API
[meviz.git] / src / main / java / eu / svjatoslav / meviz / htmlindexer / CommandlineHandler.java
1 /*
2  * Meviz - Various tools collection to work with multimedia.
3  * Copyright (C) 2012, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
4  * 
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of version 2 of the GNU General Public License
7  * as published by the Free Software Foundation.
8  */
9
10 package eu.svjatoslav.meviz.htmlindexer;
11
12 import java.io.File;
13
14 import eu.svjatoslav.commons.commandline.parameterparser.Parser;
15 import eu.svjatoslav.commons.commandline.parameterparser.parameter.DirectoryParameter;
16 import eu.svjatoslav.commons.commandline.parameterparser.parameter.StringParameter;
17 import eu.svjatoslav.meviz.encoder.EncodingOptions;
18
19 public class CommandlineHandler {
20
21         Parser parser = new Parser();
22
23         StringParameter galleryNameParameter = parser.createStringParameter(
24                         "Gallery title. (default is: " + Constants.DEFAULT_GALLERY_TITLE
25                                         + ").").addAliases("-t", "--gallery-title");
26
27         DirectoryParameter workingDirectoryParameter = parser
28                         .createDirectoryParameter("Working directory.").addAliases("-w",
29                                         "--working-directory");
30
31         public String getGalleryTitle() {
32                 if (galleryNameParameter.isParameterSpecified())
33                         return galleryNameParameter.getValue();
34                 return Constants.DEFAULT_GALLERY_TITLE;
35         }
36
37         public File getWorkingDirectory() {
38                 if (workingDirectoryParameter.isParameterSpecified())
39                         return workingDirectoryParameter.getValue();
40                 else
41                         return new File(System.getProperty("user.dir"));
42         }
43
44         /**
45          * @return {@link EncodingOptions} if commandline arguments were
46          *         successfully parsed, or <code>null</code> if parsing error
47          *         occurred.
48          */
49         public boolean parseCommandlineArguments(final String[] args) {
50                 return parser.parse(args);
51         }
52 }