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.texttruncate;
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.createNullParameter(
24 "Enable recursive mode.").addAliases("-r", "--recursive");
26 StringParameter inputPatternParameter = parser.createStringParameter(
27 "File input pattern.").addAliases("-i", "--input-pattern");
29 DirectoryParameter workingDirectoryParameter = parser
30 .createDirectoryParameter("Working directory.").addAliases("-w",
31 "--working-directory");
33 public TextTruncatingOptions parseCommandlineArguments(final String[] args) {
35 final TextTruncatingOptions options = new TextTruncatingOptions();
37 if (!parser.parse(args))
40 if (recursiveParameter.isParameterSpecified())
41 options.recursive = true;
43 if (workingDirectoryParameter.isParameterSpecified())
44 options.targetDirectory = workingDirectoryParameter
45 .getArgumentsAsFiles().get(0);
47 options.targetDirectory = new File(System.getProperty("user.dir"));
49 if (inputPatternParameter.isParameterSpecified())
50 options.inputPatterns.addAll(inputPatternParameter
51 .getArgumentsAsStrings());