com.sampullara.cli.Argument.required()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(4.8k)|赞(0)|评价(0)|浏览(105)

本文整理了Java中com.sampullara.cli.Argument.required()方法的一些代码示例,展示了Argument.required()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Argument.required()方法的具体详情如下:
包路径:com.sampullara.cli.Argument
类名称:Argument
方法名:required

Argument.required介绍

暂无

代码示例

代码示例来源:origin: spullara/cli-parser

private static void processField(Object target, Field field, Properties arguments) {
  Argument argument = field.getAnnotation(Argument.class);
  if (argument != null) {
    String name = Args.getName(argument, field);
    String alias = Args.getAlias(argument);
    Class type = field.getType();
    Object value = arguments.get(name);
    if (value == null && alias != null) {
      value = arguments.get(alias);
    }
    if (value != null) {
      if (type == Boolean.TYPE || type == Boolean.class) {
        value = true;
      }
      Args.setField(type, field, target, value, argument.delimiter());
    } else {
      if (argument.required()) {
        throw new IllegalArgumentException("You must set argument " + name);
      }
    }
  }
}

代码示例来源:origin: com.github.spullara.cli-parser/cli-parser

private static void processField(Object target, Field field, Properties arguments) {
  Argument argument = field.getAnnotation(Argument.class);
  if (argument != null) {
    String name = Args.getName(argument, field);
    String alias = Args.getAlias(argument);
    Class type = field.getType();
    Object value = arguments.get(name);
    if (value == null && alias != null) {
      value = arguments.get(alias);
    }
    if (value != null) {
      if (type == Boolean.TYPE || type == Boolean.class) {
        value = true;
      }
      Args.setField(type, field, target, value, argument.delimiter());
    } else {
      if (argument.required()) {
        throw new IllegalArgumentException("You must set argument " + name);
      }
    }
  }
}

代码示例来源:origin: com.github.spullara.cli-parser/cli-parser

private static void processProperty(Object target, PropertyDescriptor property, Properties arguments) {
    Method writeMethod = property.getWriteMethod();
    if (writeMethod != null) {
      Argument argument = writeMethod.getAnnotation(Argument.class);
      if (argument != null) {
        String name = Args.getName(argument, property);
        String alias = Args.getAlias(argument);
        Object value = arguments.get(name);
        if (value == null && alias != null) {
          value = arguments.get(alias);
        }
        if (value != null) {
          Class type = property.getPropertyType();
          if (type == Boolean.TYPE || type == Boolean.class) {
            value = true;
          }
          Args.setProperty(type, property, target, value, argument.delimiter());
        } else {
          if (argument.required()) {
            throw new IllegalArgumentException("You must set argument " + name);
          }
        }
      }
    }
  }
}

代码示例来源:origin: spullara/cli-parser

private static void processProperty(Object target, PropertyDescriptor property, Properties arguments) {
    Method writeMethod = property.getWriteMethod();
    if (writeMethod != null) {
      Argument argument = writeMethod.getAnnotation(Argument.class);
      if (argument != null) {
        String name = Args.getName(argument, property);
        String alias = Args.getAlias(argument);
        Object value = arguments.get(name);
        if (value == null && alias != null) {
          value = arguments.get(alias);
        }
        if (value != null) {
          Class type = property.getPropertyType();
          if (type == Boolean.TYPE || type == Boolean.class) {
            value = true;
          }
          Args.setProperty(type, property, target, value, argument.delimiter());
        } else {
          if (argument.required()) {
            throw new IllegalArgumentException("You must set argument " + name);
          }
        }
      }
    }
  }
}

代码示例来源:origin: com.google.code.cli-parser/cli

private static void processField(Object target, Field field, List<String> arguments) {
  Argument argument = field.getAnnotation(Argument.class);
  if (argument != null) {
    boolean set = false;
    for (Iterator<String> i = arguments.iterator(); i.hasNext();) {
      String arg = i.next();
      String prefix = argument.prefix();
      String delimiter = argument.delimiter();
      if (arg.startsWith(prefix)) {
        Object value;
        String name = getName(argument, field);
        String alias = getAlias(argument);
        arg = arg.substring(prefix.length());
        if (arg.equals(name) || (alias != null && arg.equals(alias))) {
          i.remove();
          Class type = field.getType();
          value = consumeArgumentValue(type, argument, i);
          setField(type, field, target, value, delimiter);
          set = true;
        }
        if (set) break;
      }
    }
    if (!set && argument.required()) {
      throw new IllegalArgumentException("You must set argument " + argument.value());
    }
  }
}

代码示例来源:origin: com.google.code.cli-parser/cli

if (!set && argument.required()) {
  throw new IllegalArgumentException("You must set argument " + argument.value());

代码示例来源:origin: com.github.spullara.cli-parser/cli-parser

if (!set && argument.required()) {
  String name = getName(argument, property);
  throw new IllegalArgumentException("You must set argument " + name);

代码示例来源:origin: spullara/cli-parser

if (!set && argument.required()) {
  String name = getName(argument, field);
  throw new IllegalArgumentException("You must set argument " + name);

代码示例来源:origin: spullara/cli-parser

if (!set && argument.required()) {
  String name = getName(argument, property);
  throw new IllegalArgumentException("You must set argument " + name);

代码示例来源:origin: com.github.spullara.cli-parser/cli-parser

if (!set && argument.required()) {
  String name = getName(argument, field);
  throw new IllegalArgumentException("You must set argument " + name);

相关文章