Revision: 7988
          
http://languagetool.svn.sourceforge.net/languagetool/?rev=7988&view=rev
Author:   dnaber
Date:     2012-09-04 22:12:46 +0000 (Tue, 04 Sep 2012)
Log Message:
-----------
command line: new option "--list" to list all available languages

Modified Paths:
--------------
    trunk/JLanguageTool/CHANGES.txt
    trunk/JLanguageTool/src/main/java/org/languagetool/Main.java
    
trunk/JLanguageTool/src/main/java/org/languagetool/commandline/CommandLineOptions.java
    
trunk/JLanguageTool/src/main/java/org/languagetool/commandline/CommandLineParser.java
    trunk/JLanguageTool/src/test/java/org/languagetool/MainTest.java
    
trunk/JLanguageTool/src/test/java/org/languagetool/commandline/CommandLineParserTest.java

Modified: trunk/JLanguageTool/CHANGES.txt
===================================================================
--- trunk/JLanguageTool/CHANGES.txt     2012-09-04 21:30:46 UTC (rev 7987)
+++ trunk/JLanguageTool/CHANGES.txt     2012-09-04 22:12:46 UTC (rev 7988)
@@ -50,6 +50,8 @@
   are only filtered out if the new --xmlfilter option is specified. Note that 
there's still
   a bug that can screw up position information with that option, thus it is 
deprecated.
 
+ -command line: new option "--list" to list all available languages
+
  -introduced a file resources/<lang>/hunspell/ignore.txt with words that the 
spell checker
   will ignore
 

Modified: trunk/JLanguageTool/src/main/java/org/languagetool/Main.java
===================================================================
--- trunk/JLanguageTool/src/main/java/org/languagetool/Main.java        
2012-09-04 21:30:46 UTC (rev 7987)
+++ trunk/JLanguageTool/src/main/java/org/languagetool/Main.java        
2012-09-04 22:12:46 UTC (rev 7988)
@@ -456,6 +456,10 @@
       System.out.println("LanguageTool version " + JLanguageTool.VERSION);
       System.exit(0);
     }
+    if (options.isPrintLanguages()) {
+      printLanguages();
+      System.exit(0);
+    }
 
     if (options.getFilename() == null) {
       options.setFilename("-");
@@ -493,6 +497,17 @@
     prg.cleanUp();
   }
 
+  private static void printLanguages() {
+    final List<String> languages = new ArrayList<String>();
+    for (Language language : Language.REAL_LANGUAGES) {
+      languages.add(language.getShortNameWithVariant() + " " + 
language.getName());
+    }
+    Collections.sort(languages);
+    for (String s : languages) {
+      System.out.println(s);
+    }
+  }
+
   // for language auto detect
   // TODO: alter tika's language profiles so they are in line with LT's 
supported languages
   private static Language detectLanguageOfFile(final String filename, final 
String encoding) throws IOException {

Modified: 
trunk/JLanguageTool/src/main/java/org/languagetool/commandline/CommandLineOptions.java
===================================================================
--- 
trunk/JLanguageTool/src/main/java/org/languagetool/commandline/CommandLineOptions.java
      2012-09-04 21:30:46 UTC (rev 7987)
+++ 
trunk/JLanguageTool/src/main/java/org/languagetool/commandline/CommandLineOptions.java
      2012-09-04 22:12:46 UTC (rev 7988)
@@ -26,6 +26,7 @@
 public class CommandLineOptions {
 
   private boolean printVersion = false;
+  private boolean printLanguages = false;
   private boolean verbose = false;
   private boolean recursive = false;
   private boolean taggerOnly = false;
@@ -187,4 +188,12 @@
   public void setXmlFiltering(boolean xmlFiltering) {
     this.xmlFiltering = xmlFiltering;
   }
+
+  public boolean isPrintLanguages() {
+    return printLanguages;
+  }
+
+  public void setPrintLanguages(boolean printLanguages) {
+    this.printLanguages = printLanguages;
+  }
 }

Modified: 
trunk/JLanguageTool/src/main/java/org/languagetool/commandline/CommandLineParser.java
===================================================================
--- 
trunk/JLanguageTool/src/main/java/org/languagetool/commandline/CommandLineParser.java
       2012-09-04 21:30:46 UTC (rev 7987)
+++ 
trunk/JLanguageTool/src/main/java/org/languagetool/commandline/CommandLineParser.java
       2012-09-04 22:12:46 UTC (rev 7988)
@@ -37,6 +37,8 @@
     for (int i = 0; i < args.length; i++) {
       if (args[i].equals("--version")) {
         options.setPrintVersion(true);
+      } else if (args[i].equals("--list")) {
+        options.setPrintLanguages(true);
       } else 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
@@ -130,6 +132,7 @@
             + "  -c, --encoding ENC       character set of the input text, 
e.g. utf-8 or latin1\n"
             + "  -b                       assume that a single line break 
marks the end of a paragraph\n"
             + "  -l, --language LANG      the language code of the text, e.g. 
en for English, en-GB for British English\n"
+            + "  --list                   Print all available languages and 
exit\n"
             + "  -adl, --autoDetect       auto-detect the language of the 
input text\n"
             + "  -m, --mothertongue LANG  the language code of your first 
language, used to activate false-friend checking\n"
             + "  -d, --disable RULES      a comma-separated list of rule ids 
to be disabled (use no spaces between ids)\n"

Modified: trunk/JLanguageTool/src/test/java/org/languagetool/MainTest.java
===================================================================
--- trunk/JLanguageTool/src/test/java/org/languagetool/MainTest.java    
2012-09-04 21:30:46 UTC (rev 7987)
+++ trunk/JLanguageTool/src/test/java/org/languagetool/MainTest.java    
2012-09-04 22:12:46 UTC (rev 7988)
@@ -76,6 +76,20 @@
     }
   }
 
+  public void testPrintLanguages() throws Exception {
+    try {
+      String[] args = new String[] {"--list"};
+      Main.main(args);
+      fail("LT should have exited with status 0!");
+    } catch (ExitException e) {
+      String output = new String(this.out.toByteArray());
+      assertTrue(output.contains("German"));
+      assertTrue(output.contains("de-DE"));
+      assertTrue(output.contains("English"));
+      assertEquals("Exit status", 0, e.status);
+    }
+  }
+
   public void testEnglishFile() throws Exception {
     final URL url = this.getClass().getResource(ENGLISH_TEST_FILE);
     final URI uri = new URI (url.toString());

Modified: 
trunk/JLanguageTool/src/test/java/org/languagetool/commandline/CommandLineParserTest.java
===================================================================
--- 
trunk/JLanguageTool/src/test/java/org/languagetool/commandline/CommandLineParserTest.java
   2012-09-04 21:30:46 UTC (rev 7987)
+++ 
trunk/JLanguageTool/src/test/java/org/languagetool/commandline/CommandLineParserTest.java
   2012-09-04 22:12:46 UTC (rev 7988)
@@ -71,6 +71,9 @@
 
     options = parser.parseOptions(new String[]{"--version"});
     assertTrue(options.isPrintVersion());
+
+    options = parser.parseOptions(new String[]{"--list"});
+    assertTrue(options.isPrintLanguages());
   }
 
 }

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


------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Languagetool-cvs mailing list
Languagetool-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/languagetool-cvs

Reply via email to