printException method
void
printException(
- UsageException exception, {
- required UsageOutputHandler usageOutput,
- CommandDefinition<
OptionDefinition> ? fromCommand,
override
Prints a usage exception to OutputSinks.err.
If exception is a CommandUsageException (this is the expected normal
case), the usage for its command is printed.
If it is not, the usage field of the UsageException is printed,
along with the fromCommand usage if provided.
In other words fromCommand is only used as a fallback if the exception
is not a CommandUsageException.
Implementation
@override
void printException(
final UsageException exception, {
required final UsageOutputHandler usageOutput,
final CommandDefinition? fromCommand,
}) {
usageOutput.sinks.err.writeln(exception.message);
usageOutput.sinks.err.writeln('');
if (exception is CommandUsageException) {
usageOutput.printUsage(
exception.command,
sink: usageOutput.sinks.err,
);
} else {
if (exception.usage.isNotEmpty) {
usageOutput.sinks.err.writeln(exception.usage);
}
if (fromCommand != null) {
if (exception.usage.isNotEmpty) usageOutput.sinks.err.writeln('---');
usageOutput.printUsage(fromCommand, sink: usageOutput.sinks.err);
}
}
}