2 * Meviz - Various tools collection to work with multimedia.
3 * Copyright (C) 2012 -- 2018, 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;
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;
19 class CommandlineHandler {
21 final Parser parser = new Parser();
23 private final NullParameter recursiveParameter = parser.add(
24 new NullParameter("Enable recursive mode.")).addAliases("-r",
27 private final StringParameter searchForPattern = parser
28 .add(new StringParameter("String to search for"))
29 .addAliases("-s", "--search-pattern").setMandatory();
31 private final StringParameter replaceWithPattern = parser.add(
32 new StringParameter("String to place instead")).addAliases("-p",
35 private final 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.isSpecified())
47 options.recursive = true;
49 if (directoryParameter.isSpecified())
50 options.targetDirectory = directoryParameter.getValue();
52 options.targetDirectory = new File(System.getProperty("user.dir"));
54 if (searchForPattern.isSpecified())
55 options.searchForPattern = searchForPattern.getValue();
57 if (replaceWithPattern.isSpecified())
58 options.replaceWithPattern = replaceWithPattern.getValue();