001/* 002 * SPDX-FileCopyrightText: none 003 * SPDX-License-Identifier: CC0-1.0 004 */ 005 006package dev.metaschema.cli.processor.command.impl; 007 008import dev.metaschema.cli.processor.command.ExtraArgument; 009import edu.umd.cs.findbugs.annotations.NonNull; 010import edu.umd.cs.findbugs.annotations.Nullable; 011 012/** 013 * A default implementation of the {@link ExtraArgument} interface that 014 * represents a named command-line argument which can be marked as required or 015 * optional. 016 * <p> 017 * This implementation is used by the command processor to handle additional 018 * arguments that are not covered by specific command options. 019 */ 020public class DefaultExtraArgument implements ExtraArgument { 021 private final String name; 022 private final boolean required; 023 @Nullable 024 private final Class<?> type; 025 026 /** 027 * Construct a new instance. 028 * 029 * @param name 030 * the argument name 031 * @param required 032 * {@code true} if the argument is required, or {@code false} otherwise 033 */ 034 public DefaultExtraArgument(@NonNull String name, boolean required) { 035 this(name, required, null); 036 } 037 038 /** 039 * Construct a new instance with type information for shell completion. 040 * 041 * @param name 042 * the argument name 043 * @param required 044 * {@code true} if the argument is required, or {@code false} otherwise 045 * @param type 046 * the type class for completion lookup, or {@code null} for freeform 047 * input 048 */ 049 public DefaultExtraArgument(@NonNull String name, boolean required, @Nullable Class<?> type) { 050 this.name = name; 051 this.required = required; 052 this.type = type; 053 } 054 055 @Override 056 public String getName() { 057 return name; 058 } 059 060 @Override 061 public boolean isRequired() { 062 return required; 063 } 064 065 @Override 066 @Nullable 067 public Class<?> getType() { 068 return type; 069 } 070}