@Test void testMainWithoutInput() throws RedPenException { String[] args = new String[]{ "-c", "sample/conf/redpen-conf-en.xml", }; assertEquals(1, Main.run(args)); }
@SuppressWarnings("static-access") public static int run(String... args) throws RedPenException { Options options = new Options(); options.addOption("h", "help", false, "Displays this help information and exits"); options.addOption(OptionBuilder.withLongOpt("format") .withDescription("Input file format (markdown,plain,wiki,asciidoc,latex,rest)") .hasArg() .withArgName("FORMAT") .create("f")); options.addOption(OptionBuilder.withLongOpt("conf") .withDescription("Configuration file (REQUIRED)") .hasArg() .withArgName("CONF FILE") .create("c")); options.addOption(OptionBuilder.withLongOpt("result-format") .withDescription("Output result format (json,json2,plain,plain2,xml)") .hasArg() .withArgName("RESULT FORMAT") .create("r")); options.addOption(OptionBuilder.withLongOpt("limit") .withDescription("Error limit number") .hasArg() .withArgName("LIMIT NUMBER") .create("l")); options.addOption(OptionBuilder.withLongOpt("sentence") .withDescription("Input sentences") .hasArg() .withArgName("INPUT SENTENCES") .create("s")); options.addOption(OptionBuilder.withLongOpt("lang") .withDescription("Language of error messages") .hasArg() .withArgName("LANGUAGE") .create("L")); options.addOption(OptionBuilder.withLongOpt("threshold") .withDescription("Threshold of error level (info, warn, error)") .hasArg() .withArgName("THRESHOLD") .create("t")); options.addOption(OptionBuilder.withLongOpt("version") .withDescription("Displays version information and exits") .create("v")); CommandLineParser commandLineParser = new BasicParser(); CommandLine commandLine; try { commandLine = commandLineParser.parse(options, args); } catch (ParseException e) { LOG.error("Error occurred in parsing command line options "); printHelp(options); return -1; } String inputFormat = "plain"; String configFileName = null; String resultFormat = "plain"; String inputSentence = null; String language = "en"; String threshold = "error"; int limit = DEFAULT_LIMIT; if (commandLine.hasOption("h")) { printHelp(options); return 0; } if (commandLine.hasOption("v")) { System.out.println(RedPen.VERSION); return 0; } if (commandLine.hasOption("f")) { inputFormat = commandLine.getOptionValue("f"); } if (commandLine.hasOption("c")) { configFileName = commandLine.getOptionValue("c"); } if (commandLine.hasOption("r")) { resultFormat = commandLine.getOptionValue("r"); } if (commandLine.hasOption("l")) { limit = Integer.valueOf(commandLine.getOptionValue("l")); } if (commandLine.hasOption("L")) { language = commandLine.getOptionValue("L"); } if (commandLine.hasOption("s")) { inputSentence = commandLine.getOptionValue("s"); } if (commandLine.hasOption("t")) { threshold= commandLine.getOptionValue("t"); } if (language.equals("ja")) { Locale.setDefault(new Locale("ja", "JA")); } else { Locale.setDefault(new Locale("en", "EN")); } String[] inputFileNames = commandLine.getArgs(); if (!commandLine.hasOption("f")) { inputFormat = guessInputFormat(inputFileNames); } File configFile = resolveConfigLocation(configFileName); if (configFile == null) { LOG.error("Configuration file is not found."); printHelp(options); return 1; } if (inputFileNames.length == 0 && inputSentence == null) { LOG.error("Input is not given"); printHelp(options); return 1; } RedPen redPen; try { redPen = new RedPen(configFile); } catch (RedPenException e) { LOG.error("Failed to parse input files: " + e); return -1; } List<Document> documents = getDocuments(inputFormat, inputSentence, inputFileNames, redPen); Map<Document, List<ValidationError>> documentListMap = redPen.validate(documents, threshold); Formatter formatter = FormatterUtils.getFormatterByName(resultFormat); if (formatter == null) { LOG.error("Unsupported format: " + resultFormat + " - please use xml, plain, plain2, json or json2"); return -1; } String result = formatter.format(documentListMap); System.out.println(result); long errorCount = documentListMap.values().stream().mapToLong(List::size).sum(); if (errorCount > limit) { LOG.error("The number of errors \"{}\" is larger than specified (limit is \"{}\").", errorCount, limit); return 1; } else { return 0; } }
Main { @SuppressWarnings("static-access") public static int run(String... args) throws RedPenException { Options options = new Options(); options.addOption("h", "help", false, "Displays this help information and exits"); options.addOption(OptionBuilder.withLongOpt("format") .withDescription("Input file format (markdown,plain,wiki,asciidoc,latex,rest)") .hasArg() .withArgName("FORMAT") .create("f")); options.addOption(OptionBuilder.withLongOpt("conf") .withDescription("Configuration file (REQUIRED)") .hasArg() .withArgName("CONF FILE") .create("c")); options.addOption(OptionBuilder.withLongOpt("result-format") .withDescription("Output result format (json,json2,plain,plain2,xml)") .hasArg() .withArgName("RESULT FORMAT") .create("r")); options.addOption(OptionBuilder.withLongOpt("limit") .withDescription("Error limit number") .hasArg() .withArgName("LIMIT NUMBER") .create("l")); options.addOption(OptionBuilder.withLongOpt("sentence") .withDescription("Input sentences") .hasArg() .withArgName("INPUT SENTENCES") .create("s")); options.addOption(OptionBuilder.withLongOpt("lang") .withDescription("Language of error messages") .hasArg() .withArgName("LANGUAGE") .create("L")); options.addOption(OptionBuilder.withLongOpt("threshold") .withDescription("Threshold of error level (info, warn, error)") .hasArg() .withArgName("THRESHOLD") .create("t")); options.addOption(OptionBuilder.withLongOpt("version") .withDescription("Displays version information and exits") .create("v")); CommandLineParser commandLineParser = new BasicParser(); CommandLine commandLine; try { commandLine = commandLineParser.parse(options, args); } catch (ParseException e) { LOG.error("Error occurred in parsing command line options "); printHelp(options); return -1; } String inputFormat = "plain"; String configFileName = null; String resultFormat = "plain"; String inputSentence = null; String language = "en"; String threshold = "error"; int limit = DEFAULT_LIMIT; if (commandLine.hasOption("h")) { printHelp(options); return 0; } if (commandLine.hasOption("v")) { System.out.println(RedPen.VERSION); return 0; } if (commandLine.hasOption("f")) { inputFormat = commandLine.getOptionValue("f"); } if (commandLine.hasOption("c")) { configFileName = commandLine.getOptionValue("c"); } if (commandLine.hasOption("r")) { resultFormat = commandLine.getOptionValue("r"); } if (commandLine.hasOption("l")) { limit = Integer.valueOf(commandLine.getOptionValue("l")); } if (commandLine.hasOption("L")) { language = commandLine.getOptionValue("L"); } if (commandLine.hasOption("s")) { inputSentence = commandLine.getOptionValue("s"); } if (commandLine.hasOption("t")) { threshold= commandLine.getOptionValue("t"); } if (language.equals("ja")) { Locale.setDefault(new Locale("ja", "JA")); } else { Locale.setDefault(new Locale("en", "EN")); } String[] inputFileNames = commandLine.getArgs(); if (!commandLine.hasOption("f")) { inputFormat = guessInputFormat(inputFileNames); } File configFile = resolveConfigLocation(configFileName); if (configFile == null) { LOG.error("Configuration file is not found."); printHelp(options); return 1; } if (inputFileNames.length == 0 && inputSentence == null) { LOG.error("Input is not given"); printHelp(options); return 1; } RedPen redPen; try { redPen = new RedPen(configFile); } catch (RedPenException e) { LOG.error("Failed to parse input files: " + e); return -1; } List<Document> documents = getDocuments(inputFormat, inputSentence, inputFileNames, redPen); Map<Document, List<ValidationError>> documentListMap = redPen.validate(documents, threshold); Formatter formatter = FormatterUtils.getFormatterByName(resultFormat); if (formatter == null) { LOG.error("Unsupported format: " + resultFormat + " - please use xml, plain, plain2, json or json2"); return -1; } String result = formatter.format(documentListMap); System.out.println(result); long errorCount = documentListMap.values().stream().mapToLong(List::size).sum(); if (errorCount > limit) { LOG.error("The number of errors \"{}\" is larger than specified (limit is \"{}\").", errorCount, limit); return 1; } else { return 0; } } }
Main { @SuppressWarnings("static-access") public static int run(String... args) throws RedPenException { Options options = new Options(); options.addOption("h", "help", false, "Displays this help information and exits"); options.addOption(OptionBuilder.withLongOpt("format") .withDescription("Input file format (markdown,plain,wiki,asciidoc,latex,rest)") .hasArg() .withArgName("FORMAT") .create("f")); options.addOption(OptionBuilder.withLongOpt("conf") .withDescription("Configuration file (REQUIRED)") .hasArg() .withArgName("CONF FILE") .create("c")); options.addOption(OptionBuilder.withLongOpt("result-format") .withDescription("Output result format (json,json2,plain,plain2,xml)") .hasArg() .withArgName("RESULT FORMAT") .create("r")); options.addOption(OptionBuilder.withLongOpt("limit") .withDescription("Error limit number") .hasArg() .withArgName("LIMIT NUMBER") .create("l")); options.addOption(OptionBuilder.withLongOpt("sentence") .withDescription("Input sentences") .hasArg() .withArgName("INPUT SENTENCES") .create("s")); options.addOption(OptionBuilder.withLongOpt("lang") .withDescription("Language of error messages") .hasArg() .withArgName("LANGUAGE") .create("L")); options.addOption(OptionBuilder.withLongOpt("threshold") .withDescription("Threshold of error level (info, warn, error)") .hasArg() .withArgName("THRESHOLD") .create("t")); options.addOption(OptionBuilder.withLongOpt("version") .withDescription("Displays version information and exits") .create("v")); CommandLineParser commandLineParser = new BasicParser(); CommandLine commandLine; try { commandLine = commandLineParser.parse(options, args); } catch (ParseException e) { LOG.error("Error occurred in parsing command line options "); printHelp(options); return -1; } String inputFormat = "plain"; String configFileName = null; String resultFormat = "plain"; String inputSentence = null; String language = "en"; String threshold = "error"; int limit = DEFAULT_LIMIT; if (commandLine.hasOption("h")) { printHelp(options); return 0; } if (commandLine.hasOption("v")) { System.out.println(RedPen.VERSION); return 0; } if (commandLine.hasOption("f")) { inputFormat = commandLine.getOptionValue("f"); } if (commandLine.hasOption("c")) { configFileName = commandLine.getOptionValue("c"); } if (commandLine.hasOption("r")) { resultFormat = commandLine.getOptionValue("r"); } if (commandLine.hasOption("l")) { limit = Integer.valueOf(commandLine.getOptionValue("l")); } if (commandLine.hasOption("L")) { language = commandLine.getOptionValue("L"); } if (commandLine.hasOption("s")) { inputSentence = commandLine.getOptionValue("s"); } if (commandLine.hasOption("t")) { threshold= commandLine.getOptionValue("t"); } if (language.equals("ja")) { Locale.setDefault(new Locale("ja", "JA")); } else { Locale.setDefault(new Locale("en", "EN")); } String[] inputFileNames = commandLine.getArgs(); if (!commandLine.hasOption("f")) { inputFormat = guessInputFormat(inputFileNames); } File configFile = resolveConfigLocation(configFileName); if (configFile == null) { LOG.error("Configuration file is not found."); printHelp(options); return 1; } if (inputFileNames.length == 0 && inputSentence == null) { LOG.error("Input is not given"); printHelp(options); return 1; } RedPen redPen; try { redPen = new RedPen(configFile); } catch (RedPenException e) { LOG.error("Failed to parse input files: " + e); return -1; } List<Document> documents = getDocuments(inputFormat, inputSentence, inputFileNames, redPen); Map<Document, List<ValidationError>> documentListMap = redPen.validate(documents, threshold); Formatter formatter = FormatterUtils.getFormatterByName(resultFormat); if (formatter == null) { LOG.error("Unsupported format: " + resultFormat + " - please use xml, plain, plain2, json or json2"); return -1; } String result = formatter.format(documentListMap); System.out.println(result); long errorCount = documentListMap.values().stream().mapToLong(List::size).sum(); if (errorCount > limit) { LOG.error("The number of errors \"{}\" is larger than specified (limit is \"{}\").", errorCount, limit); return 1; } else { return 0; } } private  Main(); }
Main { @SuppressWarnings("static-access") public static int run(String... args) throws RedPenException { Options options = new Options(); options.addOption("h", "help", false, "Displays this help information and exits"); options.addOption(OptionBuilder.withLongOpt("format") .withDescription("Input file format (markdown,plain,wiki,asciidoc,latex,rest)") .hasArg() .withArgName("FORMAT") .create("f")); options.addOption(OptionBuilder.withLongOpt("conf") .withDescription("Configuration file (REQUIRED)") .hasArg() .withArgName("CONF FILE") .create("c")); options.addOption(OptionBuilder.withLongOpt("result-format") .withDescription("Output result format (json,json2,plain,plain2,xml)") .hasArg() .withArgName("RESULT FORMAT") .create("r")); options.addOption(OptionBuilder.withLongOpt("limit") .withDescription("Error limit number") .hasArg() .withArgName("LIMIT NUMBER") .create("l")); options.addOption(OptionBuilder.withLongOpt("sentence") .withDescription("Input sentences") .hasArg() .withArgName("INPUT SENTENCES") .create("s")); options.addOption(OptionBuilder.withLongOpt("lang") .withDescription("Language of error messages") .hasArg() .withArgName("LANGUAGE") .create("L")); options.addOption(OptionBuilder.withLongOpt("threshold") .withDescription("Threshold of error level (info, warn, error)") .hasArg() .withArgName("THRESHOLD") .create("t")); options.addOption(OptionBuilder.withLongOpt("version") .withDescription("Displays version information and exits") .create("v")); CommandLineParser commandLineParser = new BasicParser(); CommandLine commandLine; try { commandLine = commandLineParser.parse(options, args); } catch (ParseException e) { LOG.error("Error occurred in parsing command line options "); printHelp(options); return -1; } String inputFormat = "plain"; String configFileName = null; String resultFormat = "plain"; String inputSentence = null; String language = "en"; String threshold = "error"; int limit = DEFAULT_LIMIT; if (commandLine.hasOption("h")) { printHelp(options); return 0; } if (commandLine.hasOption("v")) { System.out.println(RedPen.VERSION); return 0; } if (commandLine.hasOption("f")) { inputFormat = commandLine.getOptionValue("f"); } if (commandLine.hasOption("c")) { configFileName = commandLine.getOptionValue("c"); } if (commandLine.hasOption("r")) { resultFormat = commandLine.getOptionValue("r"); } if (commandLine.hasOption("l")) { limit = Integer.valueOf(commandLine.getOptionValue("l")); } if (commandLine.hasOption("L")) { language = commandLine.getOptionValue("L"); } if (commandLine.hasOption("s")) { inputSentence = commandLine.getOptionValue("s"); } if (commandLine.hasOption("t")) { threshold= commandLine.getOptionValue("t"); } if (language.equals("ja")) { Locale.setDefault(new Locale("ja", "JA")); } else { Locale.setDefault(new Locale("en", "EN")); } String[] inputFileNames = commandLine.getArgs(); if (!commandLine.hasOption("f")) { inputFormat = guessInputFormat(inputFileNames); } File configFile = resolveConfigLocation(configFileName); if (configFile == null) { LOG.error("Configuration file is not found."); printHelp(options); return 1; } if (inputFileNames.length == 0 && inputSentence == null) { LOG.error("Input is not given"); printHelp(options); return 1; } RedPen redPen; try { redPen = new RedPen(configFile); } catch (RedPenException e) { LOG.error("Failed to parse input files: " + e); return -1; } List<Document> documents = getDocuments(inputFormat, inputSentence, inputFileNames, redPen); Map<Document, List<ValidationError>> documentListMap = redPen.validate(documents, threshold); Formatter formatter = FormatterUtils.getFormatterByName(resultFormat); if (formatter == null) { LOG.error("Unsupported format: " + resultFormat + " - please use xml, plain, plain2, json or json2"); return -1; } String result = formatter.format(documentListMap); System.out.println(result); long errorCount = documentListMap.values().stream().mapToLong(List::size).sum(); if (errorCount > limit) { LOG.error("The number of errors \"{}\" is larger than specified (limit is \"{}\").", errorCount, limit); return 1; } else { return 0; } } private  Main(); static void main(String... args); @SuppressWarnings("static-access") static int run(String... args); }
Main { @SuppressWarnings("static-access") public static int run(String... args) throws RedPenException { Options options = new Options(); options.addOption("h", "help", false, "Displays this help information and exits"); options.addOption(OptionBuilder.withLongOpt("format") .withDescription("Input file format (markdown,plain,wiki,asciidoc,latex,rest)") .hasArg() .withArgName("FORMAT") .create("f")); options.addOption(OptionBuilder.withLongOpt("conf") .withDescription("Configuration file (REQUIRED)") .hasArg() .withArgName("CONF FILE") .create("c")); options.addOption(OptionBuilder.withLongOpt("result-format") .withDescription("Output result format (json,json2,plain,plain2,xml)") .hasArg() .withArgName("RESULT FORMAT") .create("r")); options.addOption(OptionBuilder.withLongOpt("limit") .withDescription("Error limit number") .hasArg() .withArgName("LIMIT NUMBER") .create("l")); options.addOption(OptionBuilder.withLongOpt("sentence") .withDescription("Input sentences") .hasArg() .withArgName("INPUT SENTENCES") .create("s")); options.addOption(OptionBuilder.withLongOpt("lang") .withDescription("Language of error messages") .hasArg() .withArgName("LANGUAGE") .create("L")); options.addOption(OptionBuilder.withLongOpt("threshold") .withDescription("Threshold of error level (info, warn, error)") .hasArg() .withArgName("THRESHOLD") .create("t")); options.addOption(OptionBuilder.withLongOpt("version") .withDescription("Displays version information and exits") .create("v")); CommandLineParser commandLineParser = new BasicParser(); CommandLine commandLine; try { commandLine = commandLineParser.parse(options, args); } catch (ParseException e) { LOG.error("Error occurred in parsing command line options "); printHelp(options); return -1; } String inputFormat = "plain"; String configFileName = null; String resultFormat = "plain"; String inputSentence = null; String language = "en"; String threshold = "error"; int limit = DEFAULT_LIMIT; if (commandLine.hasOption("h")) { printHelp(options); return 0; } if (commandLine.hasOption("v")) { System.out.println(RedPen.VERSION); return 0; } if (commandLine.hasOption("f")) { inputFormat = commandLine.getOptionValue("f"); } if (commandLine.hasOption("c")) { configFileName = commandLine.getOptionValue("c"); } if (commandLine.hasOption("r")) { resultFormat = commandLine.getOptionValue("r"); } if (commandLine.hasOption("l")) { limit = Integer.valueOf(commandLine.getOptionValue("l")); } if (commandLine.hasOption("L")) { language = commandLine.getOptionValue("L"); } if (commandLine.hasOption("s")) { inputSentence = commandLine.getOptionValue("s"); } if (commandLine.hasOption("t")) { threshold= commandLine.getOptionValue("t"); } if (language.equals("ja")) { Locale.setDefault(new Locale("ja", "JA")); } else { Locale.setDefault(new Locale("en", "EN")); } String[] inputFileNames = commandLine.getArgs(); if (!commandLine.hasOption("f")) { inputFormat = guessInputFormat(inputFileNames); } File configFile = resolveConfigLocation(configFileName); if (configFile == null) { LOG.error("Configuration file is not found."); printHelp(options); return 1; } if (inputFileNames.length == 0 && inputSentence == null) { LOG.error("Input is not given"); printHelp(options); return 1; } RedPen redPen; try { redPen = new RedPen(configFile); } catch (RedPenException e) { LOG.error("Failed to parse input files: " + e); return -1; } List<Document> documents = getDocuments(inputFormat, inputSentence, inputFileNames, redPen); Map<Document, List<ValidationError>> documentListMap = redPen.validate(documents, threshold); Formatter formatter = FormatterUtils.getFormatterByName(resultFormat); if (formatter == null) { LOG.error("Unsupported format: " + resultFormat + " - please use xml, plain, plain2, json or json2"); return -1; } String result = formatter.format(documentListMap); System.out.println(result); long errorCount = documentListMap.values().stream().mapToLong(List::size).sum(); if (errorCount > limit) { LOG.error("The number of errors \"{}\" is larger than specified (limit is \"{}\").", errorCount, limit); return 1; } else { return 0; } } private  Main(); static void main(String... args); @SuppressWarnings("static-access") static int run(String... args);  }