apps/src/main/java/com/sampullara/cli/Args.java
public static List<String> parse(Object target, String[] args) {
        List<String> arguments = new ArrayList<String>();
        arguments.addAll(Arrays.asList(args));
        Class<?> clazz;
        if (target instanceof Class) {
            clazz = (Class) target;
        } else {
            clazz = target.getClass();
            try {
                BeanInfo info = Introspector.getBeanInfo(clazz);
                for (PropertyDescriptor pd : info.getPropertyDescriptors()) {
                    processProperty(target, pd, arguments);
                }
            } catch (IntrospectionException e) {
                // If its not a JavaBean we ignore it
            }
        }

        // Check fields of 'target' class and its superclasses
      for (Class<?> currentClazz = clazz; currentClazz != null;  currentClazz = currentClazz.getSuperclass()) {
            for (Field field : currentClazz.getDeclaredFields()) {
                processField(target, field, arguments);
            }
        }

        for (String argument : arguments) {
            if (argument.startsWith("-")) {
                throw new IllegalArgumentException("Invalid argument: " + argument);
            }
        }
        return arguments;
    }
public static List<String> parse(Object target, String[] args) {
        List<String> arguments = new ArrayList<String>();
        arguments.addAll(Arrays.asList(args));
        Class<?> clazz;
        if (target instanceof Class) {
            clazz = (Class) target;
        } else {
            clazz = target.getClass();
            try {
                BeanInfo info = Introspector.getBeanInfo(clazz);
                for (PropertyDescriptor pd : info.getPropertyDescriptors()) {
                    processProperty(target, pd, arguments);
                }
            } catch (IntrospectionException e) {
                // If its not a JavaBean we ignore it
            }
        }

        // Check fields of 'target' class and its superclasses
      for (Class<?> currentClazz = clazz; currentClazz != null;  currentClazz = currentClazz.getSuperclass()) {
            for (Field field : currentClazz.getDeclaredFields()) {
                processField(target, field, arguments);
            }
        }

        for (String argument : arguments) {
            if (argument.startsWith("-")) {
                throw new IllegalArgumentException("Invalid argument: " + argument);
            }
        }
        return arguments;
    }
public static List < String > parse ( Object target , String [ ] args ) { List < String > arguments = new ArrayList < String > ( ) ; arguments . addAll ( Arrays . asList ( args ) ) ; Class < ? > clazz ; if ( target instanceof Class ) { clazz = ( Class ) target ; } else { clazz = target . getClass ( ) ; try { BeanInfo info = Introspector . getBeanInfo ( clazz ) ; for ( PropertyDescriptor pd : info . getPropertyDescriptors ( ) ) { processProperty ( target , pd , arguments ) ; } } catch ( IntrospectionException e ) { // If its not a JavaBean we ignore it } } // Check fields of 'target' class and its superclasses for ( Class < ? > currentClazz = clazz ; currentClazz != null ; currentClazz = currentClazz . getSuperclass ( ) ) { for ( Field field : currentClazz . getDeclaredFields ( ) ) { processField ( target , field , arguments ) ; } } for ( String argument : arguments ) { if ( argument . startsWith ( "-" ) ) { throw new IllegalArgumentException ( "Invalid argument: " + argument ) ; } } return arguments ; }
Parse a set of arguments and populate the target with the appropriate values.

@param target Either an instance or a class
@param args   The arguments you want to parse and populate
@return The list of arguments that were not consumed
Parse a set of arguments and populate the target with the appropriate values .