/*
 * @(#)PairOption.java
 *
 * Copyright (c) 2002-2003 JSCAPE
 * 1147 S. 53rd Pl., Mesa, Arizona, 85206, U.S.A.
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * JSCAPE. ("Confidential Information").  You shall not disclose such
 * Confidential Information and shall use it only in accordance with
 * the terms of the license agreement you entered into with JSCAPE.
 */

package com.jscape.util.cli;

import com.jscape.util.Assert;
import com.jscape.util.ListIterator;

/**
 * @author Alex
 * @version 1.0
 * @see <a href="PairOption.java.html">Source code</a>
 */
public class PairOption
        extends AbstractOption {

    private String parameter;

    public PairOption(String name, boolean required, int position) {
        this(name, "", required, position);
    }

    public PairOption(String name, String parameter, boolean required, int position) {
        super(name, required, position);
        Assert.notNull(parameter);
        this.parameter = parameter;
    }

    public String getParameter() {
        return this.parameter;
    }

    protected String getOptionString() {
        return (this.name + " " + OPEN_PARAMETER_BRACE + this.parameter + CLOSE_PARAMETER_BRACE);
    }

    protected String optionFound(Argument option, ListIterator i) {
        super.optionFound(option, i);
        Argument value = (Argument) i.next();
        Assert.isFalse(value.parsed, "Missing option value.");
        value.parsed = true;

        return value.value;
    }

}
