46750a3a29ff22e2f89407ce14e730a0c85ef422
[meviz.git] / src / main / java / eu / svjatoslav / meviz / bomremove / 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.bomremove;
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.NullParameter;
17 import eu.svjatoslav.commons.commandline.parameterparser.parameter.StringParameters;
18
19 public class CommandlineHandler {
20
21         Parser parser = new Parser();
22
23         NullParameter recursiveParameter = parser.add(
24                         new NullParameter("Enable recursive mode.")).addAliases("-r",
25                         "--recursive");
26
27         StringParameters inputPatternParameter = parser.add(
28                         new StringParameters("File input pattern.")).addAliases("-i",
29                         "--input-pattern");
30
31         DirectoryParameter workingDirectoryParameter = parser
32                         .add(new DirectoryParameter("Working directory."))
33                         .addAliases("-w", "--working-directory").mustExist();
34
35         public BomStrippingOptions parseCommandlineArguments(final String[] args) {
36
37                 final BomStrippingOptions options = new BomStrippingOptions();
38
39                 if (!parser.parse(args))
40                         return null;
41
42                 if (recursiveParameter.isParameterSpecified())
43                         options.recursive = true;
44
45                 if (workingDirectoryParameter.isParameterSpecified())
46                         options.targetDirectory = workingDirectoryParameter.getValue();
47                 else
48                         options.targetDirectory = new File(System.getProperty("user.dir"));
49
50                 // TODO: add support for multiple input patterns
51                 if (inputPatternParameter.isParameterSpecified())
52                         options.inputPatterns.addAll(inputPatternParameter.getValue());
53
54                 return options;
55         }
56 }