2 * Meviz - Various tools collection to work with multimedia.
3 * Copyright (C) 2012 -- 2017, 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 class CommandlineHandler {
23 final Parser parser = new Parser();
25 private final NullParameter recursiveParameter = parser.add(
26 new NullParameter("Enable recursive mode.")).addAliases("-r",
29 private final NullParameter testParameter = parser.add(
31 "Simulate renaming (no changes will be actually done)."))
32 .addAliases("-t", "--test");
34 private final StringParameter outputPatternParameter = parser.add(
35 new StringParameter("Output pattern.")).addAliases("-o",
38 private final StringParameters inputPatternParameter = parser.add(
39 new StringParameters("File input pattern.")).addAliases("-i",
42 private final 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.isSpecified())
59 options.testOnly = true;
61 if (recursiveParameter.isSpecified())
62 options.recursive = true;
64 if (outputPatternParameter.isSpecified())
65 options.outputPattern = outputPatternParameter.getValue();
67 if (workingDirectoryParameter.isSpecified())
68 options.targetDirectory = workingDirectoryParameter.getValue();
70 options.targetDirectory = new File(System.getProperty("user.dir"));
72 // TODO: add multiple input patterns support
73 if (inputPatternParameter.isSpecified())
74 options.inputPatterns.addAll(inputPatternParameter.getValue());