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;
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.StringParameters;
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 StringParameters fileInputPatternsParameter = parser.add(
28 new StringParameters("File input pattern.").addAliases("-i",
29 "--input-pattern")).setMandatory();
31 private final StringParameters splitPatternsParameter = parser
32 .add(new StringParameters("File split regular expression."))
33 .addAliases("-s", "--split-pattern").setMandatory();
35 private final DirectoryParameter workingDirectoryParameter = parser.add(
36 new DirectoryParameter("Working directory.")).addAliases("-w",
37 "--working-directory");
39 public TextSplittingOptions parseCommandlineArguments(final String[] args) {
41 final TextSplittingOptions options = new TextSplittingOptions();
43 if (!parser.parse(args))
46 if (recursiveParameter.isParameterSpecified())
47 options.recursive = true;
49 if (workingDirectoryParameter.isParameterSpecified())
50 options.targetDirectory = workingDirectoryParameter.getValue();
52 options.targetDirectory = new File(System.getProperty("user.dir"));
54 if (fileInputPatternsParameter.isParameterSpecified())
55 options.fileInputPatterns.addAll(fileInputPatternsParameter
58 if (splitPatternsParameter.isParameterSpecified())
59 options.textSplitPatterns.addAll(splitPatternsParameter.getValue());