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

Add dryRun cli Option #25

Merged
merged 2 commits into from
Jun 22, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ public static void main(final String[] args) {
@Option(names = {"-r", "--recipes"}, required = true, description = "List of Recipes to be applied.", split = ",", parameterConsumer = CommaSeparatedParameterConsumer.class)
private List<String> recipes;

@Option(names = {"-dr", "--dry-run"}, description = "Perform a dry run without making any changes.")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Short option of 2 letter looks strange to me. I think some tools like Git use the -n option for dry run

public boolean dryRun;

@Option(names = {"-d", "--debug"}, description = "Enable debug logging.")
public boolean debug;

Expand All @@ -40,6 +43,7 @@ public Config setup() {
.withVersion(getVersion())
.withPlugins(plugins)
.withRecipes(recipes)
.withDryRun(dryRun)
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@ public class Config {
private final Path cachePath;
private final String mavenHome;
private final String mavenRewritePluginVersion;
private final boolean dryRun;

private Config(String version, List<String> plugins, List<String> recipes, Path cachePath, String mavenHome, String mavenRewritePluginVersion) {
private Config(String version, List<String> plugins, List<String> recipes, Path cachePath, String mavenHome, String mavenRewritePluginVersion, boolean dryRun) {
this.version = version;
this.plugins = plugins;
this.recipes = recipes;
this.cachePath = cachePath;
this.mavenHome = mavenHome;
this.mavenRewritePluginVersion = mavenRewritePluginVersion;
this.dryRun = dryRun;
}

public String getVersion() {
Expand All @@ -46,6 +48,10 @@ public String getMavenPluginVersion() {
return mavenRewritePluginVersion;
}

public boolean isDryRun() {
return dryRun;
}

public static Builder builder() {
return new Builder();
}
Expand All @@ -57,6 +63,7 @@ public static class Builder {
private Path cachePath = Settings.DEFAULT_CACHE_PATH;
private String mavenHome = Settings.MAVEN_HOME_PATH;
private String mavenRewritePluginVersion = Settings.MAVEN_REWRITE_PLUGIN_VERSION;
private boolean dryRun = false;

public Builder withVersion(String version) {
this.version = version;
Expand Down Expand Up @@ -88,8 +95,13 @@ public Builder withMavenPluginVersion(String mavenPluginVersion) {
return this;
}

public Builder withDryRun(boolean dryRun) {
this.dryRun = dryRun;
return this;
}

public Config build() {
return new Config(version, plugins, recipes, cachePath, mavenHome, mavenRewritePluginVersion);
return new Config(version, plugins, recipes, cachePath, mavenHome, mavenRewritePluginVersion, dryRun);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ public void invokeRewrite(String pluginPath) {
private List<String> createGoalsList() throws IOException {
List<String> goals = new ArrayList<>();
String mavenPluginVersion = config.getMavenPluginVersion();
goals.add("org.openrewrite.maven:rewrite-maven-plugin:" + mavenPluginVersion + ":run");
String mode = config.isDryRun() ? "dryRun" : "run";
goals.add("org.openrewrite.maven:rewrite-maven-plugin:" + mavenPluginVersion + ":" + mode);

try (InputStream inputStream = getClass().getResourceAsStream("/recipe_data.json")) {
JsonNode recipesNode = objectMapper.readTree(inputStream).get("recipes");
Expand Down
Loading