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.Parameter;
15 import eu.svjatoslav.commons.commandline.parameterparser.Parser;
16 import eu.svjatoslav.commons.commandline.parameterparser.arguments.ExistingDirectory;
17 import eu.svjatoslav.commons.commandline.parameterparser.arguments.StringArgument;
19 public class CommandlineHandler {
21 Parameter recursiveParameter = new Parameter("Enable recursive mode.",
24 Parameter inputPatternParameter = new Parameter(true, true, true,
25 new StringArgument(), "File input pattern.", "-i",
28 Parameter workingDirectoryParameter = new Parameter(false, true, true,
29 new ExistingDirectory(), "Working directory.", "-w",
30 "--working-directory");
32 public Parser initParser() {
34 final Parser parser = new Parser();
35 parser.addParameter(recursiveParameter);
36 parser.addParameter(inputPatternParameter);
37 parser.addParameter(workingDirectoryParameter);
42 public TextSplittingOptions parseCommandlineArguments(final String[] args) {
44 final TextSplittingOptions options = new TextSplittingOptions();
46 final Parser parser = initParser();
47 if (!parser.parse(args))
50 if (recursiveParameter.isParameterSpecified())
51 options.recursive = true;
53 if (workingDirectoryParameter.isParameterSpecified())
54 options.targetDirectory = workingDirectoryParameter
55 .getArgumentsAsFiles().get(0);
57 options.targetDirectory = new File(System.getProperty("user.dir"));
59 if (inputPatternParameter.isParameterSpecified())
60 options.inputPatterns.addAll(inputPatternParameter
61 .getArgumentsAsStrings());