-
Notifications
You must be signed in to change notification settings - Fork 227
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add --mode arbitrary|project to smithy diff
This commit adds a --mode option to Smithy diff to support the arbitrary mode (the current mode used to compare two models), and the project mode used to compare the current project against another project or model. When running in project mode, the imports and sources of the current model are used to load the "new" model (the current project), but they aren't used to load the "old" model. If the --old argument points to a directory that contains a smithy-build.json file, its imports and sources are used when loading the old model, though its dependencies are ignored and it's loaded using the resolved classpath of the new model. This ensures that the models are comparable and won't cause comparison issues when trying to compare things like traits across class loaders.
Showing
10 changed files
with
240 additions
and
57 deletions.
There are no files selected for viewing
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
9 changes: 9 additions & 0 deletions
9
...s/software/amazon/smithy/cli/projects/diff-example-conflict-with-simple/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,9 @@ | ||
$version: "2.0" | ||
namespace smithy.example | ||
|
||
// See the DiffCommandTest#projectModeUsesConfigOfOldModel integration test. | ||
// | ||
// This is to cause a diff event when compared against simple-config-sources, ensuring that the config file of this | ||
// project is used and not the config file of the "new" model. If the new model's config was also loaded, the | ||
// integration test would create a shape conflict error after loading. | ||
integer MyString |
4 changes: 4 additions & 0 deletions
4
...s/software/amazon/smithy/cli/projects/diff-example-conflict-with-simple/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
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
46 changes: 46 additions & 0 deletions
46
smithy-cli/src/main/java/software/amazon/smithy/cli/commands/StyleHelper.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,46 @@ | ||
/* | ||
* 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.commands; | ||
|
||
import java.util.regex.Pattern; | ||
import software.amazon.smithy.cli.ColorFormatter; | ||
import software.amazon.smithy.cli.ColorTheme; | ||
import software.amazon.smithy.utils.StringUtils; | ||
|
||
final class StyleHelper { | ||
|
||
private static final Pattern TICK_PATTERN = Pattern.compile("`(.*?)`"); | ||
|
||
private StyleHelper() {} | ||
|
||
// Converts Markdown style ticks to use color highlights if colors are enabled. | ||
static String formatMessage(String message, int lineLength, ColorFormatter colors) { | ||
String content = StringUtils.wrap(message, lineLength, System.lineSeparator(), false); | ||
|
||
if (colors.isColorEnabled()) { | ||
content = markdownLiterals(content, colors); | ||
} | ||
|
||
return content; | ||
} | ||
|
||
static String markdownLiterals(String content, ColorFormatter colors) { | ||
if (colors.isColorEnabled()) { | ||
content = TICK_PATTERN.matcher(content).replaceAll(colors.style("$1", ColorTheme.LITERAL)); | ||
} | ||
return content; | ||
} | ||
} |
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