Skip to content
This repository was archived by the owner on May 14, 2025. It is now read-only.

Commit 937068d

Browse files
author
ritvik
committed
Refactor usedDefaultValue() into separate methods
1 parent b58284a commit 937068d

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/main/java/org/springframework/cli/runtime/command/DynamicCommand.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -172,21 +172,22 @@ private void addRoleVariables(Map<String, Object> model, CommandContext commandC
172172
}
173173

174174
private boolean usedDefaultValue(String variableName, CommandContext commandContext) {
175-
boolean usedDefaultValue = false;
176-
// Look for matching option of the provided variable name and determine if a
177-
// default value was used.
178175
List<CommandParserResult> commandParserResults = commandContext.getParserResults().results();
179176
for (CommandParserResult commandParserResult : commandParserResults) {
180177
String optionName = NamingUtils.toKebab(commandParserResult.option().getLongNames()[0]);
181-
if (variableName.equals(optionName)) {
178+
if (variableName.equals(optionName)) { // Inline isName since it's a simple equals check
182179
Object defaultOptionValue = commandParserResult.option().getDefaultValue();
183180
Object optionValue = commandParserResult.value();
184-
if (defaultOptionValue != null && optionValue != null && defaultOptionValue.equals(optionValue)) {
185-
usedDefaultValue = true;
181+
if (isDefaultValueMatching(defaultOptionValue, optionValue)) {
182+
return true;
186183
}
187184
}
188185
}
189-
return usedDefaultValue;
186+
return false;
187+
}
188+
189+
private boolean isDefaultValueMatching(Object defaultOptionValue, Object optionValue) {
190+
return defaultOptionValue != null && optionValue != null && defaultOptionValue.equals(optionValue);
190191
}
191192

192193
public void runCommand(Path workingDirectory, String springDir, String commandsDir, Map<String, Object> model) {

0 commit comments

Comments
 (0)