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.replace;
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;
16 class CommandlineHandler {
18 final Parser parser = new Parser();
20 private final NullParameter recursiveParameter = parser.add(
21 new NullParameter("Enable recursive mode.")).addAliases("-r",
24 private final StringParameter searchForPattern = parser
25 .add(new StringParameter("String to search for"))
26 .addAliases("-s", "--search-pattern").setMandatory();
28 private final StringParameter replaceWithPattern = parser.add(
29 new StringParameter("String to place instead")).addAliases("-p",
32 private final DirectoryParameter directoryParameter = parser
33 .add(new DirectoryParameter("Working directory."))
34 .addAliases("-w", "--working-directory").mustExist();
36 public CommandlineOptions parseCommandlineArguments(final String[] args) {
38 final CommandlineOptions options = new CommandlineOptions();
40 if (!parser.parse(args))
43 if (recursiveParameter.isSpecified())
44 options.recursive = true;
46 if (directoryParameter.isSpecified())
47 options.targetDirectory = directoryParameter.getValue();
49 options.targetDirectory = new File(System.getProperty("user.dir"));
51 if (searchForPattern.isSpecified())
52 options.searchForPattern = searchForPattern.getValue();
54 if (replaceWithPattern.isSpecified())
55 options.replaceWithPattern = replaceWithPattern.getValue();