Class CommandSpec

java.lang.Object
com.codename1.cli.CommandSpec

public final class CommandSpec extends Object

The model of one command: its name, help text, options, positional parameters and subcommands.

The build writes one for every @Command class from its annotations, so an application normally never constructs one. A command can receive its own through a field annotated CommandLine.Spec, to print its usage or read the name it was invoked by.

  • Constructor Details

    • CommandSpec

      public CommandSpec(String name, String[] description, String[] version, boolean standardHelpOptions, CommandBinding binding)

      Creates the model of a command.

      Parameters
      • name: the name the command is invoked by

      • description: the lines of help text printed under the usage line

      • version: the lines --version prints, or an empty array

      • standardHelpOptions: whether -h/--help and -V/--version are added

      • binding: the generated code that creates and runs the command, or null for a group that only holds subcommands

  • Method Details

    • addOption

      public CommandSpec addOption(OptionSpec option)
      Adds an option, and answers this spec.
    • addPositional

      public CommandSpec addPositional(PositionalParamSpec positional)
      Adds a positional parameter, and answers this spec.
    • addSubcommand

      public CommandSpec addSubcommand(CommandSpec sub)
      Adds a subcommand, and answers this spec.
    • aliases

      public CommandSpec aliases(String... names)
      Sets the other names the command answers to, and answers this spec.
    • name

      public String name()
      The name the command is invoked by.
    • aliases

      public String[] aliases()
      The other names the command answers to.
    • qualifiedName

      public String qualifiedName()
      The name with the names of every enclosing command before it, as the usage line prints it: git remote add.
    • description

      public String[] description()
      The lines of help text.
    • version

      public String[] version()
      The lines --version prints. A subcommand with none inherits its parent's.
    • standardHelpOptions

      public boolean standardHelpOptions()
      Whether -h/--help and -V/--version are recognized.
    • options

      public List<OptionSpec> options()
      The options, in declaration order.
    • positionals

      public List<PositionalParamSpec> positionals()
      The positional parameters, in declaration order.
    • subcommands

      public List<CommandSpec> subcommands()
      The subcommands, in declaration order.
    • parent

      public CommandSpec parent()
      The enclosing command, or null for the top level.
    • binding

      public CommandBinding binding()
      The generated code behind this command, or null for a group of subcommands with no body of its own.
    • subcommand

      public CommandSpec subcommand(String token)
      The subcommand invoked by token, by name or alias, or null.