1   /*
2    * SPDX-FileCopyrightText: none
3    * SPDX-License-Identifier: CC0-1.0
4    */
5   
6   package dev.metaschema.cli.processor.command.impl;
7   
8   import dev.metaschema.cli.processor.command.ExtraArgument;
9   import edu.umd.cs.findbugs.annotations.NonNull;
10  import edu.umd.cs.findbugs.annotations.Nullable;
11  
12  /**
13   * A default implementation of the {@link ExtraArgument} interface that
14   * represents a named command-line argument which can be marked as required or
15   * optional.
16   * <p>
17   * This implementation is used by the command processor to handle additional
18   * arguments that are not covered by specific command options.
19   */
20  public class DefaultExtraArgument implements ExtraArgument {
21    private final String name;
22    private final boolean required;
23    @Nullable
24    private final Class<?> type;
25  
26    /**
27     * Construct a new instance.
28     *
29     * @param name
30     *          the argument name
31     * @param required
32     *          {@code true} if the argument is required, or {@code false} otherwise
33     */
34    public DefaultExtraArgument(@NonNull String name, boolean required) {
35      this(name, required, null);
36    }
37  
38    /**
39     * Construct a new instance with type information for shell completion.
40     *
41     * @param name
42     *          the argument name
43     * @param required
44     *          {@code true} if the argument is required, or {@code false} otherwise
45     * @param type
46     *          the type class for completion lookup, or {@code null} for freeform
47     *          input
48     */
49    public DefaultExtraArgument(@NonNull String name, boolean required, @Nullable Class<?> type) {
50      this.name = name;
51      this.required = required;
52      this.type = type;
53    }
54  
55    @Override
56    public String getName() {
57      return name;
58    }
59  
60    @Override
61    public boolean isRequired() {
62      return required;
63    }
64  
65    @Override
66    @Nullable
67    public Class<?> getType() {
68      return type;
69    }
70  }