Martin Peřina has posted comments on this change. Change subject: uutils: added new cli parser ......................................................................
Patch Set 12: (9 comments) https://gerrit.ovirt.org/#/c/40157/12/backend/manager/modules/uutils/src/main/java/org/ovirt/engine/core/uutils/cli/parser/Argument.java File backend/manager/modules/uutils/src/main/java/org/ovirt/engine/core/uutils/cli/parser/Argument.java: Line 9: private String help; Line 10: private String defaultValue; Line 11: private Type type; Line 12: private Pattern matcher; Line 13: private Class<?> convert; I would prefer destinationType or valueType instead of convert as it much clearly describes the meaning. Line 14: private boolean mandatory; Line 15: private String metavar; Line 16: private boolean multivalue; Line 17: private String value; Line 15: private String metavar; Line 16: private boolean multivalue; Line 17: private String value; Line 18: Line 19: enum Type { I would prefer ValueRequirement instead of Type as it much more clearly describes what it is about Line 20: HAS_ARGUMENT, Line 21: OPTIONAL_ARGUMENT, Line 22: NO_ARGUMENT; Line 23: Line 20: HAS_ARGUMENT, Line 21: OPTIONAL_ARGUMENT, Line 22: NO_ARGUMENT; Line 23: Line 24: public static Type valueOfIgnoreCase(String name) { Why not reuse existing? public static Type valueOfIgnoreCase(String name) { if (name != null) { return valueOf(name.toUpperCase()); } throw new IllegalArgumentException("Invalid value null"); } Line 25: for (Type type : values()) { Line 26: if (name.equalsIgnoreCase(type.name())) { Line 27: return type; Line 28: } https://gerrit.ovirt.org/#/c/40157/12/backend/manager/modules/uutils/src/main/java/org/ovirt/engine/core/uutils/cli/parser/ArgumentsParser.java File backend/manager/modules/uutils/src/main/java/org/ovirt/engine/core/uutils/cli/parser/ArgumentsParser.java: Line 152: Line 153: /** Line 154: * Map which stores parsed converted arguments. Line 155: */ Line 156: private Map<String, Argument> arguments = new HashMap<>(); Please always initialize instance attributes in constructor Line 157: Line 158: /** Line 159: * Set of mandatory arguments to check if user specified all of them. Line 160: */ Line 157: Line 158: /** Line 159: * Set of mandatory arguments to check if user specified all of them. Line 160: */ Line 161: private Set<String> mandatory = new HashSet<>(); Please always initialize instance attributes in constructor Line 162: Line 163: /** Line 164: * Map of correctly parsed and converted arguments Line 165: */ Line 162: Line 163: /** Line 164: * Map of correctly parsed and converted arguments Line 165: */ Line 166: private Map<String, Object> parsedArgs = null; Please remove null assignment, it's the default Line 167: Line 168: /** Line 169: * List of errors which was found during pasring Line 170: */ Line 167: Line 168: /** Line 169: * List of errors which was found during pasring Line 170: */ Line 171: private List<Throwable> errors = null; Please remove null assignment, it's the default Line 172: Line 173: /** Line 174: * Inititilize ArgumentsParser attributes. Parser properties file and create argument map of it. Line 175: * Line 221: public boolean parse(List<String> args) { Line 222: parsedArgs = new HashMap<>(); Line 223: errors = new ArrayList<>(); Line 224: Line 225: while(!args.isEmpty()) { Usually it's a bad behavior to modify Collection provided by caller. Wouldn't it be better to reimplement it without modification of args? Line 226: String arg = args.get(0); Line 227: if(!arg.startsWith(LONG_PREFIX)) { Line 228: break; Line 229: } Line 246: value == null && Line 247: ( Line 248: argument.getType() == Argument.Type.OPTIONAL_ARGUMENT || Line 249: argument.getType() == Argument.Type.HAS_ARGUMENT Line 250: ) I would still prefer this condition: if (value == null && argument.getType() != Argument.Type.NO_ARGUMENT) { IMO it's much more readable Line 251: ) { Line 252: if(args.size() > 0) { Line 253: value = args.get(0); Line 254: if (value.startsWith(LONG_PREFIX)) { -- To view, visit https://gerrit.ovirt.org/40157 To unsubscribe, visit https://gerrit.ovirt.org/settings Gerrit-MessageType: comment Gerrit-Change-Id: I00042b669e19293641579582223e7ca40717132d Gerrit-PatchSet: 12 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Ondra Machacek <omach...@redhat.com> Gerrit-Reviewer: Alon Bar-Lev <alo...@redhat.com> Gerrit-Reviewer: Jenkins CI Gerrit-Reviewer: Martin Peřina <mper...@redhat.com> Gerrit-Reviewer: Mooli Tayer <mta...@redhat.com> Gerrit-Reviewer: Ondra Machacek <omach...@redhat.com> Gerrit-Reviewer: Oved Ourfali <oourf...@redhat.com> Gerrit-Reviewer: automat...@ovirt.org Gerrit-Reviewer: mooli tayer <mta...@redhat.com> Gerrit-HasComments: Yes _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches