From: Svjatoslav Agejenko Date: Sun, 27 Oct 2013 19:22:13 +0000 (+0200) Subject: updated meviz to work with new commandline parsing API X-Git-Tag: meviz-1.0~77 X-Git-Url: http://www2.svjatoslav.eu/gitweb/?a=commitdiff_plain;h=c921086faa9d28c7e5c8d3d7a382a2c00901fb18;p=meviz.git updated meviz to work with new commandline parsing API --- diff --git a/.gitignore b/.gitignore index 2f7896d..288facf 100755 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ +/.classpath +/.project target/ diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..60105c1 --- /dev/null +++ b/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,5 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 +org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning +org.eclipse.jdt.core.compiler.source=1.6 diff --git a/.settings/org.eclipse.m2e.core.prefs b/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..ff7698f --- /dev/null +++ b/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=false +version=1 diff --git a/pom.xml b/pom.xml index 2da23c2..0a0bd40 100755 --- a/pom.xml +++ b/pom.xml @@ -17,7 +17,7 @@ eu.svjatoslav svjatoslavcommons - 1.1-SNAPSHOT + 1.2-SNAPSHOT @@ -111,7 +111,7 @@ org.apache.maven.wagon wagon-ssh - 2.2 + 2.4 @@ -121,8 +121,13 @@ svjatoslav.eu svjatoslav.eu - scp://svjatoslav.eu:7022/var/www/maven + scp://svjatoslav.eu/var/www/svjatoslav.eu/maven + + svjatoslav.eu + svjatoslav.eu + scp://svjatoslav.eu/var/www/svjatoslav.eu/maven + diff --git a/src/main/java/eu/svjatoslav/meviz/bomremove/CommandlineHandler.java b/src/main/java/eu/svjatoslav/meviz/bomremove/CommandlineHandler.java index 3276e13..16d3e2c 100755 --- a/src/main/java/eu/svjatoslav/meviz/bomremove/CommandlineHandler.java +++ b/src/main/java/eu/svjatoslav/meviz/bomremove/CommandlineHandler.java @@ -11,23 +11,24 @@ package eu.svjatoslav.meviz.bomremove; import java.io.File; -import eu.svjatoslav.commons.commandline.parameterparser.Parameter; import eu.svjatoslav.commons.commandline.parameterparser.Parser; -import eu.svjatoslav.commons.commandline.parameterparser.arguments.ExistingDirectory; -import eu.svjatoslav.commons.commandline.parameterparser.arguments.StringArgument; +import eu.svjatoslav.commons.commandline.parameterparser.parameter.DirectoryParameter; +import eu.svjatoslav.commons.commandline.parameterparser.parameter.NullParameter; +import eu.svjatoslav.commons.commandline.parameterparser.parameter.StringParameter; public class CommandlineHandler { - Parameter recursiveParameter = new Parameter("Enable recursive mode.", - "-r", "--recursive"); + Parser parser = new Parser(); - Parameter inputPatternParameter = new Parameter(true, true, true, - new StringArgument(), "File input pattern.", "-i", - "--input-pattern"); + NullParameter recursiveParameter = parser.createNullParameter( + "Enable recursive mode.").addAliases("-r", "--recursive"); - Parameter workingDirectoryParameter = new Parameter(false, true, true, - new ExistingDirectory(), "Working directory.", "-w", - "--working-directory"); + StringParameter inputPatternParameter = parser.createStringParameter( + "File input pattern.").addAliases("-i", "--input-pattern"); + + DirectoryParameter workingDirectoryParameter = parser + .createDirectoryParameter("Working directory.") + .addAliases("-w", "--working-directory").mustExist(); public Parser initParser() { @@ -51,11 +52,11 @@ public class CommandlineHandler { options.recursive = true; if (workingDirectoryParameter.isParameterSpecified()) - options.targetDirectory = workingDirectoryParameter - .getArgumentsAsFiles().get(0); + options.targetDirectory = workingDirectoryParameter.getValue(); else options.targetDirectory = new File(System.getProperty("user.dir")); + // TODO: add support for multiple input patterns if (inputPatternParameter.isParameterSpecified()) options.inputPatterns.addAll(inputPatternParameter .getArgumentsAsStrings()); diff --git a/src/main/java/eu/svjatoslav/meviz/encoder/CommandlineHandler.java b/src/main/java/eu/svjatoslav/meviz/encoder/CommandlineHandler.java index eb2ac08..9b32ebd 100755 --- a/src/main/java/eu/svjatoslav/meviz/encoder/CommandlineHandler.java +++ b/src/main/java/eu/svjatoslav/meviz/encoder/CommandlineHandler.java @@ -11,39 +11,41 @@ package eu.svjatoslav.meviz.encoder; import eu.svjatoslav.commons.commandline.parameterparser.Parameter; import eu.svjatoslav.commons.commandline.parameterparser.Parser; -import eu.svjatoslav.commons.commandline.parameterparser.arguments.StringArgument; +import eu.svjatoslav.commons.commandline.parameterparser.parameter.DirectoryParameter; +import eu.svjatoslav.commons.commandline.parameterparser.parameter.NullParameter; +import eu.svjatoslav.commons.commandline.parameterparser.parameter.StringParameter; public class CommandlineHandler { - Parameter outputFormatParameter = new Parameter(true, true, true, - new StringArgument(), "Encoding output format.", "-o", - "--output-format"); + Parser parser = new Parser(); - Parameter terminalParameter = new Parameter("Enable popup terminal.", - "--terminal"); + StringParameter outputFormatParameter = parser + .createStringParameter("Encoding output format.") + .addAliases("-o", "--output-format").setMandatory(); - Parameter deinterlaceParameter = new Parameter("Deinterlace video.", - "--deinterlace", "-d"); + NullParameter terminalParameter = parser.createNullParameter( + "Enable popup terminal.").addAliases("--terminal"); - Parameter testParameter = new Parameter("Simulate file encoding.", "-t", - "--test"); + NullParameter deinterlaceParameter = parser.createNullParameter( + "Deinterlace video.").addAliases("--deinterlace", "-d"); - Parameter recursiveParameter = new Parameter("Enable recursive mode.", - "-r", "--recursive"); + NullParameter testParameter = parser.createNullParameter( + "Simulate file encoding.").addAliases("-t", "--test"); - Parameter inputPatternParameter = new Parameter(true, true, true, - new StringArgument(), "File input pattern.", "-i", - "--input-pattern"); + NullParameter recursiveParameter = parser.createNullParameter( + "Enable recursive mode.").addAliases("-r", "--recursive"); - Parameter workingDirectoryParameter = new Parameter( - false, - true, - true, - new eu.svjatoslav.commons.commandline.parameterparser.arguments.ExistingDirectory(), - "Working directory.", "-w", "--working-directory"); + StringParameter inputPatternParameter = parser + .createStringParameter("File input pattern.") + .addAliases("-i", "--input-pattern").setMandatory(); - Parameter videoBitrateParameter = new Parameter(false, true, false, - new Bitrate(), "Video bitrate.", "-v", "--video-bitrate"); + DirectoryParameter workingDirectoryParameter = parser + .createDirectoryParameter("Working directory.") + .addAliases("-w", "--working-directory").mustExist(); + + Parameter videoBitrateParameter = parser.createCustomParameter( + new Bitrate(), "Video bitrate.") + .addAliases("-v", "--video-bitrate"); public Parser initParser() { final Parser parser = new Parser(); @@ -106,8 +108,8 @@ public class CommandlineHandler { if (videoBitrateParameter.isParameterSpecified()) try { options.videoBitrate = Bitrate.bitrate - .valueOf(videoBitrateParameter.getArgumentAsString() - .toUpperCase()); + .valueOf(videoBitrateParameter.getArgumentsAsStrings() + .get(0).toUpperCase()); } catch (final Exception e) { System.out .println("Invalid video bitrate. Valid values are: LOW, MEDIUM, HIGH."); diff --git a/src/main/java/eu/svjatoslav/meviz/htmlindexer/CommandlineHandler.java b/src/main/java/eu/svjatoslav/meviz/htmlindexer/CommandlineHandler.java index 84bff07..eb32317 100755 --- a/src/main/java/eu/svjatoslav/meviz/htmlindexer/CommandlineHandler.java +++ b/src/main/java/eu/svjatoslav/meviz/htmlindexer/CommandlineHandler.java @@ -11,29 +11,34 @@ package eu.svjatoslav.meviz.htmlindexer; import java.io.File; -import eu.svjatoslav.commons.commandline.parameterparser.Parameter; import eu.svjatoslav.commons.commandline.parameterparser.Parser; -import eu.svjatoslav.commons.commandline.parameterparser.arguments.StringArgument; +import eu.svjatoslav.commons.commandline.parameterparser.parameter.DirectoryParameter; +import eu.svjatoslav.commons.commandline.parameterparser.parameter.StringParameter; import eu.svjatoslav.meviz.encoder.EncodingOptions; public class CommandlineHandler { - Parameter galleryNameParameter = new Parameter(false, true, false, - new StringArgument(), "Gallery title. (default is: " - + Constants.DEFAULT_GALLERY_TITLE + ").", "-t", - "--gallery-title"); + Parser parser = new Parser(); - Parameter workingDirectoryParameter = new Parameter(false, true, true, - new StringArgument(), "Working directory.", "-w", - "--working-directory"); + StringParameter galleryNameParameter = parser.createStringParameter( + "Gallery title. (default is: " + Constants.DEFAULT_GALLERY_TITLE + + ").").addAliases("-t", "--gallery-title"); - public Parser initParser() { + DirectoryParameter workingDirectoryParameter = parser + .createDirectoryParameter("Working directory.").addAliases("-w", + "--working-directory"); - final Parser parser = new Parser(); - parser.addParameter(galleryNameParameter); - parser.addParameter(workingDirectoryParameter); + public String getGalleryTitle() { + if (galleryNameParameter.isParameterSpecified()) + return galleryNameParameter.getValue(); + return Constants.DEFAULT_GALLERY_TITLE; + } - return parser; + public File getWorkingDirectory() { + if (workingDirectoryParameter.isParameterSpecified()) + return workingDirectoryParameter.getValue(); + else + return new File(System.getProperty("user.dir")); } /** @@ -41,24 +46,7 @@ public class CommandlineHandler { * successfully parsed, or null if parsing error * occurred. */ - public IndexingOptions parseCommandlineArguments(final String[] args) { - - final IndexingOptions options = new IndexingOptions(); - - final Parser parser = initParser(); - if (!parser.parse(args)) - return null; - - if (galleryNameParameter.isParameterSpecified()) - options.galleryTitle = galleryNameParameter.getArgumentsAsStrings() - .get(0); - - if (workingDirectoryParameter.isParameterSpecified()) - options.workingDirectory = workingDirectoryParameter - .getArgumentsAsFiles().get(0); - else - options.workingDirectory = new File(System.getProperty("user.dir")); - - return options; + public boolean parseCommandlineArguments(final String[] args) { + return parser.parse(args); } } diff --git a/src/main/java/eu/svjatoslav/meviz/htmlindexer/FilesystemIndexer.java b/src/main/java/eu/svjatoslav/meviz/htmlindexer/FilesystemIndexer.java index c103b68..0edea71 100755 --- a/src/main/java/eu/svjatoslav/meviz/htmlindexer/FilesystemIndexer.java +++ b/src/main/java/eu/svjatoslav/meviz/htmlindexer/FilesystemIndexer.java @@ -51,19 +51,19 @@ public class FilesystemIndexer extends AbstractIndexer { private DirectoryMetadata metadata; - private final IndexingOptions indexingOptions; - private final List pathElements; private HashSet layouts; + private final CommandlineHandler commandlineHandler; + public FilesystemIndexer(final File directoryToIndex, - final IndexingOptions indexingOptions, + final CommandlineHandler commandlineHandler, final List pathElements) throws IOException, ImageFormatError { this.directoryToIndex = directoryToIndex; - this.indexingOptions = indexingOptions; + this.commandlineHandler = commandlineHandler; this.pathElements = pathElements; if (!directoryToIndex.canRead()) @@ -222,9 +222,11 @@ public class FilesystemIndexer extends AbstractIndexer { layouts = new HashSet(); layouts.add(new MixedLayout()); + final String galleryTitle = commandlineHandler.getGalleryTitle(); + for (final Layout layout : layouts) - layout.init(indexingOptions.galleryTitle, pathElements, this, - new IndexingContext("", ".")); + layout.init(galleryTitle, pathElements, this, new IndexingContext( + "", ".")); } public void initializeThumbnailsDirectory() { @@ -264,7 +266,7 @@ public class FilesystemIndexer extends AbstractIndexer { metadata.ensureFileMetainfoIsUpToDate(directoryToIndex, file); if (file.isDirectory()) - new FilesystemIndexer(file, indexingOptions, + new FilesystemIndexer(file, commandlineHandler, getChildPath(file)); } } diff --git a/src/main/java/eu/svjatoslav/meviz/htmlindexer/IndexingOptions.java b/src/main/java/eu/svjatoslav/meviz/htmlindexer/IndexingOptions.java deleted file mode 100755 index 354aaed..0000000 --- a/src/main/java/eu/svjatoslav/meviz/htmlindexer/IndexingOptions.java +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Meviz - Various tools collection to work with multimedia. - * Copyright (C) 2012, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public License - * as published by the Free Software Foundation. - */ - -package eu.svjatoslav.meviz.htmlindexer; - -import java.io.File; - -public class IndexingOptions { - - File workingDirectory; - - String galleryTitle = Constants.DEFAULT_GALLERY_TITLE; - -} diff --git a/src/main/java/eu/svjatoslav/meviz/htmlindexer/Main.java b/src/main/java/eu/svjatoslav/meviz/htmlindexer/Main.java index 335b073..ae6c4c6 100644 --- a/src/main/java/eu/svjatoslav/meviz/htmlindexer/Main.java +++ b/src/main/java/eu/svjatoslav/meviz/htmlindexer/Main.java @@ -8,8 +8,6 @@ public class Main implements Module { CommandlineHandler commandlineHandler = new CommandlineHandler(); - IndexingOptions indexingOptions; - /** {@inheritDoc} */ @Override public String getDescription() { @@ -26,29 +24,23 @@ public class Main implements Module { @Override public void run(final String[] args) throws Exception { - indexingOptions = commandlineHandler.parseCommandlineArguments(args); + final boolean parsingStatus = commandlineHandler + .parseCommandlineArguments(args); - if (indexingOptions == null) { + if (!parsingStatus) { showCommandlineHelp(); return; } - new FilesystemIndexer(indexingOptions.workingDirectory, - indexingOptions, new ArrayList()); + new FilesystemIndexer(commandlineHandler.getWorkingDirectory(), + commandlineHandler, new ArrayList()); } /** {@inheritDoc} */ @Override public void showCommandlineHelp() { - commandlineHandler.initParser().showHelp(); + commandlineHandler.parser.showHelp(); } - // public static void main(final String[] args) throws Exception { - // - // final Main main = new Main(); - // main.run(new String[] { "-w", "/home/n0/Desktop/testGallery/" }); - // - // } - } diff --git a/src/main/java/eu/svjatoslav/meviz/renamer/CommandlineHandler.java b/src/main/java/eu/svjatoslav/meviz/renamer/CommandlineHandler.java index 051aaa8..9eb45de 100755 --- a/src/main/java/eu/svjatoslav/meviz/renamer/CommandlineHandler.java +++ b/src/main/java/eu/svjatoslav/meviz/renamer/CommandlineHandler.java @@ -11,43 +11,32 @@ package eu.svjatoslav.meviz.renamer; import java.io.File; -import eu.svjatoslav.commons.commandline.parameterparser.Parameter; import eu.svjatoslav.commons.commandline.parameterparser.Parser; -import eu.svjatoslav.commons.commandline.parameterparser.arguments.ExistingDirectory; -import eu.svjatoslav.commons.commandline.parameterparser.arguments.StringArgument; +import eu.svjatoslav.commons.commandline.parameterparser.parameter.DirectoryParameter; +import eu.svjatoslav.commons.commandline.parameterparser.parameter.NullParameter; +import eu.svjatoslav.commons.commandline.parameterparser.parameter.StringParameter; import eu.svjatoslav.meviz.encoder.EncodingOptions; public class CommandlineHandler { - Parameter recursiveParameter = new Parameter("Enable recursive mode.", - "-r", "--recursive"); + Parser parser = new Parser(); - Parameter testParameter = new Parameter( - "Simulate renaming (no changes will be actually done).", "-t", - "--test"); + NullParameter recursiveParameter = parser.createNullParameter( + "Enable recursive mode.").addAliases("-r", "--recursive"); - Parameter outputPatternParameter = new Parameter(true, true, true, - new StringArgument(), "Output pattern.", "-o", "--output-pattern"); + NullParameter testParameter = parser.createNullParameter( + "Simulate renaming (no changes will be actually done).") + .addAliases("-t", "--test"); - Parameter inputPatternParameter = new Parameter(true, true, true, - new StringArgument(), "File input pattern.", "-i", - "--input-pattern"); + StringParameter outputPatternParameter = parser.createStringParameter( + "Output pattern.").addAliases("-o", "--output-pattern"); - Parameter workingDirectoryParameter = new Parameter(false, true, true, - new ExistingDirectory(), "Working directory.", "-w", - "--working-directory"); + StringParameter inputPatternParameter = parser.createStringParameter( + "File input pattern.").addAliases("-i", "--input-pattern"); - public Parser initParser() { - - final Parser parser = new Parser(); - parser.addParameter(recursiveParameter); - parser.addParameter(testParameter); - parser.addParameter(outputPatternParameter); - parser.addParameter(inputPatternParameter); - parser.addParameter(workingDirectoryParameter); - - return parser; - } + DirectoryParameter workingDirectoryParameter = parser + .createDirectoryParameter("Working directory.") + .addAliases("-w", "--working-directory").mustExist(); /** * @return {@link EncodingOptions} if commandline arguments were @@ -58,7 +47,6 @@ public class CommandlineHandler { final RenamingOptions options = new RenamingOptions(); - final Parser parser = initParser(); if (!parser.parse(args)) return null; @@ -69,15 +57,14 @@ public class CommandlineHandler { options.recursive = true; if (outputPatternParameter.isParameterSpecified()) - options.outputPattern = outputPatternParameter - .getArgumentsAsStrings().get(0); + options.outputPattern = outputPatternParameter.getValue(); if (workingDirectoryParameter.isParameterSpecified()) - options.targetDirectory = workingDirectoryParameter - .getArgumentsAsFiles().get(0); + options.targetDirectory = workingDirectoryParameter.getValue(); else options.targetDirectory = new File(System.getProperty("user.dir")); + // TODO: add multiple input patterns support if (inputPatternParameter.isParameterSpecified()) options.inputPatterns.addAll(inputPatternParameter .getArgumentsAsStrings()); diff --git a/src/main/java/eu/svjatoslav/meviz/renamer/Main.java b/src/main/java/eu/svjatoslav/meviz/renamer/Main.java index 3a15e03..8818889 100755 --- a/src/main/java/eu/svjatoslav/meviz/renamer/Main.java +++ b/src/main/java/eu/svjatoslav/meviz/renamer/Main.java @@ -163,7 +163,7 @@ public class Main implements Module { @Override public void showCommandlineHelp() { - commandlineHandler.initParser().showHelp(); + commandlineHandler.parser.showHelp(); System.out.println(""); System.out.println("Output pattern special symbols:"); System.out.println(" % - file number"); diff --git a/src/main/java/eu/svjatoslav/meviz/replace/CommandlineHandler.java b/src/main/java/eu/svjatoslav/meviz/replace/CommandlineHandler.java index 4a8f336..898b391 100755 --- a/src/main/java/eu/svjatoslav/meviz/replace/CommandlineHandler.java +++ b/src/main/java/eu/svjatoslav/meviz/replace/CommandlineHandler.java @@ -11,62 +11,49 @@ package eu.svjatoslav.meviz.replace; import java.io.File; -import eu.svjatoslav.commons.commandline.parameterparser.Parameter; import eu.svjatoslav.commons.commandline.parameterparser.Parser; -import eu.svjatoslav.commons.commandline.parameterparser.arguments.ExistingDirectory; -import eu.svjatoslav.commons.commandline.parameterparser.arguments.StringArgument; +import eu.svjatoslav.commons.commandline.parameterparser.parameter.DirectoryParameter; +import eu.svjatoslav.commons.commandline.parameterparser.parameter.NullParameter; +import eu.svjatoslav.commons.commandline.parameterparser.parameter.StringParameter; public class CommandlineHandler { - Parameter recursiveParameter = new Parameter("Enable recursive mode.", - "-r", "--recursive"); + Parser parser = new Parser(); - Parameter searchForPattern = new Parameter(true, true, false, - new StringArgument(), "String to search for", "-s", - "--search-pattern"); + NullParameter recursiveParameter = parser.createNullParameter( + "Enable recursive mode.").addAliases("-r", "--recursive"); - Parameter replaceWithPattern = new Parameter(true, true, false, - new StringArgument(), "String to place instead", "-p", - "--replace-pattern"); + StringParameter searchForPattern = parser + .createStringParameter("String to search for") + .addAliases("-s", "--search-pattern").setMandatory(); - Parameter workingDirectoryParameter = new Parameter(false, true, false, - new ExistingDirectory(), "Working directory.", "-w", - "--working-directory"); + StringParameter replaceWithPattern = parser.createStringParameter( + "String to place instead").addAliases("-p", "--replace-pattern"); - public Parser initParser() { - - final Parser parser = new Parser(); - parser.addParameter(recursiveParameter); - parser.addParameter(searchForPattern); - parser.addParameter(replaceWithPattern); - parser.addParameter(workingDirectoryParameter); - - return parser; - } + DirectoryParameter directoryParameter = parser + .createDirectoryParameter("Working directory.") + .addAliases("-w", "--working-directory").mustExist(); public CommandlineOptions parseCommandlineArguments(final String[] args) { final CommandlineOptions options = new CommandlineOptions(); - final Parser parser = initParser(); if (!parser.parse(args)) return null; if (recursiveParameter.isParameterSpecified()) options.recursive = true; - if (workingDirectoryParameter.isParameterSpecified()) - options.targetDirectory = workingDirectoryParameter - .getArgumentsAsFiles().get(0); + if (directoryParameter.isParameterSpecified()) + options.targetDirectory = directoryParameter.getValue(); else options.targetDirectory = new File(System.getProperty("user.dir")); if (searchForPattern.isParameterSpecified()) - options.searchForPattern = searchForPattern.getArgumentAsString(); + options.searchForPattern = searchForPattern.getValue(); if (replaceWithPattern.isParameterSpecified()) - options.replaceWithPattern = replaceWithPattern - .getArgumentAsString(); + options.replaceWithPattern = replaceWithPattern.getValue(); return options; } diff --git a/src/main/java/eu/svjatoslav/meviz/replace/Main.java b/src/main/java/eu/svjatoslav/meviz/replace/Main.java index 3355e92..81ab76d 100755 --- a/src/main/java/eu/svjatoslav/meviz/replace/Main.java +++ b/src/main/java/eu/svjatoslav/meviz/replace/Main.java @@ -23,7 +23,6 @@ public class Main implements Module { CommandlineOptions options; - @Override public String getDescription() { return "Replace one string to another string in all occurrances and all files recursively."; @@ -54,19 +53,19 @@ public class Main implements Module { public void processFile(final File file) throws IOException { - FileReader fileReader = new FileReader(file); - BufferedReader bufferedReader = new BufferedReader(fileReader); + final FileReader fileReader = new FileReader(file); + final BufferedReader bufferedReader = new BufferedReader(fileReader); - StringBuffer result = new StringBuffer(); + final StringBuffer result = new StringBuffer(); boolean contentChanged = false; while (true) { - String line = bufferedReader.readLine(); + final String line = bufferedReader.readLine(); if (line == null) break; - String newLine = line.replace(options.searchForPattern, + final String newLine = line.replace(options.searchForPattern, options.replaceWithPattern); if (!contentChanged) @@ -81,7 +80,7 @@ public class Main implements Module { fileReader.close(); if (contentChanged) { - FileWriter fileWriter = new FileWriter(file); + final FileWriter fileWriter = new FileWriter(file); fileWriter.write(result.toString()); fileWriter.close(); } @@ -104,7 +103,7 @@ public class Main implements Module { @Override public void showCommandlineHelp() { - commandlineHandler.initParser().showHelp(); + commandlineHandler.parser.showHelp(); } } diff --git a/src/main/java/eu/svjatoslav/meviz/textsplitter/CommandlineHandler.java b/src/main/java/eu/svjatoslav/meviz/textsplitter/CommandlineHandler.java index 5f7bc0e..8060db6 100755 --- a/src/main/java/eu/svjatoslav/meviz/textsplitter/CommandlineHandler.java +++ b/src/main/java/eu/svjatoslav/meviz/textsplitter/CommandlineHandler.java @@ -11,44 +11,34 @@ package eu.svjatoslav.meviz.textsplitter; import java.io.File; -import eu.svjatoslav.commons.commandline.parameterparser.Parameter; import eu.svjatoslav.commons.commandline.parameterparser.Parser; -import eu.svjatoslav.commons.commandline.parameterparser.arguments.ExistingDirectory; -import eu.svjatoslav.commons.commandline.parameterparser.arguments.StringArgument; +import eu.svjatoslav.commons.commandline.parameterparser.parameter.DirectoryParameter; +import eu.svjatoslav.commons.commandline.parameterparser.parameter.NullParameter; +import eu.svjatoslav.commons.commandline.parameterparser.parameter.StringParameter; public class CommandlineHandler { - Parameter recursiveParameter = new Parameter("Enable recursive mode.", - "-r", "--recursive"); + Parser parser = new Parser(); - Parameter fileInputPatternsParameter = new Parameter(true, true, true, - new StringArgument(), "File input pattern.", "-i", - "--input-pattern"); + NullParameter recursiveParameter = parser.createNullParameter( + "Enable recursive mode.").addAliases("-r", "--recursive"); - Parameter splitPatternsParameter = new Parameter(true, true, true, - new StringArgument(), "File split regular expression.", "-s", - "--split-pattern"); + StringParameter fileInputPatternsParameter = parser + .createStringParameter("File input pattern.") + .addAliases("-i", "--input-pattern").setMandatory(); - Parameter workingDirectoryParameter = new Parameter(false, true, true, - new ExistingDirectory(), "Working directory.", "-w", - "--working-directory"); + StringParameter splitPatternsParameter = parser + .createStringParameter("File split regular expression.") + .addAliases("-s", "--split-pattern").setMandatory(); - public Parser initParser() { - - final Parser parser = new Parser(); - parser.addParameter(recursiveParameter); - parser.addParameter(fileInputPatternsParameter); - parser.addParameter(splitPatternsParameter); - parser.addParameter(workingDirectoryParameter); - - return parser; - } + DirectoryParameter workingDirectoryParameter = parser + .createDirectoryParameter("Working directory.").addAliases("-w", + "--working-directory"); public TextSplittingOptions parseCommandlineArguments(final String[] args) { final TextSplittingOptions options = new TextSplittingOptions(); - final Parser parser = initParser(); if (!parser.parse(args)) return null; @@ -56,8 +46,7 @@ public class CommandlineHandler { options.recursive = true; if (workingDirectoryParameter.isParameterSpecified()) - options.targetDirectory = workingDirectoryParameter - .getArgumentsAsFiles().get(0); + options.targetDirectory = workingDirectoryParameter.getValue(); else options.targetDirectory = new File(System.getProperty("user.dir")); diff --git a/src/main/java/eu/svjatoslav/meviz/textsplitter/Main.java b/src/main/java/eu/svjatoslav/meviz/textsplitter/Main.java index daaf307..e2b85cb 100755 --- a/src/main/java/eu/svjatoslav/meviz/textsplitter/Main.java +++ b/src/main/java/eu/svjatoslav/meviz/textsplitter/Main.java @@ -134,7 +134,7 @@ public class Main implements Module { @Override public void showCommandlineHelp() { - commandlineHandler.initParser().showHelp(); + commandlineHandler.parser.showHelp(); } } diff --git a/src/main/java/eu/svjatoslav/meviz/texttruncate/CommandlineHandler.java b/src/main/java/eu/svjatoslav/meviz/texttruncate/CommandlineHandler.java index d391bca..005a828 100755 --- a/src/main/java/eu/svjatoslav/meviz/texttruncate/CommandlineHandler.java +++ b/src/main/java/eu/svjatoslav/meviz/texttruncate/CommandlineHandler.java @@ -11,39 +11,29 @@ package eu.svjatoslav.meviz.texttruncate; import java.io.File; -import eu.svjatoslav.commons.commandline.parameterparser.Parameter; import eu.svjatoslav.commons.commandline.parameterparser.Parser; -import eu.svjatoslav.commons.commandline.parameterparser.arguments.ExistingDirectory; -import eu.svjatoslav.commons.commandline.parameterparser.arguments.StringArgument; +import eu.svjatoslav.commons.commandline.parameterparser.parameter.DirectoryParameter; +import eu.svjatoslav.commons.commandline.parameterparser.parameter.NullParameter; +import eu.svjatoslav.commons.commandline.parameterparser.parameter.StringParameter; public class CommandlineHandler { - Parameter recursiveParameter = new Parameter("Enable recursive mode.", - "-r", "--recursive"); + Parser parser = new Parser(); - Parameter inputPatternParameter = new Parameter(true, true, true, - new StringArgument(), "File input pattern.", "-i", - "--input-pattern"); + NullParameter recursiveParameter = parser.createNullParameter( + "Enable recursive mode.").addAliases("-r", "--recursive"); - Parameter workingDirectoryParameter = new Parameter(false, true, true, - new ExistingDirectory(), "Working directory.", "-w", - "--working-directory"); + StringParameter inputPatternParameter = parser.createStringParameter( + "File input pattern.").addAliases("-i", "--input-pattern"); - public Parser initParser() { - - final Parser parser = new Parser(); - parser.addParameter(recursiveParameter); - parser.addParameter(inputPatternParameter); - parser.addParameter(workingDirectoryParameter); - - return parser; - } + DirectoryParameter workingDirectoryParameter = parser + .createDirectoryParameter("Working directory.").addAliases("-w", + "--working-directory"); public TextTruncatingOptions parseCommandlineArguments(final String[] args) { final TextTruncatingOptions options = new TextTruncatingOptions(); - final Parser parser = initParser(); if (!parser.parse(args)) return null; diff --git a/src/main/java/eu/svjatoslav/meviz/texttruncate/Main.java b/src/main/java/eu/svjatoslav/meviz/texttruncate/Main.java index 4106e20..31f7671 100755 --- a/src/main/java/eu/svjatoslav/meviz/texttruncate/Main.java +++ b/src/main/java/eu/svjatoslav/meviz/texttruncate/Main.java @@ -150,7 +150,7 @@ public class Main implements Module { @Override public void showCommandlineHelp() { - commandlineHandler.initParser().showHelp(); + commandlineHandler.parser.showHelp(); } }