Revision: 6410
          
http://languagetool.svn.sourceforge.net/languagetool/?rev=6410&view=rev
Author:   dnaber
Date:     2012-02-03 23:56:44 +0000 (Fri, 03 Feb 2012)
Log Message:
-----------
refactor command line argument parsing to its own class

Modified Paths:
--------------
    trunk/JLanguageTool/src/java/org/languagetool/Main.java

Added Paths:
-----------
    trunk/JLanguageTool/src/java/org/languagetool/commandline/
    
trunk/JLanguageTool/src/java/org/languagetool/commandline/CommandLineOptions.java
    
trunk/JLanguageTool/src/java/org/languagetool/commandline/CommandLineParser.java
    trunk/JLanguageTool/src/test/org/languagetool/commandline/
    
trunk/JLanguageTool/src/test/org/languagetool/commandline/CommandLineParserTest.java

Modified: trunk/JLanguageTool/src/java/org/languagetool/Main.java
===================================================================
--- trunk/JLanguageTool/src/java/org/languagetool/Main.java     2012-02-03 
21:02:26 UTC (rev 6409)
+++ trunk/JLanguageTool/src/java/org/languagetool/Main.java     2012-02-03 
23:56:44 UTC (rev 6410)
@@ -30,6 +30,8 @@
 
 import javax.xml.parsers.ParserConfigurationException;
 
+import org.languagetool.commandline.CommandLineOptions;
+import org.languagetool.commandline.CommandLineParser;
 import org.xml.sax.SAXException;
 
 import org.apache.tika.language.*;
@@ -39,7 +41,6 @@
 import org.languagetool.rules.bitext.BitextRule;
 import org.languagetool.tools.StringTools;
 import org.languagetool.tools.Tools;
-import org.languagetool.tools.*;
 
 /**
  * The command line tool to check plain text files.
@@ -451,158 +452,54 @@
    * Command line tool to check plain text files.
    */
   public static void main(final String[] args) throws IOException, 
ParserConfigurationException, SAXException {
-    if (args.length < 1 || args.length > 10) {
-      exitWithUsageMessage();
+    final CommandLineParser commandLineParser = new CommandLineParser();
+    CommandLineOptions options = null;
+    try {
+       options = commandLineParser.parseOptions(args);
+    } catch (IllegalArgumentException e) {
+      System.out
+              .println("Usage: java org.languagetool.Main "
+                      + "[-r|--recursive] [-v|--verbose] [-l|--language LANG] 
[-m|--mothertongue LANG] [-d|--disable RULES] [-adl|--autoDetect] "
+                      + "[-e|--enable RULES] [-c|--encoding] 
[-u|--list-unknown] [-t|--taggeronly] [-b] [--api] [-a|--apply] "
+                      +    "[-b2|--bitext] <file>");
+      System.exit(1);
     }
-    boolean verbose = false;
-    boolean recursive = false;
-    boolean taggerOnly = false;
-    boolean singleLineBreakMarksParagraph = false;
-    boolean apiFormat = false;
-    boolean listUnknown = false;
-    boolean applySuggestions = false;
-    boolean profile = false;
-    boolean bitext = false;
-    boolean autoDetect = false;
-    Language language = null;
-    Language motherTongue = null;
-    String encoding = null;
-    String filename = null;
-    String[] disabledRules = new String[0];
-    String[] enabledRules = new String[0];
-    for (int i = 0; i < args.length; i++) {
-      if (args[i].equals("-h") || args[i].equals("-help")
-          || args[i].equals("--help") || args[i].equals("--?")) {
-        exitWithUsageMessage();
-      } else if (args[i].equals("-adl") || args[i].equals("--autoDetect")) {   
 // set autoDetect flag
-        // also initialize the other language profiles for the 
LanguageIdentifier
-        LanguageIdentifierTools.addLtProfiles();
-        autoDetect = true;
-      } else if (args[i].equals("-v") || args[i].equals("--verbose")) {
-        verbose = true;
-      } else if (args[i].equals("-t") || args[i].equals("--taggeronly")) {
-        taggerOnly = true;
-        if (listUnknown) {
-          throw new IllegalArgumentException("You cannot list unknown words 
when tagging only.");
-        }
-        if (applySuggestions) {
-          throw new IllegalArgumentException("You cannot apply suggestions 
when tagging only.");
-        }
-      } else if (args[i].equals("-r") || args[i].equals("--recursive")) {
-        recursive = true;
-      } else if (args[i].equals("-b2") || args[i].equals("--bitext")) {
-        bitext = true;
-      } else if (args[i].equals("-d") || args[i].equals("--disable")) {
-        if (enabledRules.length > 0) {
-          throw new IllegalArgumentException("You cannot specify both enabled 
and disabled rules");
-        }
-        checkArguments("-d/--disable", i, args);
-        final String rules = args[++i];
-        disabledRules = rules.split(",");
-      } else if (args[i].equals("-e") || args[i].equals("--enable")) {
-        if (disabledRules.length > 0) {
-          throw new IllegalArgumentException(
-          "You cannot specify both enabled and disabled rules");
-        }
-        checkArguments("-e/--enable", i, args);
-        final String rules = args[++i];
-        enabledRules = rules.split(",");
-      } else if (args[i].equals("-l") || args[i].equals("--language")) {
-        checkArguments("-l/--language", i, args);
-        language = getLanguageOrExit(args[++i]);
-      } else if (args[i].equals("-m") || args[i].equals("--mothertongue")) {
-        checkArguments("-m/--mothertongue", i, args);
-        motherTongue = getLanguageOrExit(args[++i]);
-      } else if (args[i].equals("-c") || args[i].equals("--encoding")) {
-        checkArguments("-c/--encoding", i, args);
-        encoding = args[++i];
-      } else if (args[i].equals("-u") || args[i].equals("--list-unknown")) {
-        listUnknown = true;
-        if (taggerOnly) {
-          throw new IllegalArgumentException("You cannot list unknown words 
when tagging only.");
-        }
-      } else if (args[i].equals("-b")) {
-        singleLineBreakMarksParagraph = true;
-      } else if (args[i].equals("--api")) {
-        apiFormat = true;
-        if (applySuggestions) {
-          throw new IllegalArgumentException("API format makes no sense for 
automatic application of suggestions.");
-        }
-      } else if (args[i].equals("-a") || args[i].equals("--apply")) {
-        applySuggestions = true;
-        if (taggerOnly) {
-          throw new IllegalArgumentException("You cannot apply suggestions 
when tagging only.");
-        }
-        if (apiFormat) {
-          throw new IllegalArgumentException("API format makes no sense for 
automatic application of suggestions.");
-        }
-      } else if (args[i].equals("-p") || args[i].equals("--profile")) {
-        profile = true;
-        if (apiFormat) {
-          throw new IllegalArgumentException("API format makes no sense for 
profiling.");
-        }
-        if (applySuggestions) {
-          throw new IllegalArgumentException("Applying suggestions makes no 
sense for profiling.");
-        }
-        if (taggerOnly) {
-          throw new IllegalArgumentException("Tagging makes no sense for 
profiling.");
-        }
-      }  else if (i == args.length - 1) {
-        filename = args[i];
-      } else {
-        System.err.println("Unknown option: " + args[i]);
-        exitWithUsageMessage();
-      }
+
+    if (options.getFilename() == null) {
+      options.setFilename("-");
     }
-    if (filename == null) {
-      filename = "-";
-    }
 
-    if (language == null) {
-      if (!apiFormat && !autoDetect) {
+    if (options.getLanguage() == null) {
+      if (!options.isApiFormat() && !options.isAutoDetect()) {
         System.err.println("No language specified, using English");
       }
-      language = Language.ENGLISH;
-    } else if (!apiFormat && !applySuggestions) {
-      System.out.println("Expected text language: " + language.getName());
+      options.setLanguage(Language.ENGLISH);
+    } else if (!options.isApiFormat() && !options.isApplySuggestions()) {
+      System.out.println("Expected text language: " + 
options.getLanguage().getName());
     }
 
-    language.getSentenceTokenizer().setSingleLineBreaksMarksParagraph(
-        singleLineBreakMarksParagraph);
-    final Main prg = new Main(verbose, taggerOnly, language, motherTongue,
-        disabledRules, enabledRules, apiFormat, applySuggestions, autoDetect, 
singleLineBreakMarksParagraph);
-    prg.setListUnknownWords(listUnknown);
-    if (profile) {
+    
options.getLanguage().getSentenceTokenizer().setSingleLineBreaksMarksParagraph(
+            options.isSingleLineBreakMarksParagraph());
+    final Main prg = new Main(options.isVerbose(), options.isTaggerOnly(), 
options.getLanguage(), options.getMotherTongue(),
+            options.getDisabledRules(), options.getEnabledRules(), 
options.isApiFormat(), options.isApplySuggestions(),
+            options.isAutoDetect(), options.isSingleLineBreakMarksParagraph());
+    prg.setListUnknownWords(options.isListUnknown());
+    if (options.isProfile()) {
       prg.setProfilingMode();
     }
-    if (bitext) {
-      if (motherTongue == null) {
+    if (options.isBitext()) {
+      if (options.getMotherTongue() == null) {
         throw new IllegalArgumentException("You have to set the source 
language (as mother tongue) in bitext mode.");
       }
-      prg.setBitextMode(motherTongue, disabledRules, enabledRules);
+      prg.setBitextMode(options.getMotherTongue(), options.getDisabledRules(), 
options.getEnabledRules());
     }
-    if (recursive) {
-      prg.runRecursive(filename, encoding, listUnknown);
+    if (options.isRecursive()) {
+      prg.runRecursive(options.getFilename(), options.getEncoding(), 
options.isListUnknown());
     } else {
-      prg.runOnFile(filename, encoding, listUnknown);
+      prg.runOnFile(options.getFilename(), options.getEncoding(), 
options.isListUnknown());
     }
   }
 
-  private static void exitWithUsageMessage() {
-    System.out
-            .println("Usage: java org.languagetool.Main "
-                    + "[-r|--recursive] [-v|--verbose] [-l|--language LANG] 
[-m|--mothertongue LANG] [-d|--disable RULES] [-adl|--autoDetect] "
-                    + "[-e|--enable RULES] [-c|--encoding] [-u|--list-unknown] 
[-t|--taggeronly] [-b] [--api] [-a|--apply] "
-                    +    "[-b2|--bitext] <file>");
-    System.exit(1);
-  }
-
-  private static void checkArguments(String option, int argParsingPos, 
String[] args) {
-    if (argParsingPos + 1 >= args.length) {
-      throw new IllegalArgumentException("Missing argument to " + option + " 
command line option.");
-    }
-  }
-
   // for language auto detect
   // TODO: alter tika's language profiles so they are in line with LT's 
supported languages
   private static Language detectLanguageOfFile(String filename, String 
encoding) throws IOException {
@@ -616,18 +513,4 @@
     return lang;
   }
 
-  private static Language getLanguageOrExit(final String userSuppliedLangCode) 
{
-    final Language language = 
Language.getLanguageForShortName(userSuppliedLangCode);
-    if (language == null) {
-      final List<String> supportedLanguages = new ArrayList<String>();
-      for (final Language lang : Language.LANGUAGES) {
-        supportedLanguages.add(lang.getShortName());
-      }
-      System.out.println("Unknown language '" + userSuppliedLangCode
-          + "'. Supported languages are: " + supportedLanguages);
-      exitWithUsageMessage();
-    }
-    return language;
-  }
-
 }

Added: 
trunk/JLanguageTool/src/java/org/languagetool/commandline/CommandLineOptions.java
===================================================================
--- 
trunk/JLanguageTool/src/java/org/languagetool/commandline/CommandLineOptions.java
                           (rev 0)
+++ 
trunk/JLanguageTool/src/java/org/languagetool/commandline/CommandLineOptions.java
   2012-02-03 23:56:44 UTC (rev 6410)
@@ -0,0 +1,172 @@
+/* LanguageTool, a natural language style checker
+ * Copyright (C) 2012 Daniel Naber (http://www.danielnaber.de)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
+ * USA
+ */
+package org.languagetool.commandline;
+
+import org.languagetool.Language;
+
+/**
+ * Options that can be set via command line arguments.
+ */
+public class CommandLineOptions {
+
+  private boolean verbose = false;
+  private boolean recursive = false;
+  private boolean taggerOnly = false;
+  private boolean singleLineBreakMarksParagraph = false;
+  private boolean apiFormat = false;
+  private boolean listUnknown = false;
+  private boolean applySuggestions = false;
+  private boolean profile = false;
+  private boolean bitext = false;
+  private boolean autoDetect = false;
+  private Language language = null;
+  private Language motherTongue = null;
+  private String encoding = null;
+  private String filename = null;
+  private String[] disabledRules = new String[0];
+  private String[] enabledRules = new String[0];
+
+  public boolean isVerbose() {
+    return verbose;
+  }
+
+  public void setVerbose(boolean verbose) {
+    this.verbose = verbose;
+  }
+
+  public boolean isRecursive() {
+    return recursive;
+  }
+
+  public void setRecursive(boolean recursive) {
+    this.recursive = recursive;
+  }
+
+  public boolean isTaggerOnly() {
+    return taggerOnly;
+  }
+
+  public void setTaggerOnly(boolean taggerOnly) {
+    this.taggerOnly = taggerOnly;
+  }
+
+  public boolean isSingleLineBreakMarksParagraph() {
+    return singleLineBreakMarksParagraph;
+  }
+
+  public void setSingleLineBreakMarksParagraph(boolean 
singleLineBreakMarksParagraph) {
+    this.singleLineBreakMarksParagraph = singleLineBreakMarksParagraph;
+  }
+
+  public boolean isApiFormat() {
+    return apiFormat;
+  }
+
+  public void setApiFormat(boolean apiFormat) {
+    this.apiFormat = apiFormat;
+  }
+
+  public boolean isListUnknown() {
+    return listUnknown;
+  }
+
+  public void setListUnknown(boolean listUnknown) {
+    this.listUnknown = listUnknown;
+  }
+
+  public boolean isApplySuggestions() {
+    return applySuggestions;
+  }
+
+  public void setApplySuggestions(boolean applySuggestions) {
+    this.applySuggestions = applySuggestions;
+  }
+
+  public boolean isProfile() {
+    return profile;
+  }
+
+  public void setProfile(boolean profile) {
+    this.profile = profile;
+  }
+
+  public boolean isBitext() {
+    return bitext;
+  }
+
+  public void setBitext(boolean bitext) {
+    this.bitext = bitext;
+  }
+
+  public boolean isAutoDetect() {
+    return autoDetect;
+  }
+
+  public void setAutoDetect(boolean autoDetect) {
+    this.autoDetect = autoDetect;
+  }
+
+  public Language getLanguage() {
+    return language;
+  }
+
+  public void setLanguage(Language language) {
+    this.language = language;
+  }
+
+  public Language getMotherTongue() {
+    return motherTongue;
+  }
+
+  public void setMotherTongue(Language motherTongue) {
+    this.motherTongue = motherTongue;
+  }
+
+  public String getEncoding() {
+    return encoding;
+  }
+
+  public void setEncoding(String encoding) {
+    this.encoding = encoding;
+  }
+
+  public String getFilename() {
+    return filename;
+  }
+
+  public void setFilename(String filename) {
+    this.filename = filename;
+  }
+
+  public String[] getDisabledRules() {
+    return disabledRules;
+  }
+
+  public void setDisabledRules(String[] disabledRules) {
+    this.disabledRules = disabledRules;
+  }
+
+  public String[] getEnabledRules() {
+    return enabledRules;
+  }
+
+  public void setEnabledRules(String[] enabledRules) {
+    this.enabledRules = enabledRules;
+  }
+}

Added: 
trunk/JLanguageTool/src/java/org/languagetool/commandline/CommandLineParser.java
===================================================================
--- 
trunk/JLanguageTool/src/java/org/languagetool/commandline/CommandLineParser.java
                            (rev 0)
+++ 
trunk/JLanguageTool/src/java/org/languagetool/commandline/CommandLineParser.java
    2012-02-03 23:56:44 UTC (rev 6410)
@@ -0,0 +1,140 @@
+/* LanguageTool, a natural language style checker
+ * Copyright (C) 2012 Daniel Naber (http://www.danielnaber.de)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
+ * USA
+ */
+package org.languagetool.commandline;
+
+import org.languagetool.Language;
+import org.languagetool.tools.LanguageIdentifierTools;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Parser for the command line arguments.
+ */
+public class CommandLineParser {
+
+  public CommandLineOptions parseOptions(String[] args) {
+    if (args.length < 1 || args.length > 10) {
+      throw new IllegalArgumentException();
+    }
+    final CommandLineOptions options = new CommandLineOptions();
+    for (int i = 0; i < args.length; i++) {
+      if (args[i].equals("-h") || args[i].equals("-help") || 
args[i].equals("--help") || args[i].equals("--?")) {
+        throw new IllegalArgumentException();
+      } else if (args[i].equals("-adl") || args[i].equals("--autoDetect")) {   
 // set autoDetect flag
+        // also initialize the other language profiles for the 
LanguageIdentifier
+        LanguageIdentifierTools.addLtProfiles();
+        options.setAutoDetect(true);
+      } else if (args[i].equals("-v") || args[i].equals("--verbose")) {
+        options.setVerbose(true);
+      } else if (args[i].equals("-t") || args[i].equals("--taggeronly")) {
+        options.setTaggerOnly(true);
+        if (options.isListUnknown()) {
+          throw new IllegalArgumentException("You cannot list unknown words 
when tagging only.");
+        }
+        if (options.isApplySuggestions()) {
+          throw new IllegalArgumentException("You cannot apply suggestions 
when tagging only.");
+        }
+      } else if (args[i].equals("-r") || args[i].equals("--recursive")) {
+        options.setRecursive(true);
+      } else if (args[i].equals("-b2") || args[i].equals("--bitext")) {
+        options.setBitext(true);
+      } else if (args[i].equals("-d") || args[i].equals("--disable")) {
+        if (options.getEnabledRules().length > 0) {
+          throw new IllegalArgumentException("You cannot specify both enabled 
and disabled rules");
+        }
+        checkArguments("-d/--disable", i, args);
+        final String rules = args[++i];
+        options.setDisabledRules(rules.split(","));
+      } else if (args[i].equals("-e") || args[i].equals("--enable")) {
+        if (options.getDisabledRules().length > 0) {
+          throw new IllegalArgumentException("You cannot specify both enabled 
and disabled rules");
+        }
+        checkArguments("-e/--enable", i, args);
+        final String rules = args[++i];
+        options.setEnabledRules(rules.split(","));
+      } else if (args[i].equals("-l") || args[i].equals("--language")) {
+        checkArguments("-l/--language", i, args);
+        options.setLanguage(getLanguage(args[++i]));
+      } else if (args[i].equals("-m") || args[i].equals("--mothertongue")) {
+        checkArguments("-m/--mothertongue", i, args);
+        options.setMotherTongue(getLanguage(args[++i]));
+      } else if (args[i].equals("-c") || args[i].equals("--encoding")) {
+        checkArguments("-c/--encoding", i, args);
+        options.setEncoding(args[++i]);
+      } else if (args[i].equals("-u") || args[i].equals("--list-unknown")) {
+        options.setListUnknown(true);
+        if (options.isTaggerOnly()) {
+          throw new IllegalArgumentException("You cannot list unknown words 
when tagging only.");
+        }
+      } else if (args[i].equals("-b")) {
+        options.setSingleLineBreakMarksParagraph(true);
+      } else if (args[i].equals("--api")) {
+        options.setApiFormat(true);
+        if (options.isApplySuggestions()) {
+          throw new IllegalArgumentException("API format makes no sense for 
automatic application of suggestions.");
+        }
+      } else if (args[i].equals("-a") || args[i].equals("--apply")) {
+        options.setApplySuggestions(true);
+        if (options.isTaggerOnly()) {
+          throw new IllegalArgumentException("You cannot apply suggestions 
when tagging only.");
+        }
+        if (options.isApiFormat()) {
+          throw new IllegalArgumentException("API format makes no sense for 
automatic application of suggestions.");
+        }
+      } else if (args[i].equals("-p") || args[i].equals("--profile")) {
+        options.setProfile(true);
+        if (options.isApiFormat()) {
+          throw new IllegalArgumentException("API format makes no sense for 
profiling.");
+        }
+        if (options.isApplySuggestions()) {
+          throw new IllegalArgumentException("Applying suggestions makes no 
sense for profiling.");
+        }
+        if (options.isTaggerOnly()) {
+          throw new IllegalArgumentException("Tagging makes no sense for 
profiling.");
+        }
+      }  else if (i == args.length - 1) {
+        options.setFilename(args[i]);
+      } else {
+        throw new IllegalArgumentException("Unknown option: " + args[i]);
+      }
+    }
+    return options;
+  }
+
+  private void checkArguments(String option, int argParsingPos, String[] args) 
{
+    if (argParsingPos + 1 >= args.length) {
+      throw new IllegalArgumentException("Missing argument to " + option + " 
command line option.");
+    }
+  }
+
+  private Language getLanguage(String userSuppliedLangCode) {
+    final Language language = 
Language.getLanguageForShortName(userSuppliedLangCode);
+    if (language == null) {
+      final List<String> supportedLanguages = new ArrayList<String>();
+      for (final Language lang : Language.LANGUAGES) {
+        supportedLanguages.add(lang.getShortName());
+      }
+      throw new IllegalArgumentException("Unknown language '" + 
userSuppliedLangCode
+                + "'. Supported languages are: " + supportedLanguages);
+    }
+    return language;
+  }
+
+}

Added: 
trunk/JLanguageTool/src/test/org/languagetool/commandline/CommandLineParserTest.java
===================================================================
--- 
trunk/JLanguageTool/src/test/org/languagetool/commandline/CommandLineParserTest.java
                                (rev 0)
+++ 
trunk/JLanguageTool/src/test/org/languagetool/commandline/CommandLineParserTest.java
        2012-02-03 23:56:44 UTC (rev 6410)
@@ -0,0 +1,72 @@
+/* LanguageTool, a natural language style checker
+ * Copyright (C) 2012 Daniel Naber (http://www.danielnaber.de)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
+ * USA
+ */
+package org.languagetool.commandline;
+
+import junit.framework.TestCase;
+import org.languagetool.Language;
+
+public class CommandLineParserTest extends TestCase {
+
+  public void testUsage() throws Exception {
+    final CommandLineParser parser = new CommandLineParser();
+    try {
+      parser.parseOptions(new String[]{});
+      fail();
+    } catch (IllegalArgumentException expected) {}
+
+    try {
+      parser.parseOptions(new String[]{"--help"});
+      fail();
+    } catch (IllegalArgumentException expected) {}
+  }
+
+  public void testErrors() throws Exception {
+    final CommandLineParser parser = new CommandLineParser();
+    try {
+      parser.parseOptions(new String[]{"--apply", "--taggeronly"});
+      fail();
+    } catch (IllegalArgumentException expected) {}
+  }
+
+  public void testSimple() throws Exception {
+    final CommandLineParser parser = new CommandLineParser();
+    CommandLineOptions options;
+
+    options = parser.parseOptions(new String[]{"filename.txt"});
+    assertNull(options.getLanguage());
+    assertEquals("filename.txt", options.getFilename());
+    assertFalse(options.isVerbose());
+
+    options = parser.parseOptions(new String[]{"--language", "de", 
"filename.txt"});
+    assertEquals(Language.GERMAN, options.getLanguage());
+    assertEquals("filename.txt", options.getFilename());
+    assertFalse(options.isVerbose());
+
+    options = parser.parseOptions(new String[]{"-l", "de", "filename.txt"});
+    assertEquals(Language.GERMAN, options.getLanguage());
+    assertEquals("filename.txt", options.getFilename());
+    assertFalse(options.isVerbose());
+
+    options = parser.parseOptions(new String[]{"-v", "-l", "de", 
"filename.txt"});
+    assertEquals(Language.GERMAN, options.getLanguage());
+    assertEquals("filename.txt", options.getFilename());
+    assertTrue(options.isVerbose());
+  }
+
+}

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
Try before you buy = See our experts in action!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-dev2
_______________________________________________
Languagetool-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/languagetool-cvs

Reply via email to