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;
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 inputPatternParameter = parser.add(
28 new StringParameters("File input pattern.")).addAliases("-i",
31 private final DirectoryParameter workingDirectoryParameter = parser.add(
32 new DirectoryParameter("Working directory.")).addAliases("-w",
33 "--working-directory");
35 public TextTruncatingOptions parseCommandlineArguments(final String[] args) {
37 final TextTruncatingOptions options = new TextTruncatingOptions();
39 if (!parser.parse(args))
42 if (recursiveParameter.isParameterSpecified())
43 options.recursive = true;
45 if (workingDirectoryParameter.isParameterSpecified())
46 options.targetDirectory = workingDirectoryParameter.getValue();
48 options.targetDirectory = new File(System.getProperty("user.dir"));
50 if (inputPatternParameter.isParameterSpecified())
51 options.inputPatterns.addAll(inputPatternParameter.getValue());