java.lang.Object
dev.metaschema.cli.processor.CallingContext
Records information about the command line options and called command
hierarchy.
-
Method Summary
Modifier and TypeMethodDescriptionprotected voidapplyGlobalOptions(org.apache.commons.cli.CommandLine cmdLine) Apply global options like --no-color and --quiet.protected Optional<ExitStatus>Check for --help and --version options before full parsing.Get the command line processor instance that generated this calling context.Get the command that was triggered by the CLI arguments.handleError(ExitStatus exitStatus, org.apache.commons.cli.CommandLine cmdLine, boolean showHelp) Handle an error that occurred while executing the command.handleInvalidCommand(String message) Generate the help message and exit status for an invalid command using the provided message.protected org.apache.commons.cli.CommandLineParse all command line options.Process the command identified by the CLI arguments.voidshowHelp()Output the help text to the console.protected Optional<ExitStatus>validateCalledCommands(org.apache.commons.cli.CommandLine cmdLine) Validate options for all called commands in the chain.protected Optional<ExitStatus>validateExtraArguments(org.apache.commons.cli.CommandLine cmdLine) Validate extra arguments for the target command.
-
Method Details
-
getCLIProcessor
Get the command line processor instance that generated this calling context.- Returns:
- the instance
-
getTargetCommand
Get the command that was triggered by the CLI arguments.- Returns:
- the command or
nullif no command was triggered
-
checkHelpAndVersion
Check for --help and --version options before full parsing.This is phase 1 of command processing.
- Returns:
- an exit status if help or version was requested, or empty to continue
-
parseOptions
@NonNull protected org.apache.commons.cli.CommandLine parseOptions() throws org.apache.commons.cli.ParseExceptionParse all command line options.This is phase 2 of command processing.
- Returns:
- the parsed command line
- Throws:
org.apache.commons.cli.ParseException- if parsing fails
-
validateExtraArguments
@NonNull protected Optional<ExitStatus> validateExtraArguments(@NonNull org.apache.commons.cli.CommandLine cmdLine) Validate extra arguments for the target command.This is phase 3 of command processing.
- Parameters:
cmdLine- the parsed command line- Returns:
- an exit status if validation failed, or empty to continue
-
validateCalledCommands
@NonNull protected Optional<ExitStatus> validateCalledCommands(@NonNull org.apache.commons.cli.CommandLine cmdLine) Validate options for all called commands in the chain.This is phase 4 of command processing.
- Parameters:
cmdLine- the parsed command line- Returns:
- an exit status if validation failed, or empty to continue
-
applyGlobalOptions
protected void applyGlobalOptions(@NonNull org.apache.commons.cli.CommandLine cmdLine) Apply global options like --no-color and --quiet.This is phase 5 of command processing.
- Parameters:
cmdLine- the parsed command line
-
processCommand
Process the command identified by the CLI arguments.- Returns:
- the result of processing the command
-
handleError
@NonNull public ExitStatus handleError(@NonNull ExitStatus exitStatus, @NonNull org.apache.commons.cli.CommandLine cmdLine, boolean showHelp) Handle an error that occurred while executing the command.- Parameters:
exitStatus- the execution resultcmdLine- the command line informationshowHelp- iftrueshow the help information- Returns:
- the resulting exit status
-
handleInvalidCommand
Generate the help message and exit status for an invalid command using the provided message.- Parameters:
message- the error message- Returns:
- the resulting exit status
-
showHelp
public void showHelp()Output the help text to the console.- Throws:
UncheckedIOException- if an error occurs while writing help output
-