/*
* Meviz - Various tools collection to work with multimedia.
- * Copyright (C) 2012, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
- *
+ * Copyright (C) 2012 -- 2019, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
+ *
* This program is free software; you can redistribute it and/or
- * modify it under the terms of version 2 of the GNU General Public License
- * as published by the Free Software Foundation.
- */
+ * modify it under the terms of version 3 of the GNU Lesser General Public License
+ * or later as published by the Free Software Foundation.
+*/
package eu.svjatoslav.meviz.bomremove;
-import java.io.File;
-
-import eu.svjatoslav.commons.commandline.parameterparser.Parameter;
import eu.svjatoslav.commons.commandline.parameterparser.Parser;
-import eu.svjatoslav.commons.commandline.parameterparser.arguments.ExistingDirectory;
-import eu.svjatoslav.commons.commandline.parameterparser.arguments.StringArgument;
+import eu.svjatoslav.commons.commandline.parameterparser.parameter.DirectoryParameter;
+import eu.svjatoslav.commons.commandline.parameterparser.parameter.NullParameter;
+import eu.svjatoslav.commons.commandline.parameterparser.parameter.StringParameters;
-public class CommandlineHandler {
-
- Parameter recursiveParameter = new Parameter("Enable recursive mode.",
- "-r", "--recursive");
+import java.io.File;
- Parameter inputPatternParameter = new Parameter(true, true, true,
- new StringArgument(), "File input pattern.", "-i",
- "--input-pattern");
+class CommandlineHandler {
- Parameter workingDirectoryParameter = new Parameter(false, true, true,
- new ExistingDirectory(), "Working directory.", "-w",
- "--working-directory");
+ final Parser parser = new Parser();
- public Parser initParser() {
+ private final NullParameter recursiveParameter = parser.add(
+ new NullParameter("Enable recursive mode.")).addAliases("-r",
+ "--recursive");
- final Parser parser = new Parser();
- parser.addParameter(recursiveParameter);
- parser.addParameter(inputPatternParameter);
- parser.addParameter(workingDirectoryParameter);
+ private final StringParameters inputPatternParameter = parser.add(
+ new StringParameters("File input pattern.")).addAliases("-i",
+ "--input-pattern");
- return parser;
- }
+ private final DirectoryParameter workingDirectoryParameter = parser
+ .add(new DirectoryParameter("Working directory."))
+ .addAliases("-w", "--working-directory").mustExist();
- public BomStrippingOptions parseCommandlineArguments(final String[] args) {
+ public BomStrippingOptions parseCommandlineArguments(final String[] args) {
- final BomStrippingOptions options = new BomStrippingOptions();
+ final BomStrippingOptions options = new BomStrippingOptions();
- final Parser parser = initParser();
- if (!parser.parse(args))
- return null;
+ if (!parser.parse(args))
+ return null;
- if (recursiveParameter.isParameterSpecified())
- options.recursive = true;
+ if (recursiveParameter.isSpecified())
+ options.recursive = true;
- if (workingDirectoryParameter.isParameterSpecified())
- options.targetDirectory = workingDirectoryParameter
- .getArgumentsAsFiles().get(0);
- else
- options.targetDirectory = new File(System.getProperty("user.dir"));
+ if (workingDirectoryParameter.isSpecified())
+ options.targetDirectory = workingDirectoryParameter.getValue();
+ else
+ options.targetDirectory = new File(System.getProperty("user.dir"));
- if (inputPatternParameter.isParameterSpecified())
- options.inputPatterns.addAll(inputPatternParameter
- .getArgumentsAsStrings());
+ // TODO: add support for multiple input patterns
+ if (inputPatternParameter.isSpecified())
+ options.inputPatterns.addAll(inputPatternParameter.getValue());
- return options;
- }
+ return options;
+ }
}