branch<O extends OptionDefinition, T> static method
CommandImpl<O, T>
branch<O extends OptionDefinition, T>({
- required String name,
- required String description,
- String? category,
- String? invocation,
- String? summary,
- List<
String> ? aliases, - List<
String> ? suggestionAliases, - List<
CommandMiddleware< ? middlewares,O, T> > - List<
O> ? persistentOptions, - List<
Command< ? subcommands,OptionDefinition, T> > - bool canRunAsLeafCommand = false,
Creates a new branch command (i.e. a command with subcommands) via parameters rather than writing a class and overriding its fields.
If canRunAsLeafCommand is true, the command prints its usage when
it is the last command on the command line, like the command runner.
Implementation
static CommandImpl<O, T> branch<O extends OptionDefinition, T>({
required final String name,
required final String description,
final String? usageFooter,
final String? category,
final bool? hidden,
final String? invocation,
final String? summary,
final List<String>? aliases,
final List<String>? suggestionAliases,
final List<CommandMiddleware<O, T>>? middlewares,
final List<O>? persistentOptions,
final List<Command<OptionDefinition, T>>? subcommands,
final bool canRunAsLeafCommand = false,
}) {
return _CommandWithRunFunction(
name: name,
description: description,
usageFooter: usageFooter,
category: category,
hidden: hidden,
invocation: invocation,
summary: summary,
aliases: aliases,
suggestionAliases: suggestionAliases,
middlewares: middlewares,
persistentOptions: persistentOptions,
subcommands: subcommands,
canRunAsLeafCommand: canRunAsLeafCommand,
run: (final CommandContext<O, T> context) {
final command = context.command;
if (!command.canRunAsLeafCommand) {
throw UnsupportedError(
'Branch command ${command.name} should not be run()',
);
}
command.runner.usageOutput.printUsage(command);
return null;
},
);
}