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.add(
24 new NullParameter("Enable recursive mode.")).addAliases("-r",
27 StringParameter searchForPattern = parser
28 .add(new StringParameter("String to search for"))
29 .addAliases("-s", "--search-pattern").setMandatory();
31 StringParameter replaceWithPattern = parser.add(
32 new StringParameter("String to place instead")).addAliases("-p",
35 DirectoryParameter directoryParameter = parser
36 .add(new DirectoryParameter("Working directory."))
37 .addAliases("-w", "--working-directory").mustExist();
39 public CommandlineOptions parseCommandlineArguments(final String[] args) {
41 final CommandlineOptions options = new CommandlineOptions();
43 if (!parser.parse(args))
46 if (recursiveParameter.isParameterSpecified())
47 options.recursive = true;
49 if (directoryParameter.isParameterSpecified())
50 options.targetDirectory = directoryParameter.getValue();
52 options.targetDirectory = new File(System.getProperty("user.dir"));
54 if (searchForPattern.isParameterSpecified())
55 options.searchForPattern = searchForPattern.getValue();
57 if (replaceWithPattern.isParameterSpecified())
58 options.replaceWithPattern = replaceWithPattern.getValue();