updated commandline handler
authorSvjatoslav Agejenko <svjatoslav@svjatoslav.eu>
Tue, 29 Oct 2013 16:51:08 +0000 (18:51 +0200)
committerSvjatoslav Agejenko <svjatoslav@svjatoslav.eu>
Tue, 29 Oct 2013 16:51:08 +0000 (18:51 +0200)
src/main/java/eu/svjatoslav/meviz/encoder/Bitrate.java [deleted file]
src/main/java/eu/svjatoslav/meviz/encoder/BitrateParameter.java [new file with mode: 0755]
src/main/java/eu/svjatoslav/meviz/encoder/CommandlineHandler.java
src/main/java/eu/svjatoslav/meviz/encoder/Encoder.java
src/main/java/eu/svjatoslav/meviz/encoder/EncodingOptions.java

diff --git a/src/main/java/eu/svjatoslav/meviz/encoder/Bitrate.java b/src/main/java/eu/svjatoslav/meviz/encoder/Bitrate.java
deleted file mode 100755 (executable)
index fb1481d..0000000
+++ /dev/null
@@ -1,35 +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.encoder;
-
-import eu.svjatoslav.commons.commandline.parameterparser.Argument;
-
-public class Bitrate implements Argument {
-    @Override
-    public String describeFormat() {
-        return "Target bitrate [LOW / MEDIUM / HIGH]";
-    }
-
-    @Override
-    public boolean validate(final String value) {
-        try {
-            bitrate.valueOf(value);
-        } catch (final IllegalArgumentException exception) {
-            return false;
-        }
-
-        return true;
-    }
-
-    static public enum bitrate {
-        LOW, MEDIUM, HIGH
-    };
-
-}
diff --git a/src/main/java/eu/svjatoslav/meviz/encoder/BitrateParameter.java b/src/main/java/eu/svjatoslav/meviz/encoder/BitrateParameter.java
new file mode 100755 (executable)
index 0000000..3ab0fe1
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * 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.encoder;
+
+import eu.svjatoslav.commons.commandline.parameterparser.ArgumentCount;
+import eu.svjatoslav.commons.commandline.parameterparser.Parameter;
+
+public class BitrateParameter extends Parameter {
+
+       public BitrateParameter(String description) {
+               super(description, ArgumentCount.SINGLE);
+       }
+
+       @Override
+       public String describeFormat() {
+               return "Target bitrate [LOW / MEDIUM / HIGH]";
+       }
+
+       @Override
+       public boolean validate(final String value) {
+               try {
+                       bitrate.valueOf(value);
+               } catch (final IllegalArgumentException exception) {
+                       return false;
+               }
+
+               return true;
+       }
+
+       static public enum bitrate {
+               LOW, MEDIUM, HIGH
+       };
+
+       public bitrate getValue() {
+               return bitrate.valueOf(getArgumentsAsStrings().get(0).toUpperCase());
+       }
+}
index 9b32ebd..870d476 100755 (executable)
@@ -9,7 +9,6 @@
 
 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.parameter.DirectoryParameter;
 import eu.svjatoslav.commons.commandline.parameterparser.parameter.NullParameter;
@@ -43,30 +42,12 @@ public class CommandlineHandler {
                        .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();
-
-               parser.addParameter(recursiveParameter);
-
-               parser.addParameter(deinterlaceParameter);
-
-               parser.addParameter(testParameter);
-
-               parser.addParameter(terminalParameter);
-
-               parser.addParameter(outputFormatParameter);
-
-               parser.addParameter(inputPatternParameter);
-
-               parser.addParameter(workingDirectoryParameter);
+       BitrateParameter videoBitrateParameter = new BitrateParameter(
+                       "Video bitrate");
 
+       public CommandlineHandler() {
+               videoBitrateParameter.addAliases("-v", "--video-bitrate");
                parser.addParameter(videoBitrateParameter);
-
-               return parser;
        }
 
        /**
@@ -78,7 +59,6 @@ public class CommandlineHandler {
 
                final EncodingOptions options = new EncodingOptions();
 
-               final Parser parser = initParser();
                parser.parse(args);
 
                if (recursiveParameter.isParameterSpecified())
@@ -107,9 +87,7 @@ public class CommandlineHandler {
 
                if (videoBitrateParameter.isParameterSpecified())
                        try {
-                               options.videoBitrate = Bitrate.bitrate
-                                               .valueOf(videoBitrateParameter.getArgumentsAsStrings()
-                                                               .get(0).toUpperCase());
+                               options.videoBitrate = videoBitrateParameter.getValue();
                        } catch (final Exception e) {
                                System.out
                                                .println("Invalid video bitrate. Valid values are: LOW, MEDIUM, HIGH.");
index 3b2f043..420fa49 100755 (executable)
@@ -166,7 +166,7 @@ public class Encoder implements Module {
 
        @Override
        public void showCommandlineHelp() {
-               commandlineHandler.initParser().showHelp();
+               commandlineHandler.parser.showHelp();
                System.out.println("Example commands:");
                System.out
                                .println("    Convert all MTS files in the current directory into MP4's.");
index a2f09d8..9f14546 100755 (executable)
@@ -15,7 +15,7 @@ import java.util.List;
 
 public class EncodingOptions {
 
-       public Bitrate.bitrate videoBitrate = Bitrate.bitrate.MEDIUM;
+       public BitrateParameter.bitrate videoBitrate = BitrateParameter.bitrate.MEDIUM;
 
        // public Bitrate audioBitrate;