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;
12 import eu.svjatoslav.commons.commandline.parameterparser.Parser;
13 import eu.svjatoslav.commons.commandline.parameterparser.parameter.DirectoryParameter;
14 import eu.svjatoslav.commons.commandline.parameterparser.parameter.NullParameter;
15 import eu.svjatoslav.commons.commandline.parameterparser.parameter.StringParameter;
16 import eu.svjatoslav.commons.commandline.parameterparser.parameter.StringParameters;
17 import eu.svjatoslav.meviz.encoder.EncodingOptions;
21 public class CommandlineHandler {
23 Parser parser = new Parser();
25 NullParameter recursiveParameter = parser.add(
26 new NullParameter("Enable recursive mode.")).addAliases("-r",
29 NullParameter testParameter = parser.add(
31 "Simulate renaming (no changes will be actually done)."))
32 .addAliases("-t", "--test");
34 StringParameter outputPatternParameter = parser.add(
35 new StringParameter("Output pattern.")).addAliases("-o",
38 StringParameters inputPatternParameter = parser.add(
39 new StringParameters("File input pattern.")).addAliases("-i",
42 DirectoryParameter workingDirectoryParameter = parser
43 .add(new DirectoryParameter("Working directory."))
44 .addAliases("-w", "--working-directory").mustExist();
47 * @return {@link EncodingOptions} if commandline arguments were
48 * successfully parsed, or <code>null</code> if parsing error
51 public RenamingOptions parseCommandlineArguments(final String[] args) {
53 final RenamingOptions options = new RenamingOptions();
55 if (!parser.parse(args))
58 if (testParameter.isParameterSpecified())
59 options.testOnly = true;
61 if (recursiveParameter.isParameterSpecified())
62 options.recursive = true;
64 if (outputPatternParameter.isParameterSpecified())
65 options.outputPattern = outputPatternParameter.getValue();
67 if (workingDirectoryParameter.isParameterSpecified())
68 options.targetDirectory = workingDirectoryParameter.getValue();
70 options.targetDirectory = new File(System.getProperty("user.dir"));
72 // TODO: add multiple input patterns support
73 if (inputPatternParameter.isParameterSpecified())
74 options.inputPatterns.addAll(inputPatternParameter.getValue());