Skip to content

Commit 3f89847

Browse files
authored
Revert "Apply recipes by number (#818)"
This reverts commit 5be3c16.
1 parent 5be3c16 commit 3f89847

File tree

6 files changed

+18
-64
lines changed

6 files changed

+18
-64
lines changed

applications/spring-shell/src/main/java/org/springframework/sbm/shell/ApplicableRecipesListHolder.java

Lines changed: 0 additions & 42 deletions
This file was deleted.

applications/spring-shell/src/main/java/org/springframework/sbm/shell/ApplyShellCommand.java

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,18 @@
1616
*/
1717
package org.springframework.sbm.shell;
1818

19-
import lombok.RequiredArgsConstructor;
20-
import org.jetbrains.annotations.NotNull;
21-
import org.jline.utils.AttributedString;
22-
import org.jline.utils.AttributedStringBuilder;
23-
import org.jline.utils.AttributedStyle;
2419
import org.springframework.sbm.engine.commands.ApplicableRecipeListCommand;
2520
import org.springframework.sbm.engine.commands.ApplyCommand;
2621
import org.springframework.sbm.engine.context.ProjectContext;
2722
import org.springframework.sbm.engine.context.ProjectContextHolder;
2823
import org.springframework.sbm.engine.recipe.Action;
2924
import org.springframework.sbm.engine.recipe.Recipe;
25+
import lombok.RequiredArgsConstructor;
26+
import org.jetbrains.annotations.NotNull;
27+
import org.jline.utils.AttributedString;
28+
import org.jline.utils.AttributedStringBuilder;
29+
import org.jline.utils.AttributedStyle;
30+
import org.jline.utils.Colors;
3031
import org.springframework.shell.Availability;
3132
import org.springframework.shell.CompletionContext;
3233
import org.springframework.shell.CompletionProposal;
@@ -48,15 +49,11 @@ public class ApplyShellCommand {
4849
private final ApplicableRecipeListRenderer applicableRecipeListRenderer;
4950
private final ProjectContextHolder projectContextHolder;
5051
private final ApplyCommandRenderer applyCommandRenderer;
51-
private final ApplicableRecipesListHolder applicableRecipeListHolder;
5252

5353
@ShellMethod(key = {"apply", "a"}, value = "Apply a given recipe to the target application.")
5454
@ShellMethodAvailability("availabilityCheck")
5555
public AttributedString apply(@ShellOption(arity = 1, valueProvider = ApplyRecipeValueProvider.class,
56-
help = "The number of the recipe to apply.") String recipeIndex) {
57-
int realIndex = Integer.parseInt(recipeIndex) - 1;
58-
Recipe recipe = applicableRecipeListHolder.getRecipeByIndex(realIndex);
59-
String recipeName = recipe.getName();
56+
help = "The name of the recipe to apply.") String recipeName) {
6057
AttributedStringBuilder header = buildHeader(recipeName);
6158
System.out.println(header.toAnsi());
6259

applications/spring-shell/src/main/java/org/springframework/sbm/shell/RecipeRenderer.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,19 @@ public AttributedString renderRecipesList(String noRecipesTitle, String title, L
3939
AttributedString titleString = renderTitle(title);
4040
builder.append(titleString);
4141

42-
foundRecipes.forEach(recipe -> this.buildRecipePresentation(foundRecipes.indexOf(recipe), builder, recipe));
42+
foundRecipes.forEach(recipe -> this.buildRecipePresentation(builder, recipe));
4343

4444
builder.append("\n");
45-
builder.append("Run command '> apply <recipe-number>' to apply a recipe.");
45+
builder.append("Run command '> apply recipe-name' to apply a recipe.");
4646
builder.append("\n");
4747
}
4848
return builder.toAttributedString();
4949
}
5050

51-
public AttributedStringBuilder buildRecipePresentation(int index, AttributedStringBuilder builder, Recipe recipe) {
52-
builder.style(AttributedStyle.BOLD);//.foreground(Colors.rgbColor("yellow")));
53-
builder.append(" ").append(Integer.toString(index + 1)).append(") ");
51+
public AttributedStringBuilder buildRecipePresentation(AttributedStringBuilder builder, Recipe recipe) {
52+
builder.style(AttributedStyle.DEFAULT);
53+
builder.append(" - ");
54+
builder.style(AttributedStyle.DEFAULT.italicDefault().boldDefault().foreground(Colors.rgbColor("yellow")));
5455
builder.append(recipe.getName());
5556
builder.style(AttributedStyle.DEFAULT);
5657
builder.append("\n -> ").append(recipe.getDescription());

applications/spring-shell/src/main/java/org/springframework/sbm/shell/ScanShellCommand.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ public class ScanShellCommand {
4242
private final PreconditionVerificationRenderer preconditionVerificationRenderer;
4343
private final ScanCommandHeaderRenderer scanCommandHeaderRenderer;
4444
private final ConsolePrinter consolePrinter;
45-
private final ApplicableRecipesListHolder applicableRecipesListHolder;
4645

4746
@ShellMethod(key = {"scan", "s"},
4847
value = "Scans the target project directory and get the list of applicable recipes.")
@@ -51,8 +50,6 @@ public String scan(
5150
help = "The root directory of the target application.")
5251
String projectRoot) {
5352

54-
applicableRecipesListHolder.clear();
55-
5653
List<Resource> resources = scanCommand.scanProjectRoot(projectRoot);
5754
String scanCommandHeader = scanCommandHeaderRenderer.renderHeader(projectRoot);
5855
PreconditionVerificationResult result = scanCommand.checkPreconditions(projectRoot, resources);
@@ -70,7 +67,6 @@ public String scan(
7067
ProjectContext projectContext = scanCommand.execute(projectRoot);
7168
contextHolder.setProjectContext(projectContext);
7269
List<Recipe> recipes = applicableRecipeListCommand.execute(projectContext);
73-
applicableRecipesListHolder.setRecipes(recipes);
7470
AttributedString recipeList = applicableRecipeListRenderer.render(recipes);
7571
stringBuilder.append(recipeList);
7672
}

applications/spring-shell/src/test/java/org/springframework/sbm/shell/RecipeRendererTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*/
1616
package org.springframework.sbm.shell;
1717

18-
import org.springframework.sbm.engine.recipe.Recipe;
1918
import org.jline.utils.AttributedString;
2019
import org.jline.utils.AttributedStringBuilder;
2120
import org.jline.utils.AttributedStyle;
@@ -76,8 +75,8 @@ void shouldRenderListOfRecipesWhenNotEmpty() {
7675

7776
AttributedStringBuilder builder = new AttributedStringBuilder();
7877

79-
sut.buildRecipePresentation(1, builder, recipe1);
80-
sut.buildRecipePresentation(2, builder, recipe2);
78+
sut.buildRecipePresentation(builder, recipe1);
79+
sut.buildRecipePresentation(builder, recipe2);
8180

8281

8382
AttributedString attributedString = sut.renderRecipesList("", title, List.of(recipe1, recipe2));

components/sbm-core/src/main/java/org/springframework/sbm/engine/commands/ApplyCommand.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@
1515
*/
1616
package org.springframework.sbm.engine.commands;
1717

18+
import org.openrewrite.ExecutionContext;
19+
import org.springframework.beans.factory.annotation.Qualifier;
1820
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
21+
import org.springframework.context.annotation.Scope;
1922
import org.springframework.sbm.common.filter.DeletedResourcePathStringFilter;
2023
import org.springframework.sbm.common.filter.ModifiedResourcePathStringFilter;
2124
import org.springframework.sbm.engine.context.ProjectContext;

0 commit comments

Comments
 (0)