Parser configuration for convenience methods
See original GitHub issueThe convenience methods CommandLine::run
and CommandLine::call
don’t allow for the parser to be configured.
Applications that need to parse with non-default parser settings can only use CommandLine::parseWithHandlers
, which is more verbose and less readable.
See #556 for an example.
One idea is to introduce overloaded CommandLine::run
and CommandLine::call
methods that take a ParserSpec
parameter used to config the parser.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:3
- Comments:7 (6 by maintainers)
Top Results From Across the Web
XNI Parser Configuration - Apache Xerces
Parser configurations built using the Xerces Native Interface are made from a series of parser components. This document details the XNI API for...
Read more >configparser — Configuration file parser — Python 3.11.1 ...
A convenience method which coerces the option in the specified section to a floating point number. See get() for explanation of raw, vars...
Read more >Class Parser - Chevrotain
A data structure containing all the Tokens used by the Parser. Optional config: IParserConfig. The Parser's configuration. Returns Parser ...
Read more >Writing Parser Extensions - GitHub Pages
Implementing a custom parser is one of two possible ways to extend the syntax of a ... Directives and in many cases that...
Read more >YangParserTestUtils (yangtools-docs 7.0.3 API) - javadoc.io
Utility class which provides convenience methods for producing effective schema ... Parameters: config - parser configuration: files - YANG files to be ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Initial version just landed in master.
Jotting down some notes on the subject of exit codes for picocli 4.0:
Spring Boot
Spring Boot has some good ideas for handling exit codes:
System.exit
itself, it just provides an API that returns anint
. It is up to the application to callSystem.exit
with that value.ExitCodeGenerator
. This solves the problem of deeply nested methods needing to return an exit code: there is no need to propagate this value through the call stack any more.ExitCodeExceptionMapper
interface that maps Exceptions to an exit code. Implementors can inspect details of the Exception object before deciding what exit code to return.Current implementation (picocli 3.x)
IResultHandler::andExit(int)
andIExceptionHandler::andExit(int)
methods that do callSystem.exit
- deprecate this in picocli 4.0: these methods are hard to find, are not flexible enough to cover many use cases, and in general we should avoid callingSystem.exit
in the library.Goals
Documentation
When generating
man
page documentation (#299, #459), it would be nice to be able to include a section listing theEXIT STATUS
values of the command (like man’s man page). This would require picocli to know all exit codes and their description.Dynamic Exit Status section
If any exit code is defined, picocli could automatically insert help section keys
SECTION_KEY_EXIT_STATUS_HEADING, SECTION_KEY_EXIT_STATUS
beforeSECTION_KEY_FOOTER_HEADING
, and put aIHelpSectionRenderer
in the help section map that prints a list of the registered exit codes and their description.Execution
Add a new
execute
method toCommandLine
(or a subclassExecutable
?) that invokes theRunnable
,Callable
orMethod
and returns the exit code. This makes the application responsible for callingSystem.exit
:This
execute
method should delegate to theIParseResultHandler2
andIExceptionHandler2
(but would ignore their return value). Applications may customize runtime behaviour by supplying their own handlers, BUT custom handlers should really extendAbstractHandler
so picocli can pass them the configured color scheme and OUT and ERR streams.Exception handling
The
execute
method would delegate error handling to theIExceptionHandler2
, but an exception handler implementation may rethrow an exception, or extract the cause exception and rethrow that. If any exit codes are configured, theexecute
method should catch all exceptions, print their stack trace, and then return the appropriate error code.Implementation
Miscellaneous
AbstractParseResultHandler
needs an alternative forhandleParseResult
that takes a ColorScheme.