Backend API. Server-side code: this runs in a Codename One backend, not in the app on the device.

public final class CommandSpec

  1. Object
  2. CommandSpec

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.

Constructors

public CommandSpec(String name, String[] description, String[] version, boolean standardHelpOptions, CommandBinding binding)Creates the model of a command.

Methods

public CommandSpec addOption(OptionSpec option)Adds an option, and answers this spec.
public CommandSpec addPositional(PositionalParamSpec positional)Adds a positional parameter, and answers this spec.
public CommandSpec addSubcommand(CommandSpec sub)Adds a subcommand, and answers this spec.
public CommandSpec aliases(String... names)Sets the other names the command answers to, and answers this spec.
public String name()The name the command is invoked by.
public String[] aliases()The other names the command answers to.
public String qualifiedName()The name with the names of every enclosing command before it, as the usage line prints it: git remote add.
public String[] description()The lines of help text.
public String[] version()The lines --version prints.
public boolean standardHelpOptions()Whether -h/--help and -V/--version are recognized.
public List<OptionSpec> options()The options, in declaration order.
public List<PositionalParamSpec> positionals()The positional parameters, in declaration order.
public List<CommandSpec> subcommands()The subcommands, in declaration order.
public CommandSpec parent()The enclosing command, or null for the top level.
public CommandBinding binding()The generated code behind this command, or null for a group of subcommands with no body of its own.
public CommandSpec subcommand(String token)The subcommand invoked by token, by name or alias, or null.

Inherited methods

Constructor details

CommandSpec

public CommandSpec(String name, String[] description, String[] version, boolean standardHelpOptions, CommandBinding binding)
Creates the model of a command.

Parameters

name String
the name the command is invoked by
description String[]
the lines of help text printed under the usage line
version String[]
the lines --version prints, or an empty array
standardHelpOptions boolean
whether -h/--help and -V/--version are added
binding CommandBinding
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.