private static String formatMessage(String message, Argument arg, ArgumentParserConfiguration config) { return String.format(Locale.ROOT, config.getResourceBundle().getString("argument"), arg.textualName(), message); }
@Override public Path convert(ArgumentParser parser, Argument arg, String value) throws ArgumentParserException { Path path; try { path = new Path(value); } catch (IllegalArgumentException e) { String localizedTypeName = HadoopExtensionResourceBundle .get(parser.getConfig().getLocale()).getString("path"); throw new ArgumentParserException( String.format(TextHelper.LOCALE_ROOT, MessageLocalization .localize(parser.getConfig().getResourceBundle(), "couldNotConvertToError"), value, localizedTypeName), e.getCause(), parser, arg); } return path; } }
@Override public Path convert(ArgumentParser parser, Argument arg, String value) throws ArgumentParserException { Path path; try { path = fileSystem.getPath(value); } catch (InvalidPathException e) { String localizedTypeName = Java7ExtensionResourceBundle .get(parser.getConfig().getLocale()).getString("path"); throw new ArgumentParserException( String.format(TextHelper.LOCALE_ROOT, MessageLocalization .localize(parser.getConfig().getResourceBundle(), "couldNotConvertToError"), value, localizedTypeName), e.getCause(), parser, arg); } try { File file = path.toFile(); if (!isSystemIn(value)) { firstFileVerification.verify(parser, arg, file); } } catch (UnsupportedOperationException e) { // Ignore: Not the default file system provider, so conversion to a // file is not possible. Simply skip the file verifications. } return path; }
private static String formatMessage(String message, Argument arg, ArgumentParserConfiguration config) { return String.format(Locale.ROOT, config.getResourceBundle().getString("argument"), arg.textualName(), message); }
private static String localizeTypeName(ArgumentParser parser, Class<?> type) { try { ResourceBundle typeBundle = ResourceBundle.getBundle( type.getName().replace('.', '/') + "-argparse4j"); return typeBundle.getString("displayName"); } catch (MissingResourceException e) { String simpleTypeName = type.getSimpleName(); return MessageLocalization.localize( parser.getConfig().getResourceBundle(), "type." + simpleTypeName, simpleTypeName); } } }
private static String localizeTypeName(ArgumentParser parser, Class<?> type) { try { ResourceBundle typeBundle = ResourceBundle.getBundle( type.getName().replace('.', '/') + "-argparse4j"); return typeBundle.getString("displayName"); } catch (MissingResourceException e) { String simpleTypeName = type.getSimpleName(); return MessageLocalization.localize( parser.getConfig().getResourceBundle(), "type." + simpleTypeName, simpleTypeName); } } }
@Override public T convert(ArgumentParser parser, Argument arg, String value) throws ArgumentParserException { for (T t : type_.getEnumConstants()) { if (t.toString().equals(value)) { return t; } } String choices = TextHelper.concat(type_.getEnumConstants(), 0, ",", "{", "}"); throw new ArgumentParserException(String.format(TextHelper.LOCALE_ROOT, MessageLocalization.localize( parser.getConfig().getResourceBundle(), "couldNotConvertChooseFromError"), value, choices), parser, arg); }
private void throwException(ArgumentParser parser, Argument arg, File file, String messageKey) throws ArgumentParserException { throw new ArgumentParserException( String.format(TextHelper.LOCALE_ROOT, MessageLocalization.localize( parser.getConfig().getResourceBundle(), messageKey), file), parser, arg); }
@Override public T convert(ArgumentParser parser, Argument arg, String value) throws ArgumentParserException { for (T t : type_.getEnumConstants()) { if (t.toString().equals(value)) { return t; } } String choices = TextHelper.concat(type_.getEnumConstants(), 0, ",", "{", "}"); throw new ArgumentParserException(String.format(TextHelper.LOCALE_ROOT, MessageLocalization.localize( parser.getConfig().getResourceBundle(), "couldNotConvertChooseFromError"), value, choices), parser, arg); }
private void throwException(ArgumentParser parser, Argument arg, File file, String messageKey) throws ArgumentParserException { throw new ArgumentParserException(String.format(TextHelper.LOCALE_ROOT, MessageLocalization .localize(parser.getConfig().getResourceBundle(), messageKey), file), parser, arg); }
@Override public Boolean convert(ArgumentParser parser, Argument arg, String value) throws ArgumentParserException { if (trueValue_.equals(value)) { return Boolean.TRUE; } if (falseValue_.equals(value)) { return Boolean.FALSE; } throw new ArgumentParserException(String.format(TextHelper.LOCALE_ROOT, MessageLocalization.localize( parser.getConfig().getResourceBundle(), "couldNotConvertChooseFromError"), value, inferMetavar()[0]), parser, arg); }
@Override public Boolean convert(ArgumentParser parser, Argument arg, String value) throws ArgumentParserException { if (trueValue_.equals(value)) { return Boolean.TRUE; } if (falseValue_.equals(value)) { return Boolean.FALSE; } throw new ArgumentParserException(String.format(TextHelper.LOCALE_ROOT, MessageLocalization.localize( parser.getConfig().getResourceBundle(), "couldNotConvertChooseFromError"), value, inferMetavar()[0]), parser, arg); }
@Override public T convert(ArgumentParser parser, Argument arg, String value) throws ArgumentParserException { try { return Enum.valueOf(type_, value); } catch (IllegalArgumentException e) { String choices = TextHelper.concat(type_.getEnumConstants(), 0, ",", "{", "}"); throw new ArgumentParserException( String.format(TextHelper.LOCALE_ROOT, MessageLocalization.localize( parser.getConfig().getResourceBundle(), "couldNotConvertChooseFromError"), value, choices), e, parser, arg); } }
@Override public T convert(ArgumentParser parser, Argument arg, String value) throws ArgumentParserException { try { return Enum.valueOf(type_, value); } catch (IllegalArgumentException e) { String choices = TextHelper.concat(type_.getEnumConstants(), 0, ",", "{", "}"); throw new ArgumentParserException( String.format(TextHelper.LOCALE_ROOT, MessageLocalization.localize( parser.getConfig().getResourceBundle(), "couldNotConvertChooseFromError"), value, choices), e, parser, arg); } }
private void throwArgumentParserException(ArgumentParser parser, Argument arg, String value, Throwable t) throws ArgumentParserException { String localizedTypeName = localizeTypeNameIfPossible(parser, type_); throw new ArgumentParserException(String.format(TextHelper.LOCALE_ROOT, MessageLocalization.localize( parser.getConfig().getResourceBundle(), "couldNotConvertToError"), value, localizedTypeName), t, parser, arg); }
private void throwArgumentParserException(ArgumentParser parser, Argument arg, String value, Throwable t) throws ArgumentParserException { String localizedTypeName = localizeTypeNameIfPossible(parser, type_); throw new ArgumentParserException(String.format(TextHelper.LOCALE_ROOT, MessageLocalization.localize( parser.getConfig().getResourceBundle(), "couldNotConvertToError"), value, localizedTypeName), t, parser, arg); }
@Override public T convert(ArgumentParser parser, Argument arg, String value) throws ArgumentParserException { T obj = null; try { obj = type_.getConstructor(String.class).newInstance(value); } catch (InstantiationException e) { handleInstantiationError(e); } catch (IllegalAccessException e) { handleInstantiationError(e); } catch (InvocationTargetException e) { String localizedTypeName = localizeTypeNameIfPossible(parser, type_); throw new ArgumentParserException( String.format(TextHelper.LOCALE_ROOT, MessageLocalization.localize( parser.getConfig().getResourceBundle(), "couldNotConvertToError"), value, localizedTypeName), e.getCause(), parser, arg); } catch (NoSuchMethodException e) { handleInstantiationError(e); } return obj; }
@Override public T convert(ArgumentParser parser, Argument arg, String value) throws ArgumentParserException { T obj = null; try { obj = type_.getConstructor(String.class).newInstance(value); } catch (InstantiationException e) { handleInstantiationError(e); } catch (IllegalAccessException e) { handleInstantiationError(e); } catch (InvocationTargetException e) { String localizedTypeName = localizeTypeNameIfPossible(parser, type_); throw new ArgumentParserException( String.format(TextHelper.LOCALE_ROOT, MessageLocalization.localize( parser.getConfig().getResourceBundle(), "couldNotConvertToError"), value, localizedTypeName), e.getCause(), parser, arg); } catch (NoSuchMethodException e) { handleInstantiationError(e); } return obj; }
String.format(TextHelper.LOCALE_ROOT, MessageLocalization.localize( parser.getConfig().getResourceBundle(), "couldNotConvertChooseFromError"), value, inferMetavar()[0]),
String.format(TextHelper.LOCALE_ROOT, MessageLocalization.localize( parser.getConfig().getResourceBundle(), "couldNotConvertChooseFromError"), value, inferMetavar()[0]),