001/*
002 * ============================================================================
003 * Copyright © 2002-2023 by Thomas Thrien.
004 * All Rights Reserved.
005 * ============================================================================
006 * Licensed to the public under the agreements of the GNU Lesser General Public
007 * License, version 3.0 (the "License"). You may obtain a copy of the License at
008 *
009 *      http://www.gnu.org/licenses/lgpl.html
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
013 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
014 * License for the specific language governing permissions and limitations
015 * under the License.
016 */
017
018package org.tquadrat.foundation.config.spi;
019
020import static org.apiguardian.api.API.Status.STABLE;
021import static org.tquadrat.foundation.lang.Objects.requireNotEmptyArgument;
022
023import org.apiguardian.api.API;
024import org.tquadrat.foundation.annotation.ClassVersion;
025import org.tquadrat.foundation.config.Argument;
026import org.tquadrat.foundation.config.cli.CmdLineValueHandler;
027
028/**
029 *  Run-time copy of the
030 *  {@link Argument @Argument}
031 *  annotation. By definition, unnamed options are arguments (and instances of
032 *  this class). Named options are actually another subclass
033 *  of
034 *  {@link CLIDefinition}.
035 *
036 *  @see CLIOptionDefinition
037 *
038 *  @extauthor Thomas Thrien - thomas.thrien@tquadrat.org
039 *  @thanks Mark Sinke
040 *  @version $Id: CLIArgumentDefinition.java 1076 2023-10-03 18:36:07Z tquadrat $
041 *  @since 0.0.1
042 *
043 *  @UMLGraph.link
044 */
045@ClassVersion( sourceVersion = "$Id: CLIArgumentDefinition.java 1076 2023-10-03 18:36:07Z tquadrat $" )
046@API( status = STABLE, since = "0.0.1" )
047public class CLIArgumentDefinition extends CLIDefinition
048{
049        /*------------*\
050    ====** Attributes **=======================================================
051        \*------------*/
052    /**
053     *  The index; only used for arguments (not for options).
054     */
055    private final int m_Index;
056
057        /*--------------*\
058    ====** Constructors **=====================================================
059        \*--------------*/
060    /**
061     *  Creates a new {@code CLIArgumentDefinition} instance.
062     *
063     *  @param  property    The name of the property.
064     *  @param  index   The position for this argument on the command line.
065     *  @param  usage   The usage text.
066     *  @param  usageKey    The resource bundle key for the usage text.
067     *  @param  metaVar The meta variable name.
068     *  @param  required    {@code true} if the argument or option is
069     *      mandatory.
070     *  @param  handler The handler for the option or argument value.
071     *  @param  multiValued {@code true} if the option or argument allows
072     *      more than one value.
073     *  @param  format  The optional format.
074     */
075    @SuppressWarnings( {"BooleanParameter", "ConstructorWithTooManyParameters"} )
076    public CLIArgumentDefinition( final String property, final int index, final String usage, final String usageKey, final String metaVar, final boolean required, final CmdLineValueHandler<?> handler, final boolean multiValued, final String format )
077    {
078        super( property, true, usage, usageKey, requireNotEmptyArgument( metaVar, "metaVar" ), required, handler, multiValued, format );
079        m_Index = index;
080    }   //  CLIArgumentDefinition()
081
082        /*---------*\
083    ====** Methods **==========================================================
084        \*---------*/
085    /**
086     *  {@inheritDoc}
087     */
088    @Override
089    public final String getSortKey() { return Integer.toString( m_Index ); }
090
091    /**
092     *  Returns the index of this argument.
093     *
094     *  @return The index.
095     */
096    public final int index() { return m_Index; }
097
098    /**
099     *  {@inheritDoc}
100     */
101    @Override
102    public final String toString() { return String.format( required() ? "%s" : "[%s]", metaVar() ); }
103}
104//  class CLIArgumentDefinition
105
106/*
107 *  End of File
108 */