fix: provide a better error message when option parsing fails (#27354)

closes: #16260

Signed-off-by: Steve Hawkins <shawkins@redhat.com>
This commit is contained in:
Steven Hawkins 2024-02-29 08:22:21 -05:00 committed by GitHub
parent 8d9439913c
commit 51590668f5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 12 additions and 2 deletions

View file

@ -70,8 +70,9 @@ class AeshConsoleCallbackImpl extends AeshConsoleCallback {
} catch (Exception e) { } catch (Exception e) {
console.stop(); console.stop();
if (e instanceof OptionParserException) { if (e instanceof OptionParserException && "Option: - must be followed by a valid operator".equals(e.getMessage())) {
System.err.println("Unknown command: " + aeshLine.getWords().get(0)); System.err.println("Please double check your command options, one or more of them are not specified correctly. "
+ "It is possible to have unintentional overlap with other options. e.g. using --clientid will get mistaken for --client, however --cclientid is needed.");
} else { } else {
System.err.println(e.getMessage()); System.err.println(e.getMessage());
} }

View file

@ -226,6 +226,15 @@ public class KcAdmTest extends AbstractAdmCliTest {
Assert.assertEquals("try help", "Try '" + CMD + " help set-password' for more information", exe.stderrLines().get(1)); Assert.assertEquals("try help", "Try '" + CMD + " help set-password' for more information", exe.stderrLines().get(1));
} }
@Test
public void testBadOverlappingOption() {
KcAdmExec exe = KcAdmExec.execute("config credentials --server http://localhost:8080 --realm master --username admin --password admin");
assertExitCodeAndStreamSizes(exe, 1, 0, 1);
Assert.assertEquals("stderr first line", "Please double check your command options, one or more of them are not specified correctly. "
+ "It is possible to have unintentional overlap with other options. e.g. using --clientid will get mistaken for --client, however --cclientid is needed.", exe.stderrLines().get(0));
}
@Test @Test
public void testCredentialsServerAndRealmWithDefaultConfig() { public void testCredentialsServerAndRealmWithDefaultConfig() {
/* /*