Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unable to directly handle unknown commands in console #653

Closed
aappddeevv opened this issue Feb 21, 2021 · 2 comments
Closed

unable to directly handle unknown commands in console #653

aappddeevv opened this issue Feb 21, 2021 · 2 comments
Milestone

Comments

@aappddeevv
Copy link

aappddeevv commented Feb 21, 2021

There is no way to definitely say, other than parsing a string, whether a command was not recognized in jline.console.

UnknownCommandException is not public, hence, the best catch you can have is Exception. But then you have to check the string for "unknown" in it. It would be nice to have that public or have a method that helps you determine when a command was not recognized in the registry. Handling an unknown command is probably not a registry specific function but could be owned by the outer layer. To be consistent with parts of jline.console, perhaps the UnknowCommandException needs to be public.

@mattirn
Copy link
Collaborator

mattirn commented Feb 22, 2021

SystemRegistryImpl can be used: 1) without scripting support and 2) with scripting support (using ConsoleEngine/ScriptEngine implementations). In a latter case UnknowCommandException will be handled internally in SystemRegistryImpl and it is never thrown outside.

When you use SystemRegistryImpl without scripting support you can test whether the command is known as

String line = reader.readLine("prompt> ");
if (systemRegistry.hasCommand(parser.getCommand(line))) {
    systemRegistry.execute(line);
}

where systemRegistry and parser are instances of SystemRegistryImpl and DefaultParser.

@mattirn mattirn added this to the 3.19.1 milestone Feb 22, 2021
@aappddeevv
Copy link
Author

Thanks!

@mattirn mattirn mentioned this issue Apr 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants