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.textsplitter;
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.StringParameters;
19 public class CommandlineHandler {
21 Parser parser = new Parser();
23 NullParameter recursiveParameter = parser.createNullParameter(
24 "Enable recursive mode.").addAliases("-r", "--recursive");
26 StringParameters fileInputPatternsParameter = parser
27 .createStringParameters("File input pattern.")
28 .addAliases("-i", "--input-pattern").setMandatory();
30 StringParameters splitPatternsParameter = parser
31 .createStringParameters("File split regular expression.")
32 .addAliases("-s", "--split-pattern").setMandatory();
34 DirectoryParameter workingDirectoryParameter = parser
35 .createDirectoryParameter("Working directory.").addAliases("-w",
36 "--working-directory");
38 public TextSplittingOptions parseCommandlineArguments(final String[] args) {
40 final TextSplittingOptions options = new TextSplittingOptions();
42 if (!parser.parse(args))
45 if (recursiveParameter.isParameterSpecified())
46 options.recursive = true;
48 if (workingDirectoryParameter.isParameterSpecified())
49 options.targetDirectory = workingDirectoryParameter.getValue();
51 options.targetDirectory = new File(System.getProperty("user.dir"));
53 if (fileInputPatternsParameter.isParameterSpecified())
54 options.fileInputPatterns.addAll(fileInputPatternsParameter
57 if (splitPatternsParameter.isParameterSpecified())
58 options.textSplitPatterns.addAll(splitPatternsParameter.getValue());