001/******************************************************************************* 002 * Copyright (C) 2009-2011 FuseSource Corp. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the Eclipse Public License v1.0 006 * which accompanies this distribution, and is available at 007 * http://www.eclipse.org/legal/epl-v10.html 008 * 009 *******************************************************************************/ 010package org.fusesource.hawtjni.generator.util; 011 012import org.apache.commons.cli.Option; 013 014/** 015 * a better version of org.apache.commons.cli.OptionBuilder 016 * IDE provides nicer auto complete and less compiler warnings. 017 * 018 * @author <a href="http://hiramchirino.com">Hiram Chirino</a> 019 */ 020public class OptionBuilder { 021 022 private String id; 023 private String name; 024 private String description; 025 private boolean required; 026 private boolean optional; 027 private int args =-1; 028 private String arg; 029 private Object type; 030 private char sperator; 031 032 public static OptionBuilder ob() { 033 return new OptionBuilder(); 034 } 035 036 public Option op() { 037 Option option = new Option( id!=null ? id : " ", description ); 038 option.setLongOpt(name); 039 option.setRequired( required ); 040 option.setOptionalArg(optional); 041 option.setType( type ); 042 option.setValueSeparator(sperator); 043 if( arg !=null && args==-1 ) { 044 args=1; 045 } 046 option.setArgs(args); 047 option.setArgName(arg); 048 return option; 049 } 050 051 public OptionBuilder arg(String argName) { 052 this.arg = argName; 053 return this; 054 } 055 056 public OptionBuilder args(int args) { 057 this.args = args; 058 return this; 059 } 060 061 public OptionBuilder description(String description) { 062 this.description = description; 063 return this; 064 } 065 066 public OptionBuilder name(String lname) { 067 this.name = lname; 068 return this; 069 } 070 071 public OptionBuilder id(String name) { 072 this.id = name; 073 return this; 074 } 075 076 public OptionBuilder optional(boolean optional) { 077 this.optional = optional; 078 return this; 079 } 080 081 public OptionBuilder required(boolean required) { 082 this.required = required; 083 return this; 084 } 085 086 public OptionBuilder sperator(char sperator) { 087 this.sperator = sperator; 088 return this; 089 } 090 091 public OptionBuilder type(Object type) { 092 this.type = type; 093 return this; 094 } 095}