2 * Meviz - Various tools collection to work with multimedia. Author: Svjatoslav Agejenko.
3 * This project is released under Creative Commons Zero (CC0) license.
7 package eu.svjatoslav.meviz.renamer;
9 import eu.svjatoslav.commons.commandline.parameterparser.Parser;
10 import eu.svjatoslav.commons.commandline.parameterparser.parameter.DirectoryParameter;
11 import eu.svjatoslav.commons.commandline.parameterparser.parameter.NullParameter;
12 import eu.svjatoslav.commons.commandline.parameterparser.parameter.StringParameter;
13 import eu.svjatoslav.commons.commandline.parameterparser.parameter.StringParameters;
14 import eu.svjatoslav.meviz.encoder.EncodingOptions;
18 class CommandlineHandler {
20 final Parser parser = new Parser();
22 private final NullParameter recursiveParameter = parser.add(
23 new NullParameter("Enable recursive mode.")).addAliases("-r",
26 private final NullParameter testParameter = parser.add(
28 "Simulate renaming (no changes will be actually done)."))
29 .addAliases("-t", "--test");
31 private final StringParameter outputPatternParameter = parser.add(
32 new StringParameter("Output pattern.")).addAliases("-o",
35 private final StringParameters inputPatternParameter = parser.add(
36 new StringParameters("File input pattern.")).addAliases("-i",
39 private final DirectoryParameter workingDirectoryParameter = parser
40 .add(new DirectoryParameter("Working directory."))
41 .addAliases("-w", "--working-directory").mustExist();
44 * @return {@link EncodingOptions} if commandline arguments were
45 * successfully parsed, or <code>null</code> if parsing error
48 public RenamingOptions parseCommandlineArguments(final String[] args) {
50 final RenamingOptions options = new RenamingOptions();
52 if (!parser.parse(args))
55 if (testParameter.isSpecified())
56 options.testOnly = true;
58 if (recursiveParameter.isSpecified())
59 options.recursive = true;
61 if (outputPatternParameter.isSpecified())
62 options.outputPattern = outputPatternParameter.getValue();
64 if (workingDirectoryParameter.isSpecified())
65 options.targetDirectory = workingDirectoryParameter.getValue();
67 options.targetDirectory = new File(System.getProperty("user.dir"));
69 // TODO: add multiple input patterns support
70 if (inputPatternParameter.isSpecified())
71 options.inputPatterns.addAll(inputPatternParameter.getValue());