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.renamer;
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;
18 import eu.svjatoslav.commons.commandline.parameterparser.parameter.StringParameters;
19 import eu.svjatoslav.meviz.encoder.EncodingOptions;
21 public class CommandlineHandler {
23 Parser parser = new Parser();
25 NullParameter recursiveParameter = parser.createNullParameter(
26 "Enable recursive mode.").addAliases("-r", "--recursive");
28 NullParameter testParameter = parser.createNullParameter(
29 "Simulate renaming (no changes will be actually done).")
30 .addAliases("-t", "--test");
32 StringParameter outputPatternParameter = parser.createStringParameter(
33 "Output pattern.").addAliases("-o", "--output-pattern");
35 StringParameters inputPatternParameter = parser.createStringParameters(
36 "File input pattern.").addAliases("-i", "--input-pattern");
38 DirectoryParameter workingDirectoryParameter = parser
39 .createDirectoryParameter("Working directory.")
40 .addAliases("-w", "--working-directory").mustExist();
43 * @return {@link EncodingOptions} if commandline arguments were
44 * successfully parsed, or <code>null</code> if parsing error
47 public RenamingOptions parseCommandlineArguments(final String[] args) {
49 final RenamingOptions options = new RenamingOptions();
51 if (!parser.parse(args))
54 if (testParameter.isParameterSpecified())
55 options.testOnly = true;
57 if (recursiveParameter.isParameterSpecified())
58 options.recursive = true;
60 if (outputPatternParameter.isParameterSpecified())
61 options.outputPattern = outputPatternParameter.getValue();
63 if (workingDirectoryParameter.isParameterSpecified())
64 options.targetDirectory = workingDirectoryParameter.getValue();
66 options.targetDirectory = new File(System.getProperty("user.dir"));
68 // TODO: add multiple input patterns support
69 if (inputPatternParameter.isParameterSpecified())
70 options.inputPatterns.addAll(inputPatternParameter.getValue());