-
Notifications
You must be signed in to change notification settings - Fork 220
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor CLI to remove --severity from some commands
Some commands don't need the severity option and should instead only show validation events if the command fails. This includes the ast and select commands. To make this work, I refactored several CLI classes: * Add a shared ModeBuilder abstraction to cleanup the old utility code. This class now uses a Validator.Mode to indicate how validation is reported, decoupling arguments from the shared validation abstraction. * Move --discover and --discover-classpath to DiscoveryOptions * Move --severity to SeverityOption so it's more granular * Add the ability to check for receivers on Arguments * Add the ability to remove receivers from Arguments * Add the ability to get positional arguments more than once * Can now add/remove argument receivers in ClasspathCommand subclasses
- Loading branch information
Showing
22 changed files
with
454 additions
and
214 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
smithy-cli/src/it/java/software/amazon/smithy/cli/AstCommandTest.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,53 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://aws.amazon.com/apache2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file 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 software.amazon.smithy.cli; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.containsString; | ||
import static org.hamcrest.Matchers.equalTo; | ||
import static org.hamcrest.Matchers.not; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import software.amazon.smithy.utils.ListUtils; | ||
|
||
public class AstCommandTest { | ||
@Test | ||
public void validatesModelSuccess() { | ||
IntegUtils.run("model-with-warning", ListUtils.of("ast"), result -> { | ||
assertThat(result.getExitCode(), equalTo(0)); | ||
assertThat(result.getOutput(), containsString("\"smithy\"")); | ||
assertThat(result.getOutput(), not(containsString("WARNING"))); | ||
}); | ||
} | ||
|
||
@Test | ||
public void convertsSyntacticallyCorrectModels() { | ||
IntegUtils.run("invalid-model", ListUtils.of("ast"), result -> { | ||
assertThat(result.getExitCode(), equalTo(0)); | ||
assertThat(result.getOutput(), containsString("\"smithy\"")); | ||
assertThat(result.getOutput(), not(containsString("WARNING"))); | ||
}); | ||
} | ||
|
||
@Test | ||
public void showsErrorsForSyntacticallyIncorrectModels() { | ||
IntegUtils.run("model-with-syntax-error", ListUtils.of("ast"), result -> { | ||
assertThat(result.getExitCode(), equalTo(1)); | ||
assertThat(result.getOutput(), containsString("ERROR")); | ||
assertThat(result.getOutput(), containsString("bar // <- invalid syntax")); | ||
}); | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
...t/resources/software/amazon/smithy/cli/projects/model-with-syntax-error/model/main.smithy
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,6 @@ | ||
$version: "2.0" | ||
namespace smithy.example | ||
|
||
structure Foo { | ||
bar // <- invalid syntax | ||
} |
4 changes: 4 additions & 0 deletions
4
...t/resources/software/amazon/smithy/cli/projects/model-with-syntax-error/smithy-build.json
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,4 @@ | ||
{ | ||
"version": "1.0", | ||
"sources": ["model"] | ||
} |
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
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
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
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
Oops, something went wrong.