@Test public void testParseCmdArgs() { System.out.println("parseCmdArgs"); String lang = "de"; String[] argv = new String[]{"--lang", lang}; CommandLine result = CowsayCli.parseCmdArgs(argv); Assert.assertEquals(lang, result.getOptionValue("lang")); }
public static CommandLine parseCmdArgs(final String[] argv) { final CommandLineParser cmdLineParser = new DefaultParser(); try { CommandLine parsed = cmdLineParser.parse(OPTIONS, argv, true); if (parsed.hasOption(Opt.LANG.text)) { String language = parsed.getOptionValue(Opt.LANG.text); if (language != null) { I18n.setLanguage(language); } } return parsed; } catch (MissingArgumentException ex) { Option option = ex.getOption(); String flag = option.getOpt(); if (flag == null) { flag = option.getLongOpt(); } String message; try { message = I18n.getMessage("missingarg." + flag); } catch (MissingResourceException mre) { message = MessageFormat.format(I18n.getMessage("missingarg"), flag); } System.err.println(message); } catch (ParseException ex) { Logger.getLogger(CowsayCli.class.getName()).log(Level.FINEST, null, ex); } return null; }
CowsayCli { public static CommandLine parseCmdArgs(final String[] argv) { final CommandLineParser cmdLineParser = new DefaultParser(); try { CommandLine parsed = cmdLineParser.parse(OPTIONS, argv, true); if (parsed.hasOption(Opt.LANG.text)) { String language = parsed.getOptionValue(Opt.LANG.text); if (language != null) { I18n.setLanguage(language); } } return parsed; } catch (MissingArgumentException ex) { Option option = ex.getOption(); String flag = option.getOpt(); if (flag == null) { flag = option.getLongOpt(); } String message; try { message = I18n.getMessage("missingarg." + flag); } catch (MissingResourceException mre) { message = MessageFormat.format(I18n.getMessage("missingarg"), flag); } System.err.println(message); } catch (ParseException ex) { Logger.getLogger(CowsayCli.class.getName()).log(Level.FINEST, null, ex); } return null; } }
CowsayCli { public static CommandLine parseCmdArgs(final String[] argv) { final CommandLineParser cmdLineParser = new DefaultParser(); try { CommandLine parsed = cmdLineParser.parse(OPTIONS, argv, true); if (parsed.hasOption(Opt.LANG.text)) { String language = parsed.getOptionValue(Opt.LANG.text); if (language != null) { I18n.setLanguage(language); } } return parsed; } catch (MissingArgumentException ex) { Option option = ex.getOption(); String flag = option.getOpt(); if (flag == null) { flag = option.getLongOpt(); } String message; try { message = I18n.getMessage("missingarg." + flag); } catch (MissingResourceException mre) { message = MessageFormat.format(I18n.getMessage("missingarg"), flag); } System.err.println(message); } catch (ParseException ex) { Logger.getLogger(CowsayCli.class.getName()).log(Level.FINEST, null, ex); } return null; } private  CowsayCli(); }
CowsayCli { public static CommandLine parseCmdArgs(final String[] argv) { final CommandLineParser cmdLineParser = new DefaultParser(); try { CommandLine parsed = cmdLineParser.parse(OPTIONS, argv, true); if (parsed.hasOption(Opt.LANG.text)) { String language = parsed.getOptionValue(Opt.LANG.text); if (language != null) { I18n.setLanguage(language); } } return parsed; } catch (MissingArgumentException ex) { Option option = ex.getOption(); String flag = option.getOpt(); if (flag == null) { flag = option.getLongOpt(); } String message; try { message = I18n.getMessage("missingarg." + flag); } catch (MissingResourceException mre) { message = MessageFormat.format(I18n.getMessage("missingarg"), flag); } System.err.println(message); } catch (ParseException ex) { Logger.getLogger(CowsayCli.class.getName()).log(Level.FINEST, null, ex); } return null; } private  CowsayCli(); static CommandLine parseCmdArgs(final String[] argv); static String[] getPipedInput(); static void showCmdLineHelp(); }
CowsayCli { public static CommandLine parseCmdArgs(final String[] argv) { final CommandLineParser cmdLineParser = new DefaultParser(); try { CommandLine parsed = cmdLineParser.parse(OPTIONS, argv, true); if (parsed.hasOption(Opt.LANG.text)) { String language = parsed.getOptionValue(Opt.LANG.text); if (language != null) { I18n.setLanguage(language); } } return parsed; } catch (MissingArgumentException ex) { Option option = ex.getOption(); String flag = option.getOpt(); if (flag == null) { flag = option.getLongOpt(); } String message; try { message = I18n.getMessage("missingarg." + flag); } catch (MissingResourceException mre) { message = MessageFormat.format(I18n.getMessage("missingarg"), flag); } System.err.println(message); } catch (ParseException ex) { Logger.getLogger(CowsayCli.class.getName()).log(Level.FINEST, null, ex); } return null; } private  CowsayCli(); static CommandLine parseCmdArgs(final String[] argv); static String[] getPipedInput(); static void showCmdLineHelp();  }