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.replace;
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;
19 public class CommandlineHandler {
21 Parser parser = new Parser();
23 NullParameter recursiveParameter = parser.createNullParameter(
24 "Enable recursive mode.").addAliases("-r", "--recursive");
26 StringParameter searchForPattern = parser
27 .createStringParameter("String to search for")
28 .addAliases("-s", "--search-pattern").setMandatory();
30 StringParameter replaceWithPattern = parser.createStringParameter(
31 "String to place instead").addAliases("-p", "--replace-pattern");
33 DirectoryParameter directoryParameter = parser
34 .createDirectoryParameter("Working directory.")
35 .addAliases("-w", "--working-directory").mustExist();
37 public CommandlineOptions parseCommandlineArguments(final String[] args) {
39 final CommandlineOptions options = new CommandlineOptions();
41 if (!parser.parse(args))
44 if (recursiveParameter.isParameterSpecified())
45 options.recursive = true;
47 if (directoryParameter.isParameterSpecified())
48 options.targetDirectory = directoryParameter.getValue();
50 options.targetDirectory = new File(System.getProperty("user.dir"));
52 if (searchForPattern.isParameterSpecified())
53 options.searchForPattern = searchForPattern.getValue();
55 if (replaceWithPattern.isParameterSpecified())
56 options.replaceWithPattern = replaceWithPattern.getValue();