All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.greenpepper.util.cli.OptionBuilder Maven / Gradle / Ivy

There is a newer version: 4.2.4
Show newest version
/*
 * Copyright (c) 2007 Pyxis Technologies inc.
 *
 * This is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA,
 * or see the FSF site: http://www.fsf.org.
 */

package com.greenpepper.util.cli;

/**
 * 

OptionBuilder class.

* * @author oaouattara * @version $Id: $Id */ public class OptionBuilder { /** *

create.

* * @param name a {@link java.lang.String} object. * @return a {@link com.greenpepper.util.cli.OptionBuilder} object. */ public static OptionBuilder create( String name ) { return new OptionBuilder( name ); } private final Option option; /** *

Constructor for OptionBuilder.

* * @param name a {@link java.lang.String} object. */ public OptionBuilder( String name ) { option = new Option( name ); } /** *

wantsArgument.

* * @param value a {@link java.lang.String} object. * @return a {@link com.greenpepper.util.cli.OptionBuilder} object. */ public OptionBuilder wantsArgument( String value ) { if (option.wantsArg()) throw new IllegalArgumentException( "Argument pattern given twice" ); option.setArg( value ); return this; } /** *

withShortForm.

* * @param shortForm a {@link java.lang.String} object. * @return a {@link com.greenpepper.util.cli.OptionBuilder} object. */ public OptionBuilder withShortForm( String shortForm ) { if (option.getShortForm() != null) throw new IllegalArgumentException( "Short form given twice" ); option.setShortForm( shortForm ); return this; } /** *

withDescription.

* * @param text a {@link java.lang.String} object. * @return a {@link com.greenpepper.util.cli.OptionBuilder} object. */ public OptionBuilder withDescription( String text ) { if (option.getDescription() != null) throw new IllegalArgumentException( "Description given twice" ); option.setDescription( text ); return this; } /** *

withLongForm.

* * @param longForm a {@link java.lang.String} object. * @return a {@link com.greenpepper.util.cli.OptionBuilder} object. */ public OptionBuilder withLongForm( String longForm ) { if (option.getLongForm() != null) throw new IllegalArgumentException( "Long form given twice" ); option.setLongForm( longForm ); return this; } /** *

defaultingTo.

* * @param value a {@link java.lang.Object} object. * @return a {@link com.greenpepper.util.cli.OptionBuilder} object. */ public OptionBuilder defaultingTo( Object value ) { option.setValue( value ); return this; } /** *

asType.

* * @param type a {@link java.lang.Class} object. * @return a {@link com.greenpepper.util.cli.OptionBuilder} object. */ public OptionBuilder asType( Class type ) { return convertedWith( CommandLine.converterFor( type ) ); } /** *

convertedWith.

* * @param converter a {@link com.greenpepper.util.cli.Converter} object. * @return a {@link com.greenpepper.util.cli.OptionBuilder} object. */ public OptionBuilder convertedWith( Converter converter ) { option.setConverter( converter ); return this; } /** *

make.

* * @return a {@link com.greenpepper.util.cli.Option} object. */ public Option make() { if (!option.isValid()) throw new IllegalArgumentException( "no switch given" ); return option; } /** *

whenPresent.

* * @param stub a {@link com.greenpepper.util.cli.Option.Stub} object. * @return a {@link com.greenpepper.util.cli.OptionBuilder} object. */ public OptionBuilder whenPresent( Option.Stub stub ) { option.setStub( stub ); return this; } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy