2 * Meviz - Various tools collection to work with multimedia.
3 * Copyright (C) 2012, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
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.
10 package eu.svjatoslav.meviz.bomremove;
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.StringParameter;
19 public class CommandlineHandler {
21 Parser parser = new Parser();
23 NullParameter recursiveParameter = parser.createNullParameter(
24 "Enable recursive mode.").addAliases("-r", "--recursive");
26 StringParameter inputPatternParameter = parser.createStringParameter(
27 "File input pattern.").addAliases("-i", "--input-pattern");
29 DirectoryParameter workingDirectoryParameter = parser
30 .createDirectoryParameter("Working directory.")
31 .addAliases("-w", "--working-directory").mustExist();
33 public Parser initParser() {
35 final Parser parser = new Parser();
36 parser.addParameter(recursiveParameter);
37 parser.addParameter(inputPatternParameter);
38 parser.addParameter(workingDirectoryParameter);
43 public BomStrippingOptions parseCommandlineArguments(final String[] args) {
45 final BomStrippingOptions options = new BomStrippingOptions();
47 final Parser parser = initParser();
48 if (!parser.parse(args))
51 if (recursiveParameter.isParameterSpecified())
52 options.recursive = true;
54 if (workingDirectoryParameter.isParameterSpecified())
55 options.targetDirectory = workingDirectoryParameter.getValue();
57 options.targetDirectory = new File(System.getProperty("user.dir"));
59 // TODO: add support for multiple input patterns
60 if (inputPatternParameter.isParameterSpecified())
61 options.inputPatterns.addAll(inputPatternParameter
62 .getArgumentsAsStrings());