Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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 @@ -46,7 +46,7 @@ public abstract class AbstractCommand implements Command {

private final String group;

private final boolean hidden;
private boolean hidden;

private AvailabilityProvider availabilityProvider = AvailabilityProvider.alwaysAvailable();

Expand Down Expand Up @@ -105,6 +105,10 @@ public boolean isHidden() {
return this.hidden;
}

public void setHidden(boolean hidden) {
this.hidden = hidden;
}

@Override
public List<String> getAliases() {
return this.aliases;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.springframework.shell.core.InputReader;
import org.springframework.shell.core.utils.Utils;

import java.io.PrintWriter;
import java.io.StringWriter;
Expand Down Expand Up @@ -51,6 +52,35 @@ void testDefaultHelpMessage() throws Exception {
Assertions.assertEquals(expectedOutput.replaceAll("\\R", "\n"), actualOutput.replaceAll("\\R", "\n"));
}

@Test
void testDefaultHelpMessageWithoutQuit() throws Exception {
// given
CommandRegistry commandRegistry = new CommandRegistry();
StringWriter stringWriter = new StringWriter();
PrintWriter outputWriter = new PrintWriter(stringWriter);
InputReader inputReader = new InputReader() {
};
ParsedInput parsedInput = ParsedInput.builder().build();
CommandContext commandContext = new CommandContext(parsedInput, commandRegistry, outputWriter, inputReader);

((AbstractCommand) Utils.QUIT_COMMAND).setHidden(true);

// when
Help help = new Help();
help.execute(commandContext);

// then
String actualOutput = stringWriter.toString();
String expectedOutput = """
AVAILABLE COMMANDS


""";
Assertions.assertEquals(expectedOutput.replaceAll("\\R", "\n"), actualOutput.replaceAll("\\R", "\n"));

((AbstractCommand) Utils.QUIT_COMMAND).setHidden(false);
}

@Test
void testHelpMessageForCommand() throws Exception {
// given
Expand Down Expand Up @@ -352,4 +382,4 @@ void testHelpMessageForCommandAlias() throws Exception {
Assertions.assertEquals(expectedOutput.replaceAll("\\R", "\n"), actualOutput.replaceAll("\\R", "\n"));
}

}
}