-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[cli] better format errors in case of a missing required parameter
- Loading branch information
1 parent
269f020
commit adda1f7
Showing
4 changed files
with
99 additions
and
8 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
.../java/io/yupiik/fusion/framework/api/configuration/MissingRequiredParameterException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* Copyright (c) 2022 - present - Yupiik SAS - https://www.yupiik.com | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package io.yupiik.fusion.framework.api.configuration; | ||
|
||
public class MissingRequiredParameterException extends IllegalArgumentException { | ||
public MissingRequiredParameterException(final String msg) { | ||
super(msg); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
fusion-cli/src/test/java/io/yupiik/fusion/cli/internal/BaseCliCommandTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* Copyright (c) 2022 - present - Yupiik SAS - https://www.yupiik.com | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package io.yupiik.fusion.cli.internal; | ||
|
||
import io.yupiik.fusion.framework.api.configuration.MissingRequiredParameterException; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
||
class BaseCliCommandTest { | ||
@Test | ||
void errorMessage() { | ||
assertEquals( | ||
""" | ||
No value for '--test-dummy' | ||
Available parameters: | ||
--test-dummy: Some param. | ||
""", | ||
assertThrows(IllegalArgumentException.class, () -> new BaseCliCommand<Map<String, String>, Runnable>( | ||
"test", | ||
"...", | ||
c -> { | ||
// simulate a parameter required=true which is missing | ||
throw new MissingRequiredParameterException("No value for 'test.dummy'"); | ||
}, | ||
(conf, deps) -> { | ||
throw new UnsupportedOperationException("shouldn't be called in this test"); | ||
}, | ||
List.of(new CliCommand.Parameter("test.dummy", "--test-dummy", "Some param."))) | ||
.create(key -> Optional.empty(), List.of())) | ||
.getMessage()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters